Errors
Errors
All errors return JSON with OpenAI-compatible format:
{ "error": { "message": "Invalid API key", "type": "authentication_error", "code": null }}Error Types
| Status | Type | Description |
|---|---|---|
| 401 | authentication_error | Invalid or missing API key |
| 429 | rate_limit_error | Rate limit exceeded |
| 502 | upstream_error | Model service unavailable |
| 413 | invalid_request_error | Request body too large |
| 400 | invalid_request_error | Invalid request parameters |
| 503 | server_error | Service temporarily unavailable |
Handling Errors
Python
from openai import AuthenticationError, RateLimitError
try: response = client.chat.completions.create(...)except AuthenticationError as e: print(f"Invalid API key: {e}")except RateLimitError as e: print(f"Rate limited: {e}") # Implement backoffNode.js
try { const response = await client.chat.completions.create(...);} catch (error) { if (error.status === 401) { console.error('Invalid API key'); } else if (error.status === 429) { console.error('Rate limited'); }}