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 | error.code (examples) | What to do |
|---|---|---|
400 | invalid_request, unsupported_parameter, unsupported_content, context_too_large, end_user_required, bad_end_user, bad_idempotency_key, model_not_supported_on_surface | fix the request |
401 | invalid_api_key | check the key (authentication) |
402 | balance_exhausted, billing_suspended | top up your balance (billing), or contact support |
403 | scope_missing, model_not_allowed, model_not_in_plan, end_user_blocked, test_key_not_supported, organization_suspended | the key or workspace may not do this |
404 | model_not_found | use a model id from GET /v1/models |
409 | idempotency_in_progress, idempotency_not_replayable | see idempotency |
413 | request_too_large | send a smaller body |
422 | idempotency_key_reused | use a new idempotency key |
429 | window_5h, window_weekly, key_rpm, key_concurrency, end_user_rpm | wait for retry-after (limits) |
503 | overloaded, unavailable, billing_unavailable | temporary: retry after retry-after |
500, 502, 504 | temporary: retry with backoff |
Retrying
x-should-retry: falsemeans retrying the same request cannot help (a used-up window, an empty balance).retry-aftergives the seconds to wait.- For
429withoutx-should-retry: falseand for5xx, retry with exponential backoff and jitter, starting at about one second. - Send an
Idempotency-Keyso a retry never runs a request twice. - Quote the
x-request-idheader when you contact support.