AI API Error Troubleshooting Guide: From Failed Requests to Stable Recovery
Locate problems layer by layer — request address, protocol, status code, and task stage — separate parameter errors from rate limiting, upstream failures, and network timeouts, and stop pointless retries from amplifying the outage.

When an API call fails, jumping straight to another model or resending the request over and over usually just makes the problem harder to locate. The order that works: first pin down which layer failed, then decide whether the failure deserves a retry.
Step 1: Preserve the Error Scene#
Record the request time, endpoint path, model identifier, HTTP status, error code, request identifier, and latency. If the call passes through your own server or a gateway, keep the correlation identifiers each layer uses.
Logs must not contain usable API keys. User inputs and outputs should not be logged indiscriminately either; keep the minimum needed to locate the problem, and sanitize sensitive content. When you escalate to support, send a redacted error response, not a screenshot containing a full key.
Step 2: Check the Address and Protocol First#
Check whether the API address has an extra /v1 appended, whether the request method is right, whether Content-Type matches the body, and whether the model supports this endpoint. A text model's request format does not transplant onto a dedicated video endpoint.
If the response is HTML instead of the expected JSON, first check whether you hit the website page, a reverse proxy error page, or a login page. Adjusting the prompt further will not fix this.
Step 3: Read the Status Code Together with the Response Body#
The table below covers common HTTP meanings; the final judgment still rests on the current endpoint's error codes and response body, and gateways and upstream services may map them differently.
| Status or symptom | Check first | Retry as-is? |
|---|---|---|
| 400-class parameter errors | Field names, types, and parameters the model supports | Retry only after fixing the request |
| 401 | Whether the API key was passed correctly and is still valid | Do not retry the same request in a loop |
| 403 | Account or model access permission | Check permissions and configuration first |
| 404 | Path, model, or resource identifier | Verify the target resource first |
| 429 | Request rate, concurrency limits, or quota conditions stated in the response | Act on the cause and any wait hint |
| 5xx | Gateway or upstream failure | Bounded retries when the retry conditions hold |
| Network timeout | Connectivity, proxy timeouts, and the server's processing state | First judge whether the request may have already executed |
Do not guess the cause from the status code alone. Two 429s — a short-lived concurrency limit versus a quota that needs adjusting — can call for completely different handling.
Step 4: Shrink to a Minimal Reproducible Request#
Reduce the request to one model already confirmed to work, one short text, and only the fields the documentation requires. Remove tools, attachments, complex formats, and multi-turn history, then add them back one by one.
Change one variable at a time and record the result. That is how you tell an unsupported parameter, an inaccessible asset, and a broken end-to-end path apart. Debug requests consume real service resources, so bound the number of attempts.
Step 5: Set Boundaries for Retries#
Retry only recoverable transient errors. Lengthen the wait step by step, add a little jitter, cap the attempt count and the overall deadline, and when the endpoint supplies a hint such as Retry-After, follow what it says.
Watch the side effects of generation requests closely: a network timeout does not mean the server did nothing. For async tasks, query the existing task first, and do not silently resend after part of a stream has already arrived. Use an idempotency mechanism only when the endpoint explicitly supports and specifies one; never assume duplicate requests merge on their own.
Turn Failure into a Recoverable Experience#
The UI should preserve user input, tell failure apart from unconfirmed status, and offer a clear next step. Partial content already generated can stay on screen, marked as incomplete.
On the server side, watch how error types, request success rate, and wait times move. Stop futile attempts promptly during sustained failures so retry traffic does not crowd out healthy requests. For streaming scenarios, continue with the streaming integration guide; for async video, see the video generation workflow.

