// guides
Errors & retries
Errors use the OpenAI format and standard HTTP status codes, so the OpenAI SDKs raise their usual exceptions.
Error format
Error response
{
"error": {
"message": "The model 'acme/unknown' does not exist",
"type": "invalid_request_error",
"code": "model_not_found"
}
}Status codes
| Status | code | Meaning | Retry? |
|---|---|---|---|
| 400 | null, max_tokens_exceeded | The request is invalid, or max_tokens is larger than the model's context. | No, fix the request |
| 401 | invalid_api_key | Missing, malformed or revoked API key. | No |
| 402 | insufficient_balance | Not enough wallet balance for this request's worst-case cost. | After recharging |
| 404 | model_not_found | Unknown or retired model id. | No |
| 429 | rate_limit_exceeded | More than 10 requests in the last minute. | Yes, after Retry-After |
| 502 | upstream_error | The model provider returned an error. | Yes, with backoff |
| 503 | upstream_overloaded | The model provider is busy. | Yes, after Retry-After |
| 504 | upstream_timeout | The model provider took too long. | Yes, with backoff |
Retrying
- For
429and503, wait the number of seconds in theRetry-Afterheader. - For
502and504, retry with exponential backoff: wait about 1s, then 2s, then 4s, and give up after a few tries. - Don't retry other 4xx errors: the same request will fail the same way.
- The OpenAI SDKs already retry 429 and 5xx errors twice with backoff. Tune it with
max_retries(Python) ormaxRetries(Node.js).
Requests that fail before the model generates anything aren't charged; a stream that fails midway is billed only for the tokens already sent. If you contact us about a request, include its x-request-id response header. More on limits in Rate limits.