Skip to main content
Errors are returned with the corresponding HTTP status and a JSON body:
{
  "error": {
    "message": "Error description",
    "type": "invalid_request_error",
    "code": "..."
  }
}

Codes

HTTPWhenWhat to do
400Malformed request (invalid JSON, fields)Check the request body
401Missing/invalid API keyCheck the key and the Authorization header
402Insufficient balanceTop up your balance (Balance)
404Unknown model/routeCheck against the model list
429Too many requestsRetry with backoff
5xxTemporary service-side errorRetry the request later

Recommendations

  • On 429 and 5xx — use exponential backoff (for example, 0.5s → 1s → 2s).
  • On 401/402, retries are pointless — they need action (key/balance).
  • Log error.message — it carries the human-readable reason.
When streaming, an error that occurs before generation starts arrives as a regular JSON with a status code; if the stream has already begun, the connection is closed.