Errors

Status codes, error types and what to do.

Errors are JSON:

{"error": {"type": "invalid_request", "message": "The request body failed validation", "details": ["questions.route.criteria: choice needs at least 2 options"]}}
StatustypeWhat to do
401invalid_api_keyCheck the key; revoked keys stop working within seconds.
402insufficient_creditsAdd credits or turn on auto top-up under Billing.
402budget_exceededA monthly budget (the organization's or this key's) is used up. The message says which, and when it resets.
403organization_suspendedContact support.
404model_not_foundUse an id from GET /v1/models.
422invalid_requestThe details list names each problem. A state longer than the model's context comes back here too, as "maximum context length exceeded".
429rate_limitedBack off and retry after the Retry-After header.
500internal_errorRetry. If it keeps happening, write to support with the x-request-id.
502model_errorThe model returned an error. Retry with backoff.
502 / 503 / 504model_unavailableThe model could not be reached in time. Retry; the first call after a quiet spell can take up to a minute.
529overloadedRetry after the Retry-After header.

Failed requests are never billed.