Skip to main content

Error shape

Every error response uses the same JSON shape:
Error
  • type is the broad class and code the exact condition. Branch on code.
  • param, when present, is the path of the offending field, such as model, questions.severity.criteria or questions.team.criteria.billing. Question names and option names can appear in it; your state, instructions and descriptions never do.
  • Some errors carry extra fields inside error, listed below.
  • message is for humans and may change. It never contains your request content.
Every response, success or error, has an x-request-id header (req_...). Include it when you contact support. No error is charged. Only a 200 response is charged. See Billing.

All errors

Money fields are decimal strings in USD with six decimals, such as "0.000150". available_usd can be negative.

Order of checks

A request that fails several checks gets only the first error, in this order:
  1. Body over the global size limit: 413.
  2. API key: 401.
  3. Request shape and global limits: 400 invalid_request.
  4. Model: unknown 400 invalid_model, retired 410, unavailable 503; then the model’s own body limit 413 and limits 400.
  5. Rate limit: 429 rate_limited.
  6. The key’s spend limit: 402 key_limit_reached.
  7. Your balance: 402 insufficient_balance.
  8. The model call: 400, 429 capacity_exceeded, 502, 503 or 504.
Every request that gets past step 2 counts against your rate limit, including requests refused later with 400, 410, 413 or 503.

Examples

400 invalid_request

Error
A body that is not valid JSON names param: "body". When the model itself rejects the input, the error has no param. The most common cause is an input over the model’s input-length limit: the API never shortens your input to make it fit. Like every error, this one is not charged.
Error

400 invalid_model

Error

401 invalid_api_key

Error

402 insufficient_balance

Returned when your balance is zero or negative, or is more than 0.01 USD short of the amount the request sets aside. required_usd is that amount; see How a request draws on the balance. topup_url is null while card top-ups in the console are not available; see Adding credit. Once they are, it links to the console page for adding credit.
Error

402 key_limit_reached

Returned when the request would take the key past its spend limit. The check counts what the key has been charged in the current period plus the requests it has in flight, so a key can be refused slightly before its charges reach the limit. resets_at is the start of the next period, in UTC (for example midnight UTC for a daily limit). For a limit with no reset period it is null: the limit covers the key’s whole lifetime, and a key’s limit cannot be changed after it is created, so create a new key to continue.
Error

410 model_retired

Error

413 request_too_large

Error

429 rate_limited and capacity_exceeded

Both carry a Retry-After header with the number of seconds to wait. rate_limited means your key or account is over its rate limit; the x-ratelimit-* headers tell you which limit and when it resets (see Limits). capacity_exceeded means the model is busy, regardless of your own limit.
Error
Error

5xx

Error
internal_error (500), upstream_error (502) and upstream_timeout (504) have the same shape.

Retrying

  • Retry 429, 500, 502, 503 and 504. For 429, wait for Retry-After; for the others, use exponential backoff with jitter.
  • Do not retry 400, 401, 402, 410 or 413 unchanged: the same request fails the same way.
  • A failed request is not charged, so retrying it costs nothing extra. A request that succeeded is charged every time you send it; see Limits.