OpenRouter adapter cannot retry 429 responses, even with `retryConfig` set
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- ai-infra-agents, backend-api-design
Direzione di ricerca
Il problema si trova nel file text.ts dell'adattatore OpenRouter, in particolare nelle funzioni chatStream, structuredOutput e structuredOutputStream. Osserva come viene chiamato il metodo chat.send dell'SDK; attualmente vengono passati solo signal e headers. La soluzione consiste nell'aggiungere retryCodes alle opzioni della richiesta, con valore predefinito ['5XX'] e consentendo l'override tramite la configurazione dell'adattatore. Inizia esaminando il codice SDK collegato per comprendere il parametro retryCodes, quindi modifica l'adattatore per passarlo. Testa con lo script di riproduzione fornito per assicurarti che le risposte 429 vengano ritentate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
TanStack AI version
0.58.0
Framework/Library version
@tanstack/ai-openrouter: 0.19.17 | @openrouter/sdk: 0.13.20
Describe the bug and the steps to reproduce it
A 429 from OpenRouter is never retried by the OpenRouter adapter. Setting retryConfig on the adapter config does not change that. A 5xx is retried.
The SDK takes the retry strategy from the client (retryConfig), but the list of retryable status codes only from the per-call request options. It defaults to ["5XX"]. There is no client-level equivalent.
The adapter passes only signal and headers as per-call options, in chatStream(), structuredOutput() and structuredOutputStream(). So there is no way to opt 429 in.
Rate limits are the common transient failure on OpenRouter, especially when provider routing narrows a model to a single upstream provider. The OpenAI and Anthropic adapters retry 429 by default through their SDKs.
Steps to reproduce:
import { chat } from '@tanstack/ai'
import { createOpenRouterText } from '@tanstack/ai-openrouter'
import { HTTPClient } from '@openrouter/sdk/lib/http.js'
let calls = 0
const httpClient = new HTTPClient({
fetcher: async () => {
calls++
return new Response(
JSON.stringify({ error: { code: 429, message: 'Rate limit exceeded' } }),
{ status: 429, headers: { 'content-type': 'application/json', 'retry-after': '1' } },
)
},
})
const adapter = createOpenRouterText('openai/gpt-4o-mini', 'sk-or-test', {
httpClient,
retryConfig: {
strategy: 'backoff',
backoff: { initialInterval: 100, maxInterval: 1000, exponent: 1.5, maxElapsedTime: 3000 },
},
})
for await (const chunk of chat({ adapter, messages: [{ role: 'user', content: 'Hello' }] })) {
if (chunk.type === 'RUN_ERROR') console.log(chunk.message)
}
console.log(calls) // 1
Returning 503 instead of 429 from the same fetcher gives 5 calls.
Expected behavior
The adapter config accepts the SDK's retryCodes and forwards it to chat.send() next to signal and headers, e.g. retryCodes: ['429', '5XX']. Default behaviour stays as it is.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
Inline above. No API key needed, the fetcher is stubbed.
Do you intend to try to help solve this bug with your own PR?
Yes, PR follows.
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- Lingua principale
- TypeScript
- Stelle
- 3.1k
- Fork
- 331
- Merge medio
- 2g 6h
- PR unite (30g)
- 155
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/ai
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
-
waiting-on: maintainer
-
Client tools never execute against spec-compliant AG-UI servers (plain `success` RUN_FINISHED) Apertawaiting-on: maintainer
-
waiting-on: maintainer
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
-
waiting-on: maintainer
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
security
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
IBM/node-sdk-core#373 ·
-
e2e-failure ready-to-code
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
chore
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100