// 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

StatuscodeMeaningRetry?
400null, max_tokens_exceededThe request is invalid, or max_tokens is larger than the model's context.No, fix the request
401invalid_api_keyMissing, malformed or revoked API key.No
402insufficient_balanceNot enough wallet balance for this request's worst-case cost.After recharging
404model_not_foundUnknown or retired model id.No
429rate_limit_exceededMore than 10 requests in the last minute.Yes, after Retry-After
502upstream_errorThe model provider returned an error.Yes, with backoff
503upstream_overloadedThe model provider is busy.Yes, after Retry-After
504upstream_timeoutThe model provider took too long.Yes, with backoff

Retrying

  • For 429 and 503, wait the number of seconds in the Retry-After header.
  • For 502 and 504, 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) or maxRetries (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.