Skip to content
Veil

Errors

Error shapes, every status code and what to do about each.

Errors are JSON with a matching HTTP status. The envelope follows the format of the endpoint you called. The type strings are the same on both.

/v1/chat/completions

{
  "error": {
    "message": "Missing or invalid API key.",
    "type": "invalid_api_key",
    "param": null,
    "code": "invalid_api_key"
  }
}

code always equals type. param is always null.

/v1/messages

{
  "type": "error",
  "error": {
    "type": "invalid_api_key",
    "message": "Missing or invalid API key."
  }
}

Status codes

StatusTypeMeaningWhat to do
400invalid_request_errorThe body is not valid JSON, has no model or no messages, lacks max_tokens on /v1/messages, sends images to a model without vision, uses /v1/messages with a model that is chat-completions only, or carries parameters the model host rejected.Fix the request. Do not retry it unchanged.
401invalid_api_keyThe key is missing, malformed or unknown.Send the full key in the Authorization or x-api-key header.
402insufficient_balanceThe balance cannot cover the input plus a minimal reply.Top up, send a shorter prompt, or wait for requests in progress to finish and release their holds.
403account_inactiveThe key was never activated, or the account is suspended.Activate a new key by signing in with it once. A suspended account cannot be reactivated through the API.
404model_not_foundThe model id is not in the catalog.Use an id from GET /v1/models, spelled exactly.
413request_too_largeThe request body is larger than 12 MB.Send less history or smaller images.
429rate_limit_errorThe key reached its requests-per-minute limit or its concurrent request limit.Wait the number of seconds in the Retry-After header, then retry.
502upstream_errorThe model returned a reply that could not be read. Nothing was charged.Retry.
503service_unavailableNo model host could take the request. Nothing was charged.Retry after the number of seconds in the Retry-After header.

Notes

  • Checks run in this order: key, account status, body size, body shape, model id, endpoint and image support, rate limit, balance, then the model itself. The first failure is the one you see.
  • 503 comes with Retry-After of 5 or 10 seconds. It is always safe to retry: nothing was charged.
  • 403 account_inactive on a brand new key means it was not activated. Sign in with it once at /login, or see Authentication.
  • Error messages are written by us. Raw errors from a model host are never passed through, so a 400 from the model says only that the parameters were rejected.
  • Errors after a stream has started arrive as a final event, not as a status. See Streaming.
  • Account endpoints under /api use a simpler shape: {"error":"message"}.

Retrying

Retry 429, 502 and 503, waiting for Retry-After when it is present. Do not retry 400, 401, 403, 404 or 413 without changing the request. Retry 402 only after topping up.