Shipping an AI app or agent? Security review in 1 working day: $149 / ₹13,900. Request a review →
AI Review Ready
Home / Error fixes / Anthropic API 400 / 500
Fix · Claude API

Anthropic API error 400 and 500

400 invalid_request_error: something in your request is wrong or not allowed. Read error.message, it names the problem. 500 api_error: an unexpected error inside Anthropic's systems, not your code. Retry with backoff, unless the response header x-should-retry is false.

The error shape

{"type": "error",
 "error": {"type": "invalid_request_error", "message": "..."},
 "request_id": "req_..."}

Keep the request_id (also in the request-id response header; in Python, message._request_id). Anthropic support asks for it.

400 invalid_request_error: common causes

Message or situationFix
prompt is too longThe input alone is bigger than the model's context window. Shorten it, drop old turns, or summarise. In Claude Code this shows as Prompt is too long / Context limit reached · /compact or /clear to continue
A spend limit you set was reachedAnthropic: "The API also returns a 400 when usage reaches an organization or workspace spend limit you set." Raise or wait for the limit (Claude Code workspace limits return 429 instead)
This model does not support assistant message prefill. The conversation must end with a user message.Newer models don't take a prefilled assistant turn. End the messages list with a user message and use instructions or structured outputs instead
thinking or redacted_thinking blocks ... cannot be modifiedSend the latest assistant message's thinking blocks back exactly as you received them
"thinking.type.enabled" is not supported for this model / adaptive thinking is not supported on this modelThe thinking setting doesn't match the model. Check that model's docs and switch the thinking type
tool_choice: type "tool" and "any" are not supported for this model.Use auto or none with that model
... does not support tool types: ...The tool version isn't available on that model; use the version its docs list
max_tokens above the model's limit"Different models have different maximum values for this parameter": lower it to the model's maximum

Not a 400, even though it looks like one

  • Wrong or retired model name: 404 not_found_error. "Once the model is retired... the Messages API returns a 404". Update the model ID.
  • Request too big: 413 request_too_large. Limits: 128 MB for Messages and Token Counting, 256 MB for Batches, 500 MB for Files. Cloudflare rejects it before it reaches the API.
  • Too many requests: 429. See Anthropic 429 rate_limit_error.

500 api_error: what to do

  1. Retry with backoff. The official SDKs already retry twice (three attempts in all) on 408, 409, 429 and 500+, honour retry-after, and otherwise back off from 0.5 to 8 seconds. Change it with max_retries (Python) or maxRetries (TypeScript).
  2. Respect x-should-retry: false: Anthropic says don't retry then.
  3. Long requests: a 500 can carry timeout_error when a request hits the server's time limit. Use streaming or the Batches API, "especially those over 10 minutes".
  4. Still failing: check status.claude.com, then contact support with the request ID.

Claude Code prints it as API Error: 500 Internal server error. This is a server-side issue, usually temporary. Its docs: "It is not caused by your prompt, settings, or account."

Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review

FAQ

What does Anthropic API error 400 invalid_request_error mean?

The format or content of your request is wrong or not supported, for example a prompt longer than the context window, a reached spend limit, an assistant prefill on a model that doesn't allow it, or a thinking or tool_choice setting the model doesn't support. The error message names the problem.

Is a wrong model name a 400 error?

No. An invalid or retired model returns 404 not_found_error. Update the model ID to a current model.

Should I retry Anthropic API error 500?

Yes, with backoff, unless the x-should-retry header is false. The official SDKs retry twice by default. If it persists, check status.claude.com and contact support with the request ID.

Why does Claude Code say Prompt is too long?

The conversation is larger than the model's context window. Run /compact to summarise it or /clear to start fresh.

Related errors

Sources

Read 2 Dec 2026. These tools change often: if a step no longer matches, the linked page wins.

Related free tools