LLM API Errors: A Status-Code Troubleshooting Guide
An LLM API error does not always mean the model is unavailable. The cause may be an expired key, an incompatible endpoint, exhausted credits, or a request that exceeds model limits. This troubleshooting guide helps you identify the failing layer before changing settings or paying for repeated attempts.
Start here: capture the actual failure
Record the HTTP status, error message, request ID, timestamp, endpoint, model identifier, and elapsed time. Note whether failure happens before generation or midway through streaming. Redact API keys, authorization headers, and sensitive prompts before sharing logs. An SDK exception alone may hide the server's useful error details.
401 and 403: authentication or access problems
- 401 Unauthorized: Confirm the running process loads the intended key. Check for trailing whitespace, stale environment variables, and a key issued by a different provider. Restart applications that cache configuration.
- 403 Forbidden: Check account permissions, model access, and any organization or network restrictions. Read the response body; valid credentials do not guarantee access to every resource.
For OpenAI-compatible endpoints, authentication normally uses an Authorization header with a Bearer token. Other API formats may require different headers. Follow the endpoint's documented format rather than mixing authentication conventions.
404: wrong route or model identifier
A 404 can mean the URL is wrong, not just that a model is missing. For 59API, the service base URL is https://api.59api.com. Confirm the documented API prefix and endpoint before configuring your SDK; do not assume the root URL alone is sufficient or accidentally duplicate a version prefix.
Copy the exact API model identifier from the provider's current catalog. Display names such as Claude Haiku 4.5 or DeepSeek V4 Flash are not necessarily the strings accepted in the model field. Also confirm that the selected model supports your endpoint.
400, 413, and 422: fix the request, not the retry count
Depending on the provider, these statuses can indicate invalid fields, oversized bodies, or unsupported features. Reduce the request to one short text message and the required parameters. If that succeeds, restore images, tools, structured output, and optional settings one at a time.
- Context exceeded: Shorten conversation history or retrieved documents and reserve room for the requested output.
- Invalid tools: Validate schemas and ensure tool-result messages match their originating calls.
- Unsupported parameters: Remove settings the selected model or endpoint does not accept.
429: distinguish throttling from exhausted balance
Read the error body before retrying. A 429 may reflect requests-per-minute limits, token limits, concurrency limits, or an account quota. An exhausted balance needs billing action; repeated requests will not fix it.
For temporary throttling, honor Retry-After when present. Otherwise, use capped exponential backoff with random jitter and a small retry limit. Queue work, reduce parallel requests, and avoid synchronized retries across workers. Inspect documented rate-limit headers when available.
5xx errors and timeouts: retry selectively
Temporary server failures may justify bounded retries, but avoid multiplying retries across the SDK, application, and job queue. Check the provider's status notices and preserve request IDs for support.
For timeouts, distinguish connection establishment from waiting for generated output. Configure connection and read timeouts separately where supported. Longer outputs may need a larger read timeout or streaming. A disconnected request may still finish upstream, so retrying can duplicate work and charges; do not assume generation requests are idempotent.
FAQ: successful response, unexpected result?
Why does a 200 response fail during streaming? The connection can break after headers arrive. Use an SDK or proper server-sent-event parser, preserve incomplete chunks, and inspect in-stream error events.
Why is the answer cut off? Inspect the finish reason and output-token limit. A transport failure and an intentional length stop require different fixes.
Can switching models help? Sometimes, but first verify feature compatibility. A fallback will not repair malformed requests or invalid credentials.
Keep troubleshooting affordable with 59API
59API offers low-cost, pay-as-you-go access across multiple model families and advertises native official-quality models without downgrading. Its compatibility with Claude Code, Codex, Gemini CLI, and OpenAI SDKs can simplify integration. Check current pricing and referral rebate terms, then sign up when you are ready to test your workload.
¿Listo para empezar?
Conecta Claude y GPT en minutos a los precios más bajos, sin recortes. Regístrate para obtener tu clave API.
Registro gratis