Errors

Errors use the OpenAI error envelope, so existing SDKs surface them cleanly. The HTTP status tells you the category; the body gives a machine-readable code.

Error shape#

json
{
  "error": {
    "message": "Invalid or revoked API key.",
    "type": "invalid_request_error",
    "code": "invalid_api_key",
    "param": null
  }
}

Status codes#

FieldTypeDescription
400invalid_request_errorMissing or malformed parameters (e.g. no model or prompt).
401invalid_request_errorMissing, invalid, or revoked API key.
402insufficient_quotaNot enough credits — top up or upgrade.
403invalid_request_errorKey not authorized for this scope (insufficient_scope).
404invalid_request_errorUnknown model, job, or resource.
429rate_limit_errorRate limit exceeded — see the Retry-After header.
502api_errorThe upstream model provider returned an error.

Common codes#

FieldTypeDescription
missing_api_key401No Authorization: Bearer header was sent.
invalid_api_key401The key is unknown, revoked, or expired.
insufficient_scope403The key lacks the scope for this endpoint.
insufficient_credits402Your credit balance is too low for the request.
model_not_found404The model id doesn't exist or isn't allowed for this key.
rate_limit_exceeded429Too many requests in the current window.

Handling errors#

Retry 429 after the Retry-After header, and treat 502 as transient (retry with backoff). 400, 401, 403, and 404 are client errors — fix the request rather than retrying.