Claude API Error Codes: A Complete Reference Guide
If you're debugging a failed request, you want one thing: a mapping of each Claude API error code to its cause and fix, without wading through unrelated documentation. This guide covers every HTTP status code and error type the Claude API returns, what triggers it, and how to handle it in production code.
The short version: Claude API errors are JSON objects with a type field nested under error, and the HTTP status code tells you the error category at a glance. Once you know the pattern, every error response is self-explanatory — the hard part is building retry and fallback logic around them, which is what the second half of this article covers.
The error response shape
Every error from the Claude API looks like this:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages: at least one message is required"
}
}
The HTTP status code and the error.type field together tell you exactly what went wrong. You should always parse error.type, not just the status code, because some statuses (like 400) cover multiple distinct problems.
Error codes reference
400 — invalid_request_error
Something is malformed in the request body: a missing required field, an invalid parameter value, a message array that doesn't alternate roles correctly, or a max_tokens value outside the allowed range for the model. The message field usually pinpoints the exact field. Fix: validate request payloads client-side before sending, especially message role ordering and token limits.
401 — authentication_error
The API key is missing, malformed, or revoked. This is the most common first-request error for new integrations. Check that:
- You're sending the key as a header, not a query parameter
- There's no stray whitespace or quote character copied from a
.envfile - The key hasn't been rotated or deleted from the dashboard
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $API_KEY" \
-H "anthropic-version: 2023-06-01"
403 — permission_error
The key is valid but doesn't have permission for the requested resource — for example, calling a model your account tier doesn't have access to, or using a feature gated behind a waitlist. Fix: check your account's model access list, or request access to the specific capability.
404 — not_found_error
The requested resource doesn't exist. Most commonly this is a typo in the model name (claude-3-5-sonne-20241022 instead of claude-3-5-sonnet-20241022) or referencing a message/batch ID that was deleted or never existed.
413 — request_too_large
The request body exceeds the maximum allowed size, usually from oversized file attachments or an extremely long conversation history. Fix: trim context, paginate large documents, or split the request.
429 — rate_limit_error
You've exceeded requests-per-minute, tokens-per-minute, or tokens-per-day limits for your account tier. This is the error you'll see most often once you're in production, and it's almost always recoverable with backoff — see the retry section below.
500 — api_error
An unexpected error on Anthropic's side. These are rare and not caused by anything in your request. Retry with backoff; if it persists, it's worth checking the provider's status page before assuming it's your code.
529 — overloaded_error
The API is temporarily overloaded and can't process the request. This spikes during high-traffic periods and is functionally similar to a 429 for retry purposes, but it reflects platform capacity, not your account's rate limit.
Building retry logic that actually works
Error codes are only useful if your client reacts to them correctly. A production-grade retry strategy should distinguish between errors worth retrying and errors that need a code fix:
| Status | Retry? | Strategy | |---|---|---| | 400, 401, 403, 404, 413 | No | Fix the request, don't retry | | 429 | Yes | Exponential backoff, respect retry-after header if present | | 500 | Yes | Exponential backoff, cap retries at 3–5 | | 529 | Yes | Exponential backoff with jitter |
A minimal backoff implementation in JavaScript:
async function callWithRetry(fn, maxRetries = 4) {
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
return await fn();
} catch (err) {
const retryable = [429, 500, 529].includes(err.status);
if (!retryable || attempt === maxRetries) throw err;
const delay = Math.min(1000 * 2 ** attempt, 15000) + Math.random() * 300;
await new Promise(r => setTimeout(r, delay));
}
}
}
The key mistakes teams make here: retrying 4xx errors (wastes calls and can trigger stricter rate limiting), not capping retry count (causes cascading failures under sustained 429s), and not adding jitter (causes thundering-herd retries across concurrent requests).
Where SubToAPI fits
If you're running Claude behind an application and want one less thing to reverse-engineer during an incident, SubToAPI wraps the same error semantics behind a stable HTTPS API with application-scoped keys (sub_live_...). Request and error logs are visible per key in the dashboard, so when a 429 or 500 happens you can see exactly which key, endpoint, and payload size triggered it without instrumenting your own logging first. Check the quickstart or the messages reference to see the request/response shape, and pricing for plan details — Solo, Team, and Scale all include a free trial at signup.
Logging errors for debugging
Regardless of which client you use, log these three fields on every failed request: error.type, the HTTP status, and the request ID (returned in response headers). The request ID is what support teams need to trace a specific failure server-side — without it, you're debugging blind.
questions
What does a 429 error mean on the Claude API? It means you've exceeded a rate limit — requests per minute, tokens per minute, or tokens per day for your account tier. It's not a code error; back off exponentially and retry.
Why am I getting a 401 even though my API key looks correct? Usually a formatting issue: extra whitespace, quotes copied from an env file, or sending the key as a query parameter instead of a header. Also check the key hasn't been revoked in your dashboard.
Should I retry every failed request automatically? No. Only retry 429, 500, and 529 with exponential backoff. 400, 401, 403, 404, and 413 indicate a problem with the request itself and will fail identically on retry until fixed.