Check the HTTP status and JSON error. Streaming failures may arrive after HTTP 200.
HTTP statuses
| Status | Action |
|---|---|
| 400 | Fix the request or remove unsupported fields. |
| 401 | Check your API key. |
| 402 / 403 | Check credits and key permissions. Messages uses 403 for insufficient credit; Chat Completions uses 402. |
| 404 | Check the model ID. Token counting always returns 404. |
| 413 | Reduce the request body. |
| 429 | Wait for the Retry-After seconds, then retry. The code names the limit: concurrency_limit_exceeded, requests_per_minute_limit_exceeded or daily_spend_limit_exceeded. |
| 503 | supplier_budget_exhausted: daily service budget reached; retry after 00:00 UTC. model_usage_brake: this model is paused for a usage reporting investigation; retry later or choose another model. Both are uncharged and include Retry-After seconds (300 for the model brake). |
| Other 5xx | Check request usage before retrying a generation. |
Error bodies
{
"error": {
"message": "max_tokens must be a positive integer.",
"type": "invalid_request_error",
"code": "invalid_value",
"param": "max_tokens"
}
}
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be a positive integer."
}
}
Retry requests
Use bounded exponential backoff for temporary failures. A disconnected request may have generated tokens. Check usage before sending it again.