Error Response Format
All errors return a consistent JSON format with optional Agent-First hints:message, type, code, param) are always present. The hint fields (did_you_mean, suggestions, hint, retryable, retry_after, balance_usd, estimated_cost_usd) are optional extensions for AI agent self-correction. See the Agent-First API guide for details.
OpenAI-compatible endpoints use LemonData’s stable gateway error types. Anthropic-compatible and Gemini-compatible endpoints use their own native error families and response shapes.
HTTP Status Codes
| Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid or missing API key |
| 402 | Payment Required - Insufficient balance |
| 403 | Forbidden - Access denied or model not allowed |
| 404 | Not Found - Model or resource not found |
| 413 | Payload Too Large - Input or file size exceeded |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error |
| 502 | Bad Gateway - Upstream provider error |
| 503 | Service Unavailable - Service temporarily unavailable |
| 504 | Gateway Timeout - Request timed out |
Error Types
Authentication Errors (401)
| Type | Code | Description |
|---|---|---|
invalid_api_key | invalid_api_key | API key is missing or invalid |
expired_api_key | expired_api_key | API key has been revoked |
Payment Errors (402)
| Type | Code | Description |
|---|---|---|
insufficient_balance | insufficient_balance | Account balance is too low (OpenAI-compatible endpoints) |
insufficient_balance_error | insufficient_balance | Account balance is too low (Anthropic-compatible endpoints) |
quota_exceeded | quota_exceeded | API key usage limit reached |
Access Errors (403)
| Type | Code | Description |
|---|---|---|
access_denied | access_denied | Access to resource denied |
access_denied | model_not_allowed | Model not allowed for this API key |
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:Retry-After header and retry_after field both indicate the exact seconds to wait before retrying.
Payload Too Large (413)
When input or file size exceeds limits:- Image file too large (max 20MB)
- Audio file too large (max 25MB)
- Input text exceeds model context length
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.