Skip to content
NewRouters/Documentation
GET STARTED

Diagnose LLM API errors and retries

Separate authentication, contract, rate-limit and interrupted-response failures, and design bounded retries that avoid duplicate generation.

Record UTC time, endpoint, public model ID, HTTP status, request ID if returned, and whether any output arrived. Keep a sanitized error summary. Do not record API keys, authorization headers, private prompts or full user payloads in shared logs.

Use model discovery to confirm the route and protocol selection to check its request shape. A media task status and an LLM HTTP error require different recovery paths.

ObservationFirst checkNext action
400 or validation errorRequired fields, model-specific parameters, context/output limitsCorrect the request before another attempt
401Missing or invalid credential and required auth headerFix credentials; do not retry unchanged
403Key permissions or access policyConfirm access with the account owner
404Public model ID, protocol endpoint and final SDK URLCheck discovery and avoid duplicated /v1
429Rate limit, account limits and returned error detailsReduce concurrency; honor Retry-After when present
5xxSanitized error and request IDInvestigate service/upstream failure; use bounded recovery
Timeout or broken streamWhether output or usage was already producedTreat completion as uncertain, not automatically failed

The table is a diagnostic starting point. Read the actual native error body; the same status can have several causes. A 429 is not proof that buying credit resolves the problem.

Retry only failures your application has classified as transient. Use exponential backoff with jitter, a small maximum attempt count, an overall deadline and a total cost budget. Stop at whichever bound is reached first. Respect Retry-After when supplied; do not promise that every response contains it.

Check SDK retry defaults before adding an outer retry loop. Nested retries multiply requests. Do not silently switch models on failure: changed capabilities and output behavior can invalidate the user’s task or your evaluation.

A timed-out generation may still have run. This guide does not assume idempotency support for LLM POST endpoints, or that resending the same body deduplicates usage. After partial output, preserve the partial result and ask the application/user to choose recovery rather than automatically replaying it.

Include a minimal sanitized request shape, endpoint, model ID, timestamps with timezone, status, request ID, and whether the issue reproduces. Exclude credentials and customer content. Report usage as observed, missing or pending; do not mark absent receipts as zero cost.

For a newly integrated application, return to the minimal first request. For errors only during streaming, check event parsing and completion. Review cost accounting before approving a larger retry experiment.