AI API errors: fix 401, 404, 429 and timeouts
Start with the HTTP status and request route. Authentication errors, model permissions, rate limits and browser CORS failures have different remedies; repeating the same request is not a diagnosis.
Read the status before changing the key
| Result | Possible cause | Next action |
|---|---|---|
| 400 / 422 | Invalid body or unsupported parameter | Check protocol, required fields and output-limit parameter |
| 401 | Missing, invalid or expired credential | Check the header and key locally |
| 403 | Permission or policy restriction | Confirm model access; do not assume it only means insufficient balance |
| 404 | Wrong route or unavailable resource | Check /v1 duplication and exact model ID |
| 429 | Rate limit or quota condition | Inspect the error and Retry-After if available |
| 5xx | Service or gateway failure | Use a bounded retry and preserve the request ID |
Providers can map errors differently. A status alone cannot identify every cause. Never paste a complete key into a public support report.
Network error is not an authentication verdict
A browser can block a response because the endpoint does not allow cross-origin requests. DNS, TLS, browser extensions and connectivity can also cause fetch to fail without an accessible HTTP status. Run the same minimal call locally with cURL to separate browser restrictions from API failure.
Do not disable browser security or certificate checks. The browser checker reports an inconclusive network/CORS result instead of calling a key invalid.
Retry only when useful
For a transient service failure or rate limit, wait, respect Retry-After when supplied, and cap attempts. Use increasing delays with jitter in production. Stop retrying invalid authentication or malformed requests until the configuration is corrected. A timed-out request may still have generated a response and a charge.
What to send to support
- Timestamp and timezone, model ID, client version and selected protocol.
- HTTP status and request ID, if available.
- Whether a local minimal request works and whether streaming changes the outcome.
- A redacted request shape. Remove authorization headers, personal documents and private endpoints if sharing publicly.
Start with the setup checklist if you have not yet completed a minimal call.
Keep learning
Sources and scope
Based on public protocol references. Delivered model permissions, rates and capabilities govern actual use. This is not a compatibility guarantee for every client version.
Get an API key ↗