Browse the docsError codes

Error codes

Every failure returns the same envelope: a stable machine-readable code, a human-safe message, and the request_id to quote in a support ticket. Branch on code, never on the message text.

HTTPCodeWhat went wrongHow to fix it
401invalid_api_keyMissing, malformed, or revoked key, or an inactive account.Fix or replace the key.
402insufficient_creditsThe account is out of credits.Top up, then resend.
403permission_deniedThis key is not allowed to perform the action.Check the key's scope and workspace.
404model_not_foundUnknown model name in the request.Use chitragupta.
405method_not_allowedWrong HTTP method for this route.All completion routes are POST.
409idempotency_conflictAn Idempotency-Key was reused with a different body.Use a new key, or resend the exact original body.
413file_too_largeThe uploaded file exceeds the size limit.Compress the file before encoding.
413page_limit_exceededToo many pages and images combined.Split into smaller requests.
422invalid_requestMalformed body, or max_tokens above the cap.Fix the payload.
422system_message_not_allowedA system message was sent; the model uses a fixed prompt.Move the instruction into the user message.
422images_not_allowedAn image was sent to a text-only model.Use a vision-capable model.
429rate_limit_exceededToo many requests per second, or too many in flight on this key.Honor the Retry-After header.
429quota_exceededThe key or account hit its usage quota.Wait for the reset or raise the quota.
500internal_errorUnexpected server-side failure.Retry with exponential backoff.
502inference_failedThe model returned an invalid response.Retry once; if it persists, log the request_id.
503provider_unavailableInference capacity is temporarily unavailable.Retry with exponential backoff.
504inference_timeoutThe model took too long.Retry with backoff, or send fewer pages.
# See the request_id even on an error:
try:
    r = client.chat.completions.create(model=MODEL, messages=[{"role": "user", "content": "hi"}])
    print(r.id.replace("chatcmpl-", ""))
except Exception as e:
    print(type(e).__name__, getattr(e, "status_code", "?"), getattr(e, "body", None))