Errors

Errors

OpenAI and Anthropic error envelopes, the codes, what to do about them and which requests to retry.

An error comes in the envelope of the format you sent the request in — the way your SDK understands it. Include request_id when contacting support; it also comes in the x-request-id header of every response.

Every endpoint except /v1/messages uses the OpenAI envelope:

json
{"error": {"message": "...", "type": "...", "code": "...", "param": "...", "request_id": "req_..."}}

/v1/messages uses the Anthropic envelope; our code and param are extra fields inside error, and request_id is at the top level:

json
{"type": "error", "error": {"type": "not_found_error", "message": "...", "code": "model_not_found"}, "request_id": "req_..."}

The param field is present only when the error concerns a specific parameter. error.type in the Anthropic envelope depends only on the HTTP status: 400 — invalid_request_error, 401 — authentication_error, 402 — billing_error, 403 — permission_error, 404 — not_found_error, 413 — request_too_large, 429 — rate_limit_error, 500 and 502 — api_error, 503 — overloaded_error.

Error codes

HTTPcodeWhat it means
400invalid_requestMalformed request body (no model, broken JSON) — check the parameters. A provider rejection the gateway could not classify uses the same code; the HTTP status is then the provider's (4xx).
400unsupported_parameterA request parameter is not supported — its name is in the param field. Remove it and retry. See Request parameters.
400unsupported_value, invalid_valueThe model's provider rejected a parameter value; the parameter name is in the param field when it could be determined.
400context_length_exceededThe request does not fit the model's context window. The message starts with “Prompt is too long:” — Claude Code uses it to trigger context compaction.
400content_policy_violationThe model's content policy rejected the request — change the prompt.
400invalid_imageThe model rejected the reference image — try a different one.
401invalid_api_keyKey missing, not found or revoked — check the Authorization header.
402insufficient_quotaBalance exhausted — top up your account. If the remainder is held by requests in progress, retry once they finish.
403spend_limit_exceededThis key hit its spend limit — raise the limit or create a new key.
404model_not_foundThe model does not exist, is disabled, is not available to your account or does not fit the endpoint (an image model on chat) — check GET /v1/models with your key.
404not_foundUnknown endpoint, video job not found or the video is not ready yet.
413invalid_requestThe request body exceeds the limit — see Limits.
422generation_failedThe model returned no image. Retry the request or rephrase the prompt.
429rate_limit_exceededToo many concurrent requests on your account, or the model is overloaded at the provider. Retry after the pause in the Retry-After header.
500—Internal gateway error (type: server_error, no code). Retry; if it persists, contact support with the request_id.
502upstream_unavailableThe model's providers are temporarily unavailable — retry later.
503service_unavailableService under maintenance or temporarily unavailable — retry later.
503—The model has no available routes right now (type: server_error, no code) — retry later or pick another model.

Retries

Retrying makes sense for 429, 500, 502, 503 and 422. Other errors will not go away on retry — fix the request, key or balance first.

  • On 429 wait for the pause in the Retry-After header; without it, use exponential backoff (1, 2, 4… seconds). The OpenAI and Anthropic SDKs do this themselves.
  • An error that arrives as an event mid-stream is also a reason to retry the whole request (see Streaming).

Stuck? Email us at support@example.com with the request_id from the response.

Updated September 29, 2026