Using the API
Errors
Status codes, the error object, and how to handle each kind of failure.
The API uses standard HTTP status codes. Every error response has a JSON body in the OpenAI error format, so SDKs raise their usual exception types.
Error object
Status codes
Out of credits
When your prepaid balance reaches zero, requests fail with status 402 until you add credits or auto-reload tops you up.
402 Payment Required
Handling errors in code
Retries
Retry 429, 502 and 503 responses with exponential backoff and jitter. Do not retry 400, 401, 402 or 404: the same request will fail again. The OpenAI SDKs retry some of these for you; set max_retries (Python) or maxRetries (TypeScript) to tune it.