Skip to content

Errors

All error responses use a consistent shape:

{
"error": {
"message": "Invalid API key",
"type": "auth_error"
}
}
HTTPtypeReasonWhat to do
400invalid_request_errorInvalid JSON, missing field, unknown parameterFix the request and check the schema
401auth_errorInvalid or revoked keyGenerate a new key in the dashboard
402insufficient_balanceCredit balance is too lowTop up from Dashboard > Billing
403forbiddenThe model is not available for this accountVerify model access
404model_not_foundUnknown model valueCheck the canonical ID (provider/model)
413request_too_largeContext window exceededShorten the messages content
429rate_limit_exceededRate limit hitRetry with exponential backoff
500internal_errorGateway internal errorRetry after a short delay
502provider_errorProvider-side failureOften transient, retry
503provider_unavailableProvider unreachableRetry later
504timeoutRequest timed outRequest fewer tokens or try streaming
Retry only for 429, 500, 502, 503, 504.
Backoff: exponential + jitter.
Max retry: 3.

Example (Python):

import time, random
from openai import OpenAI, APIStatusError
RETRIABLE = {429, 500, 502, 503, 504}
def call(client, payload, attempt=0):
try:
return client.chat.completions.create(**payload)
except APIStatusError as e:
if e.status_code in RETRIABLE and attempt < 3:
time.sleep(2 ** attempt + random.random())
return call(client, payload, attempt + 1)
raise

When implementing retries, also account for client-side timeouts, broken connections, and duplicate sends.