Documentation · Errors & limits

API

Errors & limits

Status codes, the error format and how to retry correctly.

Error format#

Errors follow the OpenAI format — an HTTP status plus an error object:

401 Unauthorized
{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

Status codes#

CodeMeaningWhat to do
400Bad requestCheck the request body and parameters.
401Missing or invalid keyCheck the Authorization header and the key itself.
402Insufficient balanceTop up your balance in the dashboard.
403Key restrictedThe key hit its spending limit or was revoked.
404Model not foundCheck the model id against the catalog.
429Too many requestsRetry later with exponential backoff.
500Internal errorRetry; if it persists, contact support.
502, 503Provider unavailableRetry later or pick another model.
504Timed outLower max_tokens or switch to streaming.

Retries#

Retry only 429 and 5xx errors, with a growing pause: 1, 2, 4, 8 seconds. If the response has a Retry-After header, wait as long as it says. Other 4xx errors will not succeed on retry — the request needs fixing.

The official OpenAI and Anthropic SDKs already retry these for you (twice by default); tune it with max_retries.

Timeouts#

Large models and long answers take time — sometimes minutes. Give your client a timeout of at least 120 seconds, or use streaming: the first tokens arrive sooner and the connection never sits idle.

Limits#

Rate limits depend on the model and current load. When you exceed them the API answers 429 — pause and retry. The spending limit on each key is yours to set in the dashboard.