Error response format
Errors return a JSON body with anerror object and an appropriate HTTP status:
type field is the machine-readable discriminator. Common values:
Status codes
Handle errors with the SDK
OpenAI client libraries map these statuses to typed exceptions:Python
JavaScript
Retry transient errors
Retry429 and 5xx responses with exponential backoff. Do not retry 400 or 401: they will
fail again until you fix the request or the key.
Common cases
Invalid API key (401, authentication_error)
Invalid API key (401, authentication_error)
Check the key in the dashboard, confirm the
Bearer prefix,
and check for stray whitespace.Unknown model (400, model_not_found)
Unknown model (400, model_not_found)
The
model id is not available. List valid ids with GET /v1/models.
Note that model ids are prefixed, for example openai/gpt-5.Unsupported parameter (400, invalid_request_error)
Unsupported parameter (400, invalid_request_error)
Some models reject a parameter. For example, newer OpenAI models (GPT-5, o3, o4) require
max_completion_tokens instead of max_tokens. Check the model’s supported_parameters in
/v1/models.Rate limited (429)
Rate limited (429)
Back off and retry with exponential backoff, and reduce your request rate.
Best practices
- Branch on the HTTP status and the
error.type, not on the message text. - Retry only transient errors (
429,5xx) with backoff. - Keep keys in environment variables and never log them.