Errors
An error has an HTTP status and a JSON body that says what went wrong. The body is shaped the way the API you called shapes its errors, so each lab’s SDK raises its usual exceptions.
The three shapes
Section titled “The three shapes”Most endpoints answer in OpenAI’s shape. It is the only one that carries a code, which is the thing to test for in your own code.
{ "error": { "message": "Insufficient balance for this request. Add credit at https://exoticrouter.com/dashboard/billing/ or in Telegram with @ExoticRouterBot, or lower max_tokens.", "type": "insufficient_quota", "param": null, "code": "insufficient_balance" }}{ "type": "error", "error": { "type": "billing_error", "message": "Insufficient balance for this request. Add credit at https://exoticrouter.com/dashboard/billing/ or in Telegram with @ExoticRouterBot, or lower max_tokens." }}{ "error": { "code": 402, "message": "Insufficient balance for this request. Add credit at https://exoticrouter.com/dashboard/billing/ or in Telegram with @ExoticRouterBot, or lower max_tokens.", "status": "FAILED_PRECONDITION" }}The message is the same in all three. In the Anthropic and Gemini shapes the type follows the HTTP status:
| Status | Anthropic error.type |
Gemini error.status |
|---|---|---|
| 400 | invalid_request_error |
INVALID_ARGUMENT |
| 401 | authentication_error |
UNAUTHENTICATED |
| 402 | billing_error |
FAILED_PRECONDITION |
| 404 | not_found_error |
NOT_FOUND |
| 413 | request_too_large |
INVALID_ARGUMENT |
| 429 | rate_limit_error |
RESOURCE_EXHAUSTED |
| 503 | overloaded_error |
UNAVAILABLE |
| 504 | timeout_error |
DEADLINE_EXCEEDED |
| Any other | api_error |
INTERNAL |
Every error
Section titled “Every error”| Status | code |
What happened | What to do |
|---|---|---|---|
| 400 | invalid_request |
The request is not well formed; the message names the field | Fix the request |
| 400 | context_length_exceeded |
The prompt does not fit the model’s context window | Shorten the input or lower max_tokens |
| 400 | content_filter |
The model’s content filter blocked the request | Change the prompt |
| 400 | request_rejected |
The model refused the request as it stands, often a parameter it does not support | Check the parameters against the model |
| 401 | missing_api_key |
No key in the request | Send the key |
| 401 | invalid_api_key |
The key is unknown, switched off or deleted | Use a working key |
| 402 | insufficient_balance |
The balance does not cover the request | Add credit, or lower max_tokens |
| 404 | model_not_found |
No such model, or the model does not answer on this endpoint | Check the id and its formats in the list |
| 404 | not_found |
No such path, or a video id or file link that does not open | Check the address |
| 405 | method_not_allowed |
The path exists but not with that method | Use the right method |
| 409 | not_ready |
The video is not finished | Ask for its status and wait |
| 413 | request_too_large |
The request is too large for the model | Send less |
| 429 | rate_limit_exceeded |
The key is over its requests per minute | Wait retry-after seconds, then retry |
| 500 | internal_error |
A fault on our side | Retry |
| 503 | model_unavailable |
The model could not answer just now | Wait retry-after seconds, then retry, or use another model |
| 503 | service_unavailable |
The gateway is briefly out of reach | Wait retry-after seconds, then retry |
| 504 | timeout |
The model took too long | Retry; stream long answers |
- What a model’s own service says about a refused request is never passed on. You get one of the 400s above, with a general message, so the
codeis the best lead and the cause is usually a parameter the model does not take. - A request that answers an error before any answer began is not charged.
- Every answer to a POST, an error included, has an
x-request-idheader.
Errors after a 200
Section titled “Errors after a 200”Once an answer has begun, its status cannot change. A failure after that point is reported inside the answer:
| Where | How the failure shows |
|---|---|
| A Chat Completions stream | A last data: frame holding an error object, and no [DONE] |
A Messages, Responses or Gemini (alt=sse) stream |
A last event named error, in the endpoint’s own shape |
A Gemini stream without alt=sse |
The JSON array stops early and is never closed |
| A slow image generation | A 200 whose body is an error object instead of data |
data: {"id":"chatcmpl-8Zr0…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Sunlight is"}}]}
data: {"error":{"message":"The model is temporarily unavailable. Please retry shortly.","type":"api_error","param":null,"code":"model_unavailable"}}So a stream that ends without its closing mark ([DONE], message_stop, response.completed) did not finish. The part that was written is charged.
What to retry
Section titled “What to retry”| Status | Retry? |
|---|---|
| 429 | Yes, after retry-after seconds |
| 500, 503, 504 | Yes, a few times, waiting longer each time |
| 400, 401, 402, 404, 405, 409, 413 | No: the same request will fail the same way |
The OpenAI and Anthropic SDKs retry 429 and the 5xx statuses a couple of times by themselves. Before a 503 reaches you the gateway has already tried the model more than once, so a long row of them means the model is out for now: fall back to another.
Where next
Section titled “Where next”- Rate limits: Requests per minute, per key.
- Billing and balance: What is and is not charged.