Anthropic Claude API error
Anthropic API 400 invalid_request_error: what it means and how to fix it
400 invalid_request_errorRetry? Not statedLast verified 5 documented fixes1 source
What it means
There was an issue with the format or content of your request. This error type may also be used for other 4XX status codes not listed in the docs.
Causes
- Malformed or invalid request format or content
- Sending a prefilled last assistant message to Claude 4.6 and later models ("This model does not support assistant message prefill. The conversation must end with a user message.")
- Editing, reordering, filtering or reconstructing thinking or redacted_thinking blocks in the latest assistant message before sending them back
- Sending thinking: {"type": "enabled"} to Claude 4.7 and later models, or thinking: {"type": "adaptive"} to Claude 4.5 and earlier models
- Sending thinking: {"type": "disabled"} to models where thinking is always on
- Sending tool_choice type "tool" or "any" to models that do not support forced tool use
- Declaring an Anthropic-defined tool type the requested model does not support
- Sending thinking.block_binding without the thinking-binding-controls-2026-08-01 beta header
How to fix it
- Fix 1.
Check the request format and parameters against the API reference and the Common validation errors section of the errors page.
- Fix 2.
On models that do not support prefill, use structured outputs, system prompt instructions, or output_config.format instead.
- Fix 3.
Pass thinking and redacted_thinking blocks back exactly as received, including blocks whose thinking field is empty.
- Fix 4.
Use adaptive thinking on models that removed extended thinking, and thinking: {"type": "enabled", "budget_tokens": N} on models that only support extended thinking.
- Fix 5.
Use tool_choice auto (the default) with strict tool use, or structured outputs, on models that reject forced tool use.
Seen in coding agents
These coding agent messages pass this Anthropic API error through. Each page has the agent-specific fix.
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.5: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01FRvEykWmCgrgJ22mvBbKhV. Each `tool_use` block must have a corresponding `tool_result` block in the next message."}}Status: OpenClaude CodeAI_APICallError: messages.13: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01CfJCsh21fK1pAXsXWYJYBA, toolu_01NoqnwsaxoK3AYM2FyrxmjN. Each `tool_use` block must have a corresponding `tool_result` block in the next message.Status: Fixed in releaseOpenCodemessages.3.content.0.type: Expected `thinking` or `redacted_thinking`, but found `tool_use`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`.Status: WorkaroundOpenCode
More Anthropic API errors
All 13 Anthropic API errors400 invalid_request_error (spend limit reached)Retry? Not stated401 authentication_errorRetry? Not stated402 billing_errorRetry? Not stated403 permission_errorRetry? Not stated404 not_found_errorRetry? Not stated409 conflict_errorRetry? Yes413 request_too_largeRetry? Not stated429 rate_limit_errorRetry? Yes
HTTP 400 at other providers
Compare 400 across providers400 ValidationExceptionRetry? NoAmazon Bedrock400 ServiceQuotaExceededExceptionRetry? YesAmazon Bedrock400 IncompleteSignatureRetry? Not statedAmazon Bedrock400 InvalidActionRetry? Not statedAmazon Bedrock400 NotAuthorizedRetry? Not statedAmazon Bedrock400 RequestExpiredRetry? Not statedAmazon Bedrock400 Bad RequestRetry? Not statedAzure OpenAI400 content_filterRetry? Not statedAzure OpenAI400 Bad RequestRetry? Not statedCohere API400 Bad Request (too many tokens)Retry? Not statedCohere API400 - Invalid FormatRetry? Not statedDeepSeek API400 invalid_requestRetry? NoGemini API
FAQ
What does the Anthropic API error "400 invalid_request_error" mean?
There was an issue with the format or content of your request. This error type may also be used for other 4XX status codes not listed in the docs.
How do I fix Anthropic API "400 invalid_request_error"?
There are 5 documented fixes. Start with the first: Check the request format and parameters against the API reference and the Common validation errors section of the errors page.
Should I retry Anthropic API "400 invalid_request_error"?
Not stated. The official docs do not say whether this error is retryable.
Which other AI APIs return HTTP 400?
Per their official error docs: Amazon Bedrock (400 ValidationException; 400 ServiceQuotaExceededException; 400 IncompleteSignature; 400 InvalidAction; 400 NotAuthorized; 400 RequestExpired), Azure OpenAI (400 Bad Request; 400 content_filter), Cohere API (400 Bad Request; 400 Bad Request (too many tokens)), DeepSeek API (400 - Invalid Format), Gemini API (400 invalid_request; 400 failed_precondition; 400 parameter_unknown; 400 INVALID_ARGUMENT; 400 FAILED_PRECONDITION), Groq API (400 Bad Request), Mistral API (400 Bad request), OpenAI API (400 invalid_request_error (Invalid service_tier argument); 400 BadRequestError), OpenRouter (400 invalid_request; 400 invalid_prompt; 400 context_length_exceeded; 400 max_tokens_exceeded; 400 token_limit_exceeded; 400 string_too_long; 400 invalid_image; 400 image_too_large; 400 image_too_small; 400 unsupported_image_format; 400 image_download_failed), Vertex AI (400 INVALID_ARGUMENT / FAILED_PRECONDITION), xAI API (400 Bad Request).
Sources
Last verified against 1 source: Anthropic API's official docs and official SDK repositories.
- platform.claude.comhttps://platform.claude.com/docs/en/api/errors
Newsletter
Know when the APIs change
One email per week. New model releases, API changes, what broke, and how developers are working around it.