Docs / Errors

Errors and rate limits

Errors use the OpenAI error object, so the SDKs raise their usual exceptions. The status codes and codes below are the complete list the relay produces.

The error object

Error body
{
  "error": {
    "message": "Your credit balance is exhausted. Top up to continue.",
    "type": "insufficient_quota",
    "code": "insufficient_quota",
    "param": null
  }
}

Status codes

Errors returned by the API
StatuscodetypeWhenRetry?
400nullinvalid_request_errorThe body is not a JSON object.No
400missing_modelinvalid_request_errorNo model in the body.No
400 / 413 / 422nullinvalid_request_errorThe model rejected the request parameters. The status is the model's; the message is generic.No — fix the request
401missing_api_keyinvalid_request_errorNo bearer token.No
401invalid_api_keyinvalid_request_errorUnknown or revoked key.No
401api_key_expiredinvalid_request_errorThe key passed its expiry date.No — create a new key
402insufficient_quotainsufficient_quotaBalance is zero or below, or held by requests in flight.After a top-up, or once parallel requests settle
402key_spend_limit_reachedinsufficient_quotaThis key used up its own spend limit. The account may still have balance.Use another key
402bonus_not_applicableinsufficient_quotaOnly bonus credit is left and the model accepts paid credit only (model-one).Use another model or top up
403account_suspendedpermission_errorThe account is suspended.No — contact us
404model_not_foundinvalid_request_errorUnknown or disabled model id.No
404not_foundinvalid_request_errorUnknown path.No
405method_not_allowedinvalid_request_errorCompletion endpoints take POST only.No
429rate_limit_exceededrate_limit_errorThis key passed its request rate limit.Yes, with backoff
429upstream_rate_limitedrate_limit_errorThe model is temporarily overloaded.Yes, with backoff
502nullupstream_errorThe model returned an error or an invalid response, or could not be reached.Yes
503nullupstream_errorNo route to the model is available right now.Yes
503billing_unavailableapi_errorBilling could not reserve credit for the request.Yes
504nullupstream_errorThe model did not finish in time.Yes, with a smaller max_tokens or a lower reasoning effort

Checks run in this order: key (401), path and method (404, 405), account (403), empty balance (402), rate limit (429), request body (400), model (404), credit reservation (402), then the model itself.

An empty balance is 402, not OpenAI's 429, so SDKs do not retry it in a loop. The OpenAI SDKs do retry 429 and 5xx on their own by default.

A stream that fails after it started cannot change its status. It ends with an in-band error event instead; see Errors inside a stream.

Python · handling 402
import openai

try:
    response = client.chat.completions.create(model="model-one", max_tokens=1024, messages=messages)
except openai.APIStatusError as e:
    if e.status_code == 402 and e.code == "bonus_not_applicable":
        ...  # only bonus credit left: switch to model-zero or model-one-flash, or top up
    elif e.status_code == 402:
        ...  # balance exhausted: top up; retrying will not help
    else:
        raise

Rate limits

Request ids

Successful completion responses carry an X-Request-Id header (req_…). Error responses do not. Every request that got as far as the model — including ones that failed there — is listed in the dashboard with its status, tokens and cost. That is the place to look when a charge surprises you.