Skip to content

AI API Error Decoder

Decode an error response from the OpenAI, Anthropic, Gemini, Mistral or Cohere API into its cause, a Python and Node.js fix and a retry strategy.

AI API Error Decoder

244 chars

OpenAI 401: Invalid API Key

Provider:OpenAI
Status:401
Type:authentication_error
Invalid API Key
What happened

The API key you provided is invalid or has been revoked. OpenAI cannot authenticate your request.

Root cause

The API key is either malformed, expired, deleted from your account, or belongs to a different organization.

How to fix

Verify your API key starts with 'sk-' and regenerate it at platform.openai.com/api-keys. Check that the key belongs to the correct organization.

import openai
import os

# Store key in environment variable, never hardcode
client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"])

# Verify key works
try:
    client.models.list()
    print("API key is valid")
except openai.AuthenticationError:
    print("Invalid API key - regenerate at platform.openai.com/api-keys")
Retry strategy
Strategy
Do not retry
Max retries
0
Delay pattern
N/A
Details

Do not retry. Fix the API key first.

Common mistakes
  • !Using a project key (sk-proj-) where an org key is expected
  • !Copying extra whitespace with the key
  • !Using a key from a deleted project
Related errors
Malformed API Key (400)
Parsed response
{
  "error": {
    "message": "Incorrect API key provided: sk-1234****abcd. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

What this tool does

Paste an error response from the Claude, OpenAI, Gemini, Cohere, or Mistral API and the decoder identifies the provider, matches the error against its pattern database, and explains what went wrong in plain language — with a fix snippet and a retry strategy. Matching runs in your browser. Key nuance: a 429 can mean rate limiting (retry with backoff) or exhausted credits (retrying never helps).

Updated . Provided as is. Check the output before you rely on it in production.

How to use AI API Error Decoder

  1. 1

    Paste the error response

    Copy the full error response from your API call — JSON, text, or HTTP response body — and paste it into the input area.

  2. 2

    Check the auto-detected provider

    The tool identifies the API provider (OpenAI, Claude, Gemini, Cohere, Mistral) from the error format and shows the specific error type and HTTP status.

  3. 3

    Read the explanation and fix

    The decoded output includes a plain-English explanation, root cause, and fix code snippets in Python and Node.js that you can copy directly into your project.

  4. 4

    Apply the retry strategy

    Follow the recommended retry strategy — whether to retry immediately, use exponential backoff, or not retry at all — with suggested delay patterns and maximum retry counts.

Questions and answers

What is AI API Error Decoder?
AI API errors are the status codes and JSON bodies a model provider returns when a request fails, such as 401 invalid key or 429 rate limit. This decoder detects the provider from the pasted response, matches it against a library of known error patterns and returns the cause, Python and Node.js fixes and a retry strategy.
Which API providers are supported?
OpenAI (GPT), Anthropic (Claude), Google (Gemini), Cohere, and Mistral. The tool auto-detects the provider from the error response format.
Does it send my error responses to a server?
No. All decoding happens in your browser using a static error pattern database. Your API errors — which may contain sensitive information — never leave your device.
How many error patterns does it cover?
The pattern library covers OpenAI, Anthropic, Google, Mistral and Cohere errors plus generic network, JSON parse, CORS, TLS and proxy failures. They cover invalid keys, rate limits, quota, context length, content filters, malformed requests, deprecated parameters and server errors.
For AI agents: how to call this tool

Machine-readable contract, endpoints and examples. Humans can ignore this section.

Best Path For Builders

Browser workflow

Runs instantly in the browser with private local processing and copy/export-ready output.

Browser Workflow

This tool is optimized for instant in-browser execution with local data handling. Run it here and copy/export the output directly.

/ai-api-error-decoder/

For automation planning, fetch the canonical contract at /api/tool/ai-api-error-decoder.json.

How do I fix an error response from the OpenAI, Claude, or Gemini API?

Paste the raw error — the JSON body, the exception message, or the whole log line. The decoder detects the provider from key prefixes and vocabulary in the message, matches it against a database of known error patterns across OpenAI, Anthropic, Google Gemini, Cohere, and Mistral (plus provider-agnostic network, JSON-parse, CORS, SSL, and proxy failures), and returns the root cause, a Python and Node.js fix snippet, and whether retrying is worth it.

Step by step

  1. Copy the full error response — including the JSON body if you have it, since fields like error.type and error.code make matching precise.
  2. Paste it into the decoder. Provider, status code, and the matched pattern appear immediately.
  3. Read the root cause before the fix — many AI API errors look transient but are configuration problems that no retry will solve.
  4. Apply the fix snippet in Python or Node.js, and adopt the suggested retry strategy (none, immediate, or exponential backoff) in your client.

Common AI API error codes by provider

Provider Status / code Meaning and action
OpenAI 429 rate_limit_exceeded Too many requests or tokens per minute. Retry with exponential backoff plus jitter.
OpenAI 429 insufficient_quota Out of credits or spend cap hit — a billing state, not a rate limit. Do not retry; add credits.
OpenAI 400 context_length_exceeded Input plus max_tokens exceeds the model's context window. Trim messages; count tokens first.
Anthropic 401 authentication_error Missing or invalid x-api-key. Keys start with sk-ant-; do not retry, fix the key.
Anthropic 529 overloaded_error Anthropic-specific capacity signal. Retry with long delays (30s+) or fall back to another model.
Google Gemini 429 RESOURCE_EXHAUSTED Quota exceeded on the API key or project. Back off, then review quota settings.
Google Gemini 200 + SAFETY block The HTTP call succeeds but the candidate is blocked by the safety filter — check finish reason, not just status.
Mistral 422 validation_error Request body fails schema validation. Fix the parameters; retrying the same body always fails.
Cohere 401 unauthorized Invalid or revoked API key. Do not retry; regenerate the key.
Any 502 bad_gateway A proxy or gateway between you and the provider failed. Retry briefly; check your egress path.

Codes and meanings as implemented in this tool's error database; providers evolve their error surfaces, so treat the provider's own docs as final.

When should I retry an AI API error?

Retry only what is transient: rate limits (with exponential backoff and jitter, honoring a retry-after header when present), 5xx server errors, and overload responses. Never blind-retry authentication failures, malformed requests, context-length errors, or quota exhaustion — those return the same failure every time and can amplify an outage. The decoder marks each matched error with its retry strategy so the distinction is explicit.

Do pasted error responses leave the browser?

No. Detection and pattern matching run client-side against a local database; nothing is uploaded or logged. Error bodies often quote your prompt, internal identifiers, or a partially masked API key, so a local-only decoder is the safe way to debug them.