Codes
| HTTP | When | What to do |
|---|---|---|
400 | Malformed request (invalid JSON, fields) | Check the request body |
401 | Missing/invalid API key | Check the key and the Authorization header |
402 | Insufficient balance | Top up your balance (Balance) |
404 | Unknown model/route | Check against the model list |
429 | Too many requests | Retry with backoff |
5xx | Temporary service-side error | Retry the request later |
Recommendations
- On
429and5xx— use exponential backoff (for example, 0.5s → 1s → 2s). - On
401/402, retries are pointless — they need action (key/balance). - Log
error.message— it carries the human-readable reason.
When streaming, an error that occurs before generation starts arrives as a
regular JSON with a status code; if the stream has already begun, the
connection is closed.