LLM API error codes, explained and fixed
Check the HTTP status, the error type and code, and the stream's terminal event together. A 400 can mean the wrong model endpoint; 402 means a billing limit; 429 means rate limiting. An HTTP 200 stream can still end with response.failed. Keep the X-Request-ID response header (and any request_id in the error body): a request refused before any model is called — such as a 401 for the key, a 402 for wallet funds or a key spend cap, a 429 from your key's or account's limits, or a 400 or 404 for the model ID or endpoint — has no row in Dashboard → Logs, while one that failed after reaching a model normally has a final request row there that support can correlate with intermediate attempts (a streamed request that failed before any output may not).
Quick reference
The first thing to check for each status code:
| Code | Meaning | First thing to check |
|---|---|---|
| 400 | Invalid request, or the wrong endpoint for that model | The message names the problem: a Responses feature the gateway does not run (background, image_generation), an incomplete response_format envelope, or a model that has to be called on another path — model '<id>' must be called via /v1/messages or /v1/chat/completions. |
| 400 CONTENT_FILTERED | Blocked by content policy before any model is called | An image or video generation prompt that fails content moderation returns prompt rejected by content moderation. A rejected request calls no model and is not billed. Do not retry it automatically; if you believe the block is a mistake, contact support with the request_id. When moderation itself is unavailable, image and video requests are refused with 502 MODERATION_UNAVAILABLE rather than generated unchecked; retry later. |
| 401 | Invalid or missing API key | The Authorization header carries your key as Bearer sk-… — check for typos, a space or line break inside the key, or an empty env var in the shell that runs your client. Refused before any model is called, so it leaves no row in Dashboard → Logs; keep the X-Request-ID header. |
| 402 | Insufficient available funds or key budget | Read the error message and any X-Billing-Funds-Reason header. Funds may be reserved by in-flight requests, or the key's maxSpend wallet cap may be reached (a wallet top-up does not raise a key's spend cap; plan-covered requests draw from the account's shared plan quota). Refused before any model is called, with no row in Dashboard → Logs. |
| 403 | Forbidden | Usually not a key problem: a revoked, expired or unknown key returns 401, not 403. Keep the full error body, X-Request-ID header and any request_id for support, and confirm you're calling the right base URL for your client. |
| 404 | Unknown route or model | The path or model ID doesn't exist (check for a missing or doubled /v1). Copy the exact model ID from the /models page — IDs are case-sensitive. A 404 for an unknown path or model ID is refused before any model is called, with no row in Dashboard → Logs. |
| 429 | Rate limit exceeded | RATE_LIMIT_EXCEEDED (requests per minute) or TOKEN_QUOTA_EXCEEDED (token limits). A 429 that has a row in Dashboard → Logs came back from upstream after the gateway's retries. A gateway limit on the key, the account, or the account's use of one model refuses the request before any model is called: its 429 has no row, carries an X-RateLimit-Scope of api_key, subject or subject_model, and recurs at the same rate; an X-RateLimit-Scope of upstream_provider points at the model vendor. A streamed request that hit an upstream limit before any output can also come back without a row, so a 429 without a row is not always a gateway limit — read X-RateLimit-Scope first. Honor Retry-After and back off. Key and account limits start at platform defaults and can be raised on request: email support@router.one with your account ID, the key's name (never the key itself), and your expected peak traffic. |
| 499 | Client cancelled the request | Your client closed the connection before the response finished — a stop button, an SDK timeout, or a dropped network. Not an upstream failure and never failed over. A stream the client closes on /v1/chat/completions or /v1/responses is billed for the usage the upstream reported or, if none arrives after output has streamed, from an estimate (as of 2026-10-13); a stream closed before any output is not billed if no usage arrives (see the streaming guide). A stream: false call on /v1/chat/completions, /v1/responses or /v1/messages keeps running after the client leaves (as of 2026-10-09): if the model finishes, the request is billed for the usage it reports and the trace shows those tokens; if it fails or outlasts the gateway's non-streaming window, nothing is billed. |
| 500 | Internal server error | Transient server-side failure. Retry with backoff; contact support if it persists. |
| 502 | Upstream response failed | Inspect the error body or stream event and keep the request_id. A 502 alone does not show whether every eligible route failed or whether a nested error was a rate limit. |
| 503 | Service or model route temporarily unavailable | Check the catalog and error code. PROVIDER_UNAVAILABLE can mean that no eligible route is available now; it does not by itself mean the model ID is unknown. Retry with bounded backoff if the error is transient. |
| 504 | Upstream wait timed out | Router One can normalize a timeout or deadline error to 504 PROVIDER_UNAVAILABLE. It does not prove the upstream returned HTTP 504. Keep the error message, endpoint, request_id and time; distinguish a timeout waiting for headers from an interrupted stream. |
| 529 | Upstream overloaded | The model's upstream is saturated (for example Anthropic's 529 overloaded_error, checked 2026-11-27). If the error is retryable and another healthy route serves the same exact model, Router One can try that route and demotes routes with sustained upstream errors — it never silently swaps to a different model; otherwise retry with bounded backoff. |
| Timeout | No response in time | Identify which layer stopped waiting: your SDK, a proxy, the gateway, or the upstream. A client timeout can occur without an HTTP error response. Compare its configured deadline with response headers, stream events and the final request record. |
402 with balance remaining: wallet funds or a key cap?
When a 402 response includes X-Billing-Funds-Reason, use that value with the error message to distinguish available funds from temporary reservations and key limits. These diagnostics depend on the returned response; if a client does not expose them, retain the message and request_id for support instead of inferring a reason from the dashboard balance alone.
| Reason, when present | Next step |
|---|---|
| wallet_reserved | Some wallet funds are held by in-flight requests. Let them settle and check the available amount again; final charges may reduce what is released. |
| key_reserved | In-flight requests reserve part of this key's budget. Wait for settlement or adjust its maxSpend in Dashboard → API Keys. A wallet top-up does not lift this limit. |
| key_cap | The key's available spend budget is too small. Raise or clear its maxSpend if appropriate; adding wallet funds does not change the cap. |
| wallet_insufficient | Available wallet funds are below the required initial reservation. Review the request size and available amount, then reduce the input or top up. |
- If present, X-Billing-Available-Balance-USD and X-Billing-Reserved-Balance-USD distinguish available wallet funds from funds already held; X-Billing-Minimum-Required-USD describes the minimum initial reservation for admission, not the final bill.
- For a capped key, X-Billing-Available-Key-Budget-USD and X-Billing-Reserved-Key-Budget-USD describe the separate key budget. maxSpend caps wallet charges only — requests covered by your plan's quota draw from the account's shared plan quota and do not count toward any key's cap. Released reservations do not guarantee the next request will fit; final charges and other concurrent requests can change availability.
- When wallet_insufficient is returned, add funds in Dashboard → Deposit: Top up with a card, Alipay or WeChat Pay through hosted checkout, or with USDT/USDC on six chains (Tron, BSC, Ethereum, Polygon, Base, Arbitrum). No US credit card required.
Why did HTTP 200 end with response.failed?
HTTP 200 on an SSE connection means the stream started; it does not prove generation completed. For Responses, read response.error inside response.failed as well as top-level error events. A rate_limit_error or Too many pending requests message points to rate limiting; response.incomplete needs its incomplete_details inspected. Preserve partial output, and treat an unexpected disconnect before a terminal event as incomplete. Once output has reached the client, do not assume the gateway can replay the request on another route.
event: response.failed
data: {"type":"response.failed","response":{"status":"failed","error":{"type":"rate_limit_error","message":"Too many pending requests, please retry later"}}}504 or SDK timeout: which layer stopped waiting?
A timeout describes an elapsed limit, not a complete diagnosis. Start with whether an HTTP response arrived and whether any model output reached the client. Keep the endpoint, model ID, request_id when available, time and timezone, elapsed duration, and exact error text. Do not include your API key. Support can correlate the final request with intermediate attempts; the status alone cannot identify the responsible network hop.
| Observed evidence | What it establishes | Next check |
|---|---|---|
| SDK timeout with no HTTP response | The client stopped waiting; it does not establish an upstream HTTP error. | Check connect/read/total limits and local network or proxy errors. If the request reached the gateway and its connection was closed, the final log may record client cancellation. On a stream: false call the model may still finish and be billed (see 499), and a retry your SDK sends after its timeout is a separate request, billed on its own if its model finishes (as of 2026-10-09). |
| Client.Timeout exceeded while awaiting headers in the correlated upstream attempt | The gateway's HTTP client timed out before it received upstream response headers. A normalized 504 is not proof of an upstream HTTP 504 response. | Ask support to check the raw attempt and its timeout setting. Do not assume the SDK timeout or the same setting applies to every endpoint. |
| HTTP 200, then an error event or unexpected EOF | The SSE transport opened, but generation may have failed or remained incomplete. | Inspect the terminal event and preserve partial output. Check the streaming guide before retrying; an already delivered stream cannot be assumed to restart on another route. |
| HTTP 200 on a non-streaming call, but the JSON body is an error | The call ran long enough for the gateway's keepalive to start (about 25 seconds): HTTP 200 was committed and JSON leading whitespace was written, so a later failure could no longer change the status code. | Check for an error before reading the result — a top-level error object on /v1/chat/completions and /v1/responses, and "type": "error" with an error object (the Anthropic envelope) on /v1/messages — and classify it by its type and code as you would a non-200 response. Applies, as of 2026-10-09, to long stream: false calls on /v1/chat/completions, /v1/responses and /v1/messages; use stream: true for generations that take minutes. |
- The long-wait policy for a named model's native /v1/responses stream does not apply to every protocol or non-streaming request. Client, proxy and upstream limits still matter, and model:auto retains its candidate budgets.
- Only a real upstream HTTP response establishes the upstream's status code. Gateway-normalized errors and individual failed attempts must be distinguished from the final outcome, which may succeed after an eligible fallback.
Read the trace before guessing
Dashboard → Logs records requests the gateway forwarded to a model (pre-model 401, 402, gateway-limit 429, and invalid-model/endpoint 400 or 404 rejections leave no row, and a streamed request that failed before any output may have none either). Each customer-facing request row shows the model, tokens, wallet charge or plan quota used, total time and, for streamed requests that produced output, time to first token (TTFT), and status. Dashboard → Logs filters by model, API key, status and date, so you can see whether an error is isolated or recurring. It does not expose the provider or intermediate attempts; every response carries an X-Request-ID header — share X-Request-ID (and any request_id in the error body) with support when the route or fallback chain needs investigation. Requests awaiting pricing may not appear yet, so an absent row is not proof of a zero charge.
Errors in Claude Code
Claude Code talks to the Anthropic-compatible endpoint at https://api.router.one — note: no /v1 suffix. Most 401/403s in Claude Code come from environment variables that are missing or exported in a different shell from the one that launches claude. Claude Code authenticates against a gateway with ANTHROPIC_AUTH_TOKEN, which takes precedence over ANTHROPIC_API_KEY and over a /login sign-in (Claude Code's authentication docs, checked 2026-11-27); ANTHROPIC_API_KEY is not required, and when it is set, interactive mode asks once whether to use it. A 400 whose message reads model '<id>' must be called via /v1/chat/completions is a different problem: the model ID you configured is not served on the Anthropic-compatible endpoint, so pick one whose detail page lists POST /v1/messages (currently listed Claude-family models and DeepSeek ids) or call that model on /v1/chat/completions instead. Claude Code's own sign-in messages (Not logged in · Please run /login, Invalid API key, Invalid auth token · Fix external auth token, Login expired · Please run /login) are mapped to their fixes on the Claude Code 401 & 403 page (https://router.one/claude-code-403). Claude Code's own usage-limit messages (You've hit your session limit · resets 3:45pm and its weekly, Opus and Sonnet variants) come from a Claude subscription sign-in (per Claude Code's error reference, checked 2026-11-27), not from Router One; the Claude Code usage-limit page (https://router.one/claude-code-usage-limit) explains each one and how to bill a terminal session to Router One instead. For the auth case, run these in the shell you start claude from (or add them to your shell profile), then restart claude:
export ANTHROPIC_BASE_URL=https://api.router.one export ANTHROPIC_AUTH_TOKEN=sk-your-router-one-key unset ANTHROPIC_API_KEY
Errors in Codex CLI
Codex CLI speaks the Responses API wire format, which many OpenAI-compatible relays don't implement — that's why Codex 404s against them. Router One supports wire_api = "responses" natively. Configure Codex in ~/.codex/config.toml with a top-level model = "gpt-6.2-sol" (without it, Codex 0.159.1 through 0.169.0 use their bundled default gpt-6.1-sol, and from 0.169.1 it is gpt-6.2-sol) and a provider with base_url = "https://api.router.one/v1", wire_api = "responses", and env_key = "ROUTER_ONE_API_KEY", then export ROUTER_ONE_API_KEY with your Router One key. Codex does not read OPENAI_BASE_URL or OPENAI_API_KEY for a custom provider. Leave requires_openai_auth off on the Router One provider: it turns on OpenAI sign-in, with ChatGPT or an OpenAI API key, for the provider (Codex's authentication docs, checked 2026-11-27), and the Router One provider takes its key from env_key instead. A 400 invalid_request that mentions background or image_generation is the gateway refusing two Responses features it does not run: drop background = true, and generate images through /v1/images/generations instead of the image_generation tool; hosted tools and previous_response_id work on models served natively over the Responses wire format. A 400 that reads model '<id>' must be called via /v1/messages or /v1/chat/completions is a different case: a Claude-family model ID reached the Responses endpoint, where Claude is not served — point Codex at a currently listed GPT-family model and use Claude Code for Claude. Two stream errors are raised by Codex itself (the text is Codex's, not a gateway error body): stream disconnected before completion: idle timeout waiting for SSE means no SSE event arrived within Codex's stream_idle_timeout_ms (300000 ms by default per Codex's configuration reference, checked 2026-11-27), and stream disconnected before completion: stream closed before response.completed means the connection closed before the final event. Look the request up in Dashboard → Logs by time and model. Raise stream_idle_timeout_ms on your custom [model_providers.<id>] block for long-reasoning GPT runs and check your proxy or network; the gateway does not end a native Responses stream for being idle. Full walkthrough, including both stream errors, on the Codex Responses API page.
FAQ
My key looks correct but I still get 401. Why?
The three usual causes: the env var is set in a different shell (or profile file) than the one running your client; the key was pasted with a line break or with a space inside it; or the client reads a different variable than the one you set. In the same session, check that the expected variable is set without printing the key or including it in screenshots.
Which Authorization header mistakes cause a 401 most often?
The value should be Bearer, a space, and the key. The mangled forms we see most: the scheme added twice (Bearer Bearer sk-…) because a client prefixes it and the env var already contains it; the key wrapped in quotes that were part of the pasted value; a newline or space inside the key; the Authorization header present but empty, or x-api-key sent empty while Authorization is missing; a dashboard session token (a JWT) sent where an API key is expected; and Authorization: sk-… with no scheme at all. Fix the value, not the key — a valid key sent in one of these forms still gets a 401.
What's the difference between 402 and 429?
402 concerns the funds or key budget available for a request, including amounts held by in-flight requests; read any X-Billing-Funds-Reason diagnostics before topping up. 429 concerns request or token limits, or an upstream limit. Check the response code and message, then correlate the request in Dashboard → Logs when a record is available.
Does 504 PROVIDER_UNAVAILABLE prove the upstream returned HTTP 504?
No. Router One can produce that status by normalizing a timeout or deadline error, even if no upstream response headers arrived. A client-side SDK timeout is another case and may have no HTTP response at all. Preserve the exact message and request_id when available so support can separate the raw upstream attempt, any fallback, and the final request outcome.
Do 5xx errors mean I have to write retry logic?
An eligible 5xx or timeout can be retried on another healthy route serving the same exact model, when one is available, and routes with sustained upstream errors are demoted until they recover — failover never swaps to a different model. Retrying is not guaranteed for every error, so use bounded backoff for failures returned to your app and contact support if the pattern continues.
I got HTTP 200 with an empty message. Should my client retry?
First distinguish a completed Chat Completions reply from a failed stream. A completed reply with non-zero usage can be empty because of reasoning or refusal; inspect finish_reason, refusal and usage before retrying, since repeating it can incur another wallet charge or use another plan quota unit. HTTP 200 with response.failed, an error event, or an interrupted stream is a different case: inspect the terminal event and preserve the X-Request-ID header and any request_id. A truly empty upstream reply with no usage is treated as an upstream error.
Does response.failed with Too many pending requests mean my key is invalid?
No. A nested rate_limit_error indicates rate limiting, not an authentication failure. Reduce concurrency and retry with bounded backoff. Keep the request_id, model ID, endpoint, time and timezone, and error type/code for support; do not include your API key. The error alone does not prove which route was tried or whether fallback ran.
Why does Claude Code return 403 while the same key works with curl?
curl talks to the OpenAI-compatible endpoint; Claude Code needs the Anthropic-compatible base URL without the /v1 suffix, plus ANTHROPIC_AUTH_TOKEN. ANTHROPIC_API_KEY is not required — leave it unset. See the dedicated Claude Code 403 guide for the full checklist.
Where do I see exactly which request failed and why?
Dashboard → Logs shows requests the gateway forwarded to a model — their status, model, tokens, wallet charge or plan quota used, and latency — with model, API key, status and date filters. Requests stopped before any model is called (401, 402, gateway-limit 429, or wrong-model/endpoint 400 or 404) leave no row there (a streamed request that failed before any output may have none either), and the customer view does not show the provider or fallback chain. Keep the X-Request-ID response header (and any request_id in the error body), including while a row is not yet visible, so support can investigate the final outcome and intermediate attempts.
I get unsupported_country_region_territory or insufficient_quota — are those Router One errors?
No — both come from the official OpenAI API, not the gateway. unsupported_country_region_territory is a 403 region block on the platform edge; insufficient_quota is OpenAI's billing/quota HTTP 429 error type (per OpenAI's error-codes docs, checked 2026-11-27, billing-related 429s can still carry error.type insufficient_quota alongside specific error.code values such as credit_balance_exhausted or spend-limit codes). Each has a dedicated fix guide: the region error page and the insufficient_quota page.