Skip to main content

Error response format

Errors return a JSON body with an error object and an appropriate HTTP status:
The 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

Retry 429 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

Check the key in the dashboard, confirm the Bearer prefix, and check for stray whitespace.
The model id is not available. List valid ids with GET /v1/models. Note that model ids are prefixed, for example openai/gpt-5.
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.
Back off and retry with exponential backoff, and reduce your request rate.
The upstream provider failed to respond. Retry, or try another model.

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.