Complete guide to AI API gateway error codes. Find causes, meanings, and solutions for common errors.
| Code | Name | Description | Solution |
|---|---|---|---|
| 400 | Bad Request | Invalid request format or missing parameters | Check request body, JSON syntax, required fields |
| 401 | Unauthorized | Invalid or missing API key | Verify API key is correct and included in header |
| 403 | Forbidden | API key lacks required permissions | Check key permissions and scope settings |
| 429 | Rate Limited | Too many requests in time window | Implement exponential backoff, reduce request rate |
| 500 | Server Error | Internal gateway or upstream error | Retry with backoff, contact support if persists |
| 502 | Bad Gateway | Upstream service unavailable | Check backend service status, retry later |
| 503 | Service Unavailable | Gateway is overloaded or maintaining | Implement circuit breaker, retry after delay |
| 504 | Gateway Timeout | Upstream took too long to respond | Increase timeout, optimize request size |
Identify error type
Retryable or not
Apply strategy
Log and alert
Resume operation
Use exponential backoff for transient errors. Start with 1s delay, double each retry, max 3-5 attempts. retry: { max: 3, backoff: 'exponential' }
Only retry 429, 500, 502, 503, 504. Never retry 400, 401, 403 as they indicate client issues requiring code changes.
After N consecutive failures, stop making requests temporarily. This prevents cascade failures and allows services to recover.
Track error rates, types, and patterns. Set up alerts for unusual spikes that may indicate systemic issues.