LLM API Errors — Meaning & Fix
A quick reference for the errors you actually hit calling OpenAI, Anthropic, and Gemini APIs — what each one means and the fastest way to fix it.
context_length_exceeded· OpenAI, AzureWhat it means: Your prompt plus the requested max_tokens exceeds the model's context window. The request is rejected before any tokens are generated.
How to fix: Shorten the prompt, lower max_tokens, or switch to a larger-context model. Check the prompt against the window first with a context-window checker.
→ Context Window Checkerinvalid_request_error (Anthropic) / INVALID_ARGUMENT (Gemini)· Anthropic, GoogleWhat it means: Malformed request — usually a bad messages array, an unknown parameter, or a schema that doesn't match the provider's tool format.
How to fix: Validate your messages array roles/content and confirm your tool definitions match the provider's exact envelope.
→ Schema → Tool Definitioninvalid_api_key / authentication_error· AllWhat it means: The API key is missing, revoked, or wrong. Common when the key isn't loaded from the environment or a trailing space sneaks in.
How to fix: Confirm the key is set in your environment (never hard-coded), has no whitespace, and belongs to the right org/project.
permission_denied / model_not_found· OpenAI, Anthropic, GoogleWhat it means: Your key is valid but not allowed to use this model — often a model you haven't been granted access to, or a region restriction.
How to fix: Request access to the model, use a model your tier supports, or check regional availability.
model_not_found· AllWhat it means: The model name is misspelled or has been deprecated and removed.
How to fix: Use the exact current model id. Deprecated models are removed on a schedule — check the provider's model list.
→ Current model list & pricingrate_limit_exceeded / too_many_requests· AllWhat it means: You've exceeded requests-per-minute (RPM) or tokens-per-minute (TPM) for your tier. The most common production error.
How to fix: Add exponential backoff with jitter, batch requests, or raise limits by upgrading tier. Respect the Retry-After header when present.
insufficient_quota· OpenAIWhat it means: Different from a rate limit — your account has no remaining credit or billing isn't set up. The wording is misleading; it's a billing issue, not throughput.
How to fix: Add a payment method or top up credits. This won't resolve with backoff.
server_error / api_error· AllWhat it means: An unexpected error on the provider's side. Usually transient.
How to fix: Retry with exponential backoff. If it persists, check the provider's status page.
overloaded_error· AnthropicWhat it means: Anthropic's API is temporarily overloaded. Spikes during peak hours.
How to fix: Retry with backoff and jitter. Consider a fallback model or provider for high-availability paths.