Error Response Format
All errors return a consistent JSON format:HTTP Status Codes
| Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid or missing API key |
| 402 | Payment Required - Insufficient balance |
| 404 | Not Found - Model or resource not found |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error |
| 502 | Bad Gateway - Upstream provider error |
| 503 | Service Unavailable - All channels failed |
Error Types
Authentication Errors (401)
| Type | Description |
|---|---|
unauthorized | No API key provided |
invalid_api_key | API key format is incorrect |
expired_api_key | API key has been revoked |
Payment Errors (402)
| Type | Description |
|---|---|
insufficient_balance | Account balance is too low |
quota_exceeded | API key usage limit reached |
Validation Errors (400)
| Type | Description |
|---|---|
invalid_request_error | Request parameters are invalid |
context_length_exceeded | Input too long for model |
model_not_found | Requested model doesn’t exist |
Rate Limit Errors (429)
When you exceed rate limits:Upstream Errors (502, 503)
| Type | Description |
|---|---|
upstream_error | Provider returned an error |
all_channels_failed | No available providers |
timeout_error | Request timed out |
Handling Errors in Python
Handling Errors in JavaScript
Best Practices
Implement exponential backoff
Implement exponential backoff
When rate limited, wait progressively longer between retries:
Set timeouts
Set timeouts
Always set reasonable timeouts to avoid hanging requests:
Log errors for debugging
Log errors for debugging
Log the full error response including request ID for support:
Handle model-specific errors
Handle model-specific errors
Some models have specific requirements (e.g., max tokens, image formats).
Validate inputs before making requests.