Errors

Error formats, status codes, error codes and how to retry.

Errors use the format of the API style you called, with a stable machine-readable error.code and a human-readable error.message. Branch on the status and the code, never on the message.

Messages API
{
  "type": "error",
  "error": {
    "type": "rate_limit_error",
    "code": "key_rpm",
    "message": "too many requests per minute for this key"
  }
}
Chat Completions API
{
  "error": {
    "type": "usage_limit_reached",
    "code": "key_rpm",
    "message": "too many requests per minute for this key"
  }
}

Status codes

Status codes
Statuserror.code (examples)What to do
400invalid_request, unsupported_parameter, unsupported_content, context_too_large, end_user_required, bad_end_user, bad_idempotency_key, model_not_supported_on_surfacefix the request
401invalid_api_keycheck the key (authentication)
402balance_exhausted, billing_suspendedtop up your balance (billing), or contact support
403scope_missing, model_not_allowed, model_not_in_plan, end_user_blocked, test_key_not_supported, organization_suspendedthe key or workspace may not do this
404model_not_founduse a model id from GET /v1/models
409idempotency_in_progress, idempotency_not_replayablesee idempotency
413request_too_largesend a smaller body
422idempotency_key_reuseduse a new idempotency key
429window_5h, window_weekly, key_rpm, key_concurrency, end_user_rpmwait for retry-after (limits)
503overloaded, unavailable, billing_unavailabletemporary: retry after retry-after
500, 502, 504temporary: retry with backoff

Retrying

  • x-should-retry: false means retrying the same request cannot help (a used-up window, an empty balance).
  • retry-after gives the seconds to wait.
  • For 429 without x-should-retry: false and for 5xx, retry with exponential backoff and jitter, starting at about one second.
  • Send an Idempotency-Key so a retry never runs a request twice.
  • Quote the x-request-id header when you contact support.