Which API errors are safe to retry: one list, one formula, three exceptions
Rate-limit 429s, 5xx errors and timeouts can be retried automatically; quota-type 429s and 4xx request errors cannot. Honor Retry-After before any backoff formula, and think about double billing before retrying a timeout.
Automatic retries can rescue most transient failures — and can also inflate a small problem into a billing incident. The dividing line is a single question: is the error transient or deterministic? A deterministic error fails identically on every retry, burning quota for nothing. OpenAI's and Anthropic's official error documentation draw this line clearly12.
The list to memorize
Safe to retry automatically (after a short wait):
- Rate-limit 429s: you sent requests too fast. The most typical transient failure — slow down and come back12.
- 500 / 503 / 529: internal server errors, model overload, API-wide overload. OpenAI's official advice for 500 is to "retry your request after a brief wait"1; Anthropic recommends "retrying the request with exponential backoff" for 5002.
- Timeouts and connection errors: the request never landed or the response never came back. Your client knows locally; just retry.
Retrying is useless (fix first):
- Quota-type 429s: credit balance exhausted, monthly spend limits, organizational usage caps. OpenAI is blunt — retrying billing, spend or quota errors won't restore API access; update the credits or limits first1. Anthropic's spend-cap 429s likewise carry no Retry-After header and keep failing until access resumes2.
- 400 / 401 / 403: the request itself is wrong — invalid parameters, bad key, no permission. Resending the identical request produces the identical error12.
- Streams that break mid-response: when an SSE stream dies after emitting some content, the client sees HTTP 200, so it never enters any error branch. "Retrying" from scratch means paying again for already-generated tokens, and resuming a broken stream requires your own logic.
Retry-After beats any backoff formula
429 and 503 responses often carry a Retry-After header, which takes one of two forms: a number of seconds, or an HTTP date3. The rule is simple: if it's there, obey it. OpenAI explicitly requires waiting "at least as long as it specifies" before retrying1.
When the header is absent, use exponential backoff with jitter1:
delay = min(base * 2^attempt + random(0, base), cap)
- Start with a
baseof 0.5–1 second; - Jitter is mandatory — without it, a batch of concurrent requests all retries in lockstep and makes the rate limit worse;
- Cap retries at 2–3. Anthropic's official SDK also defaults to just 2 retries and honors the retry-after header automatically2.
Three exceptions that matter more than the list
1. Retrying a timeout can bill you twice
A client-side timeout only means you got impatient; it does not mean the request was free. The request may have completed server-side and been billed normally. An application-level retry then charges the same context as input twice. OpenAI specifically warns that application-level retries must account for retries the SDK already performed — don't stack them1.
What to do:
- Set the client timeout larger than the model's longest plausible inference time, not smaller;
- Turn the SDK's retry count down — every official SDK exposes a
max_retries-style option2;
- When you suspect double billing, check the response's request_id against your bill instead of firing another request.
2. Figure out who is rate-limiting you
When calling through a relay, a 429 may come from the upstream provider or from the gateway's own concurrency/balance protection — and the fixes differ. The former means slow down; the latter means check your account settings or balance. Read the response headers and error identifiers before deciding, instead of treating every 429 as "wait and retry".
3. Never classify errors by string matching
Error responses are structured JSON: OpenAI provides error.code, Anthropic provides error.type plus typed exception classes in the SDK. Anthropic explicitly recommends catching typed classes rather than string-matching messages — one reworded sentence from the provider and your retry logic is dead2.
The implementation checklist
- Branch by error type: in the retryable list → backoff with jitter; quota-type 429 → alert a human immediately; 4xx request errors → fix the request, don't retry.
- Obey
Retry-Afterwhenever present; otherwise exponential backoff with jitter, capped at 2–3 attempts13.
- Before retrying timeouts, confirm the SDK's default retries aren't multiplied with your application-level retries12.
- Log the original request_id for every retry, so a mismatched bill can be traced to the exact call.
- Monitor the share of retried requests: a sudden spike means your upstream or gateway is degrading — retries stop the bleeding, they are not the cure.
The essence of a retry policy is admitting that failures will happen, then buying back success at the lowest possible cost. A retry whose cost you can't compute — duplicate billing, traffic amplification — is more dangerous than no retry at all.
Sources & attribution
This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.
- Error codes and troubleshooting — OpenAI · accessed 2026-11-15Note:Retry guidance for 429 versus quota errors, retry advice for 500/503, and the official Retry-After and jittered exponential backoff guidance are from OpenAI's official error codes documentation.
- Errors — Anthropic · accessed 2026-11-15Note:Exponential backoff for 500, the 529 overloaded error, spend-cap 429 responses lacking a Retry-After header, and the SDK's default of two automatic retries honoring retry-after are from Anthropic's official errors documentation.
- Retry-After header (MDN Web Docs) — MDN · accessed 2026-11-15Note:The use cases of the Retry-After response header (429, 503, redirects) and its two value formats (delay-seconds or HTTP-date) are from the official MDN documentation.
One key for Claude, GPT and 50+ models
The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.