Skip to Content
Guides/Errors

Errors

What the API returns when something goes wrong, which errors to retry, and how to report.

An error is an HTTP status code and a JSON body:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "messages: At least one message is required"
  },
  "request_id": "req_7Hq2LmN9xP4sTv1KcW8bYd3R"
}

error.message says what to fix. It's written for people, so log it, but branch on error.type and the status code.

What to do

StatusTypeWhat to do
400invalid_request_errorFix the request. Don't retry it as it is
401authentication_errorCheck the key, or create a new one
402billing_errorAdd credits, or raise the key's spend limit. Don't retry until then; show the message to whoever can fix it
404not_found_errorCheck the model name or the endpoint
529overloaded_errorThe model is busy, or web search is unavailable. Retry with backoff
500api_errorRetry with backoff
503api_errorThe API is unavailable. Retry with backoff

The full list is in the reference.

Out of credits or over a limit

A 402 has one of two messages:

  • Out of credits. Your organization's balance reached zero. An owner or admin buys credits or turns on auto-reload on the Billing page.
  • Spend limit reached. The key spent its monthly limit. An owner or admin raises it on the API keys page, or the key works again on the first day of next month (UTC).

See Limits and spend.

Retries

Retry 529, 500 and 503, and network errors, with exponential backoff — wait 1, 2, 4… seconds, plus a little randomness, and give up after a few tries.

The Anthropic SDKs already do this: they retry these errors twice by default. Change it with maxRetries (TypeScript) or max_retries (Python).

A stream that fails after it started ends with an error event rather than a status code. Retry the whole request.

Request IDs

Every response — success or error — has a request-id header, and error bodies repeat it as request_id. Log it. When you report a problem, send us the request ID and we can find your request.

In the SDKs it's message._request_id (TypeScript and Python).

On this page