Docs/API access

Error codes

Use one error shape to debug faster: read the status code, then decide whether to retry.

On this page

Error response shape

Whether the error comes from the gateway or upstream, the body has one shape:

json
{
  "error": {
    "message": "insufficient balance for the requested maximum usage",
    "type": "upstream_error",
    "code": "insufficient_funds",
    "retryable": false
  }
}

retryable says whether sending the same request again later could succeed. When contacting support, include the X-Maxx-Request-ID response header — it pins down the exact call.

HTTP status codes

StatusMeaningRetry?
400Invalid body, unsupported parameter, or unknown model ID (model_not_supported)No — fix the request
401No key, or the key is invalid, disabled or expiredNo
402Balance can't cover this request's maximum possible cost (insufficient_funds)No — top up first
403This key may not call the model (API_KEY_MODEL_DENIED)No
404Path not foundNo
413Body too large to estimate cost (request_too_large)No — trim the context
422Estimated cost exceeds the per-request ceiling (billing_limit_exceeded)No — lower max_tokens
429Too many concurrent requests or upstream throttling; see Retry-AfterYes, with backoff
500Gateway internal errorYes
502Upstream failed and every candidate provider failed tooYes
503No provider currently available for the model, or all are at capacityYes, or switch models

Common error codes

codeMeaningWhat to do
model_not_supportedModel ID misspelled or not currently offeredCheck with GET /v1/models
API_KEY_MODEL_DENIEDThe model isn't in this key's allowed modelsEdit the key's allowed models in the console
insufficient_fundsBalance too lowTop up, or lower max_tokens
context_length_exceededInput exceeds the model's context windowTrim history or use a longer-context model
unsupported_parameterThe model doesn't accept one of the parametersDrop it, or switch models
api_key_concurrency_exceededToo many requests in flight on this keySee rate limits
rate_limit_exceededUpstream throttling with no other provider to switch toBack off and retry
provider_saturatedEvery provider for the model is at capacityRetry shortly
no_available_providerNo provider currently available for the modelRetry later, or switch models
upstream_timeoutUpstream took too longRetry
content_policy_violationBlocked by the upstream content policyAdjust the prompt

Recommended retry strategy

Retry only 408 / 429 / 5xx, at most three times, with exponential backoff and jitter. For 429, honour the Retry-After header first.

python
import time, random
from openai import OpenAI, APIStatusError

RETRY = {408, 429, 500, 502, 503}

def call_with_retry(client, **kwargs):
    for attempt in range(3):
        try:
            return client.chat.completions.create(**kwargs)
        except APIStatusError as e:
            if e.status_code not in RETRY or attempt == 2:
                raise
            wait = (2 ** attempt) + random.random()
            time.sleep(wait)
Warning

Never retry 400 / 401 / 402 / 403. The outcome will not change, and the attempts tie up concurrency that real requests need.

Contact us

Something unclear, or need a human? Pick the channel that fits your question.