Claude API errors
Understand the HTTP status codes, error response shape, and request IDs the Claude API returns, and handle errors with the SDK’s typed exceptions.
To find the SDK error that an API error becomes, see SDK error types. To catch it in your code, see Handle errors.
HTTP errors
The API follows a predictable HTTP error code format:
-
400 -
invalid_request_error: There’s an issue with the format or content of your request. The API might also use this error type for other 4XX status codes not listed in this section. The API also returns a 400 when usage reaches an organization or workspace spend limit you set. Limits on the Claude Code workspace are the exception: they can return a 429 instead. If the message names a problem with your request, look for it in Common validation errors. -
401 -
authentication_error: There’s an issue with your API key (for example, it’s malformed, revoked, or expired; see Key expiration). On Claude Platform on AWS, this can also indicate a problem with your AWS credentials or SigV4 signature.On Claude Models on Google Cloud (Anthropic managed), a 401 can mean a problem with your Google Cloud credentials.
A 401 whose message begins
CORS requests are not allowed for this Organizationis not a problem with your API key. The request included anOriginheader, which browsers add, and your organization cannot call the Claude API directly from a browser. The message continuesbecause of custom retention settingsorbecause of its settings. The first appears only for data retention arrangements such as zero data retention (ZDR); the second is the general case. No change to the browser request fixes it, so send the request from your own back end; see Browser-based applications. -
402 -
billing_error: There’s an issue with your billing or payment information. Check your payment details in the Claude Console, or in AWS Marketplace if you’re using Claude Platform on AWS. -
403 -
permission_error: Your API key does not have permission to use the specified resource. Check your organization’s access and workspace settings in the Claude Console.On Claude Models on Google Cloud (Anthropic managed), Google Cloud checks each request before forwarding it to Anthropic. To fix a 403, do the following:
- Check that
claude.googleapis.comis enabled on your project. - Check that the caller’s IAM role allows the request.
- If the 403 says
Permission 'UNKNOWN' denied, check the request’s path. Google Cloud doesn’t offer that route, so no IAM role fixes it.
- Check that
-
404 -
not_found_error: The requested resource was not found. Check the endpoint path and any resource IDs in the request URL. -
409 -
conflict_error: The request conflicts with the current state of a resource. For example, the resource was modified concurrently, or a value that must be unique is already in use. Resolve the conflict, then retry the request. -
413 -
request_too_large: Request exceeds the maximum allowed number of bytes. See Request size limits for per-endpoint maximums. -
429 -
rate_limit_error: Your organization has hit a rate limit, reached its usage tier’s monthly spend cap, or reached a spend limit on the Claude Code workspace. A tier spend-cap 429 has noretry-afterheader and keeps failing until access resumes; see Reaching your spend cap for how to recognize it. A sharp increase in usage can also cause a 429 even while you’re under your rate limits; see Ramp limits.To tell the spend cap from a rate limit in code, check the error code.
-
500 -
api_error: An unexpected error has occurred internal to Anthropic’s systems. Retry only if the response’sx-should-retryheader isn’tfalse(see Retries). If the error persists, contact support with the request ID. If the error type istimeout_errorinstead, see the 504 entry. -
504 -
timeout_error: The request timed out while processing. The API also returnstimeout_errorwith other status codes, such as a 500 when a request reaches the server’s time limit before the response starts. For long-running Messages API requests, use the streaming Messages API. See Long requests for more options. -
529 -
overloaded_error: The API is temporarily overloaded.
When receiving a streaming response over server-sent events (SSE), an error can occur after the API returns a 200 response. In that case, error handling doesn’t follow these standard mechanisms. See Error events for the shape of mid-stream errors.
The SDK doesn’t retry an error in a stream. To catch one, see Handle an error in a stream.
Retries
By default, the SDK retries a failed request up to two times (three attempts in all). To change the number of retries, set max_retries on the client. A value of 0 turns retries off.
For each failed attempt, the SDK determines two things:
- Whether the SDK retries: If the response has an
x-should-retryheader (trueorfalse), the SDK follows it. Otherwise, the SDK retries connection errors, timeouts, and the statuses 408, 409, 429, and 500 and above. - How long the SDK waits: If the response has a
retry-afterheader, the SDK waits as long as the header says. Otherwise, it uses exponential backoff from 0.5 to 8 seconds.
The Go SDK retries some create methods in fewer cases. See Retries for create methods in the Go SDK.
Without the SDK, follow x-should-retry and retry-after in your own code and use backoff and a retry limit.
Request size limits
The first-party Claude API enforces these request size limits. For other platforms, see the API overview.
| Endpoint type | Maximum request size |
|---|---|
| Messages API | 128 MB |
| Token Counting API | 128 MB |
| Batch API | 256 MB |
| Files API | 500 MB |
If you exceed these limits, you’ll receive a 413 request_too_large error. On the first-party Claude API, Cloudflare returns this error before the request reaches the API servers.
Error shapes
The API always returns errors as JSON, with a top-level error object that always includes a type and message value. The response also includes a request_id field for easier tracking and debugging. For example:
{
"type": "error",
"error": {
"type": "not_found_error",
"message": "The requested resource could not be found."
},
"request_id": "req_011CSHoEeqs5C35K2UUqR7Fy"
}Under the API versioning policy, the values within these objects can expand, and new type values can appear.
Error codes
Some errors also have an error code in error.details.error_code. One type can cover several causes, and a code names one of them.
For example, hitting a rate limit and reaching your monthly spend cap both cause a 429 rate_limit_error. On the Messages API, the spend-cap response adds a code:
{
"type": "error",
"error": {
"type": "rate_limit_error",
"message": "You have reached your API usage limits: ...",
"details": { "error_code": "enforced_spend_limit_reached" }
},
"request_id": "req_018EeWyXxfu5pfWkrYcMdjWG"
}Other APIs that return this 429, such as Claude Managed Agents, don’t add the code. There, only the message tells the two causes apart, and you shouldn’t match it in code. A spend-cap 429 keeps failing until access resumes, so limit your retries after a 429.
The set of codes can grow. If an error has no code or has a code that you don’t recognize, handle it by its type or HTTP status.
For the full list of codes, see ErrorDetailsPreview with links to the API reference available — press Tab until focus enters the card, Escape to return. in the API reference. To find the codes that a method can return, see Handle a specific error code.
SDK error types
This section lists what to catch or check in the SDK for each kind of error. To write a handler, see Handle errors.
These classes are in the anthropic package unless a row names another. A class also catches its subclasses, so put the narrower class first. For example, RateLimitError also catches EnforcedSpendLimitReachedError.
| To handle | Catch |
|---|---|
| One error code | Its own class, such as anthropic.EnforcedSpendLimitReachedError (see Handle a specific error code) |
| 400 | BadRequestError |
| 401 | AuthenticationError |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 409 | ConflictError |
| 413 | ContentTooLargeError |
| 422 | UnprocessableEntityError |
| 429 | RateLimitError |
| 504 | GatewayTimeoutError |
| 529 | OverloadedError |
| Every 5xx, such as 500, 504, and 529 | InternalServerError |
| Every error response | APIStatusError |
| An error event in a stream | APIStatusError |
| A client timeout (the SDK stopped waiting) | APITimeoutError |
| Every connection failure before a response arrives (including a client timeout) | APIConnectionError |
| A connection that drops or stalls in mid-stream | httpx2.TransportError (httpx2 is the SDK’s HTTP library) |
| Every error in this table except a dropped stream | APIError |
For a status that has no row, such as 402, catch APIStatusError and compare its status_code.
To reach the underlying exception or the raw response, see Handling errors in Python.
The table goes by HTTP status and error code, not by error.type:
- A 503 with
overloaded_errorcounts as a 5xx, not as a 529. - An error event in a stream never matches a status row or a code’s class. Its HTTP status is the stream’s 200 or is missing.
To go by error.type instead, check the error’s type as in Handle an error in a stream.
Request ID
Every API response includes a unique request-id header. This header contains a value such as req_018EeWyXxfu5pfWkrYcMdjWG. The same identifier appears as the request_id field in error response bodies. When contacting support about a specific request, include this ID to help quickly resolve your issue.
On Claude Platform on AWS, responses include two request IDs: the AWS request ID (x-amzn-requestid, primary, indexed in CloudTrail) and the Anthropic request ID (request-id, secondary). Use the AWS request ID for CloudTrail lookups and the Anthropic request ID for Anthropic support tickets.
When the API returns an error response, read the ID from the SDK error in request_id. For a sample, see Catch errors by kind. When a request succeeds, read the ID from the response.
The Python and TypeScript SDKs expose the request ID as a _request_id property on top-level response objects. The C#, Go, Java, and PHP SDKs expose it through their raw-response accessors, and the Ruby SDK through middleware. In every SDK except Ruby, use with_raw_response to read any other response header, such as anthropic-organization-id and anthropic-workspace-id. In Ruby, use the same middleware. On Claude Platform on AWS, use the raw-response accessor to read the AWS request ID (x-amzn-requestid) as well:
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude"}],
)
print(f"Request ID: {message._request_id}")For Claude Platform on AWS request-ID examples in other languages, see Request IDs.
Long requests
Avoid setting a large max_tokens value without using the streaming Messages API
or Message Batches APIPreview with links to the API reference available — press Tab until focus enters the card, Escape to return.:
- Some networks might drop idle connections after a variable period of time, which can cause the request to fail or time out without receiving a response from Anthropic.
- Networks differ in reliability. The Message Batches APIPreview with links to the API reference available — press Tab until focus enters the card, Escape to return. can help you manage the risk of network issues by allowing you to poll for results rather than requiring an uninterrupted network connection.
If you are building a direct API integration, setting a TCP socket keep-alive can reduce the impact of idle connection timeouts on some networks.
The Anthropic SDK validates that your non-streaming Messages API requests are not expected to exceed a 10-minute timeout. It also sets a socket option for TCP keep-alive.
If you don’t need to process events incrementally, the SDK can consume the stream for you and return the complete Message object, identical to what a non-streaming call returns:
client = anthropic.Anthropic()
with client.messages.stream(
max_tokens=128000,
messages=[{"role": "user", "content": "Write a detailed analysis..."}],
model="claude-sonnet-5",
) as stream:
message = stream.get_final_message()
print(next(block.text for block in message.content if block.type == "text"))See Get the final message without handling events for more details.
Common validation errors
Prefill not supported
Claude 4.6 and later models and Claude Mythos Preview do not support prefilling assistant messages. Sending a request with a prefilled last assistant message to any of these models returns a 400 invalid_request_error:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "This model does not support assistant message prefill. The conversation must end with a user message."
}
}Use structured outputs on models that support it, system prompt instructions, or output_config.format instead.
Thinking blocks cannot be modified
If thinking blocks in the request don’t match what the API returned, the request can get a 400 invalid_request_error. The error message starts with the position of the offending block (for example, messages.1.content.0) and contains:
`thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.With tool use, pass back every thinking and redacted_thinking block from the assistant turn exactly as received, including blocks whose thinking field is empty. If your application filters content blocks by type before resending, include both thinking and redacted_thinking. This is a different failure from the prefix check, whose error says that a block is bound to a different conversation. Setting prefix_mismatch_behavior might not clear it. See the fix for modified thinking blocks in Troubleshooting thinking.
Extended thinking not supported
Claude 4.7 and later models don’t support extended thinking. Sending thinking: {"type": "enabled"} to any of these models returns a 400 invalid_request_error:
"thinking.type.enabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.Use adaptive thinking instead. For the parameter mapping, see Migrating to adaptive thinking. To fix the error from its symptom, see A 400 error says "thinking.type.enabled" is not supported.
Adaptive thinking not supported
Models that support only extended thinking (Claude 4.5 and earlier models) reject thinking: {"type": "adaptive"} with a 400 invalid_request_error:
adaptive thinking is not supported on this modelUse thinking: {"type": "enabled", "budget_tokens": N} on these models; see Extended thinking for the configuration and the symptom-first fix for the adaptive thinking error in Troubleshooting thinking.
Thinking cannot be disabled
On Claude Fable 5.2, Claude Mythos 5.2, Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, Claude Mythos 5, Claude Opus 5.5, and Claude Mythos Preview, thinking is always on. Sending thinking: {"type": "disabled"} to any of these models returns a 400 invalid_request_error. On all of these models except Claude Mythos Preview, the message reads:
"thinking.type.disabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.On Claude Mythos Preview, the only one of these models that accepts extended thinking, the message reads:
"thinking.type.disabled" is not supported for this model. Thinking defaults to adaptive mode when not specified; use "thinking.type.enabled" with "budget_tokens" for extended thinking.On Claude Sonnet 5.5, thinking can’t be set to disabled. Use thinking: {"type": "between_tools"} for the lowest thinking setting, which turns off up-front thinking. Sending thinking: {"type": "disabled"} returns a 400 invalid_request_error with this message:
To turn thinking off on this model, send "thinking": {"type": "between_tools"} instead of {"type": "disabled"}. The model does not think before responding. The short updates it writes between tool calls come back as thinking blocks.At xhigh or max effort, a request with between_tools also returns a 400 invalid_request_error. The error message says thinking is disabled because between_tools has no up-front thinking:
output_config.effort 'xhigh' is not supported when thinking is disabled on this model. Use effort 'high' or below, or enable thinking.With between_tools, effort can’t change mid-conversation: a per-message output_config.effort that differs from the level in effect returns a 400 error. The error names the position of the message that set the new level:
messages.N: output_config.effort 'low' differs from the 'high' in effect before it; effort cannot change when thinking is disabled on this model. Use effort 'high', or enable thinking.Claude Haiku 5.5 accepts thinking: {"type": "disabled"} and holds it to the same two effort limits that apply to between_tools: at xhigh or max effort, or with a per-message output_config.effort that differs from the level in effect, the request returns a 400 invalid_request_error with the matching message shown earlier.
In both messages, “enable thinking” means adaptive thinking: omit the thinking field or send thinking: {"type": "adaptive"}. Claude Sonnet 5.5 and Claude Haiku 5.5 also reject "enabled" with a 400 error. To vary effort for each turn, use adaptive thinking.
Sending thinking: {"type": "between_tools"} to any model other than Claude Sonnet 5.5 returns a 400 invalid_request_error:
"thinking.type.between_tools" is not supported for this model.For the fixes, see the between_tools and effort errors in Troubleshooting thinking.
Omit the thinking parameter and the request runs with adaptive thinking. To keep thinking content out of responses without turning thinking off, set display: "omitted" on the thinking configuration. See the fix for the disabled thinking error in Troubleshooting thinking.
Forced tool use not supported
Claude Fable 5.2, Claude Mythos 5.2, Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1, and Claude Mythos 5.1 don’t support forced tool use. Sending tool_choice: {"type": "any"} or tool_choice: {"type": "tool", "name": "..."} to any of these models, including on the token counting endpoint, returns a 400 invalid_request_error:
tool_choice: type "tool" and "any" are not supported for this model.tool_choice: {"type": "auto"} (the default) and {"type": "none"} are accepted. Use auto with strict tool use to keep tool inputs schema-valid, or structured outputs when you need the response itself in a fixed JSON shape. See Forcing tool use.
Computer use tool version not supported
Claude Fable 5.2, Claude Mythos 5.2, Claude Opus 5.5, Claude Sonnet 5.5, and Claude Haiku 5.5 return a 400 error for any computer use tool version they don’t accept. On the Claude API, that includes computer_20251124 with its beta header. They don’t accept computer_20250124 on any platform. The Claude API’s invalid_request_error message names the rejected type and, after Did you mean one of, lists the tool types the model accepts. For Claude Opus 5.5, the message begins:
'claude-opus-5-5' does not support tool types: computer_20251124.The Claude API returns the same message for any Anthropic-defined tool type that the requested model doesn’t support. Claude Fable 5.2, Claude Mythos 5.2, Claude Opus 5.5, Claude Sonnet 5.5, and Claude Haiku 5.5 support computer use through the computer_toolset_20260801 toolset. Declare {"type": "computer_toolset_20260801"} without the beta header and update your agent loop as described in Migrate from computer_20251124. To move from computer_20250124, see Move computer use to the toolset in the Claude Haiku 5.5 migration guide.
On Amazon Bedrock, Claude Fable 5.2, Claude Mythos 5.2, Claude Opus 5.5, Claude Sonnet 5.5, and Claude Haiku 5.5 also accept the computer_20251124 tool with the computer-use-2025-11-24 beta header. With Amazon Bedrock’s InvokeModel API, send computer-use-2025-11-24 in the anthropic_beta array of the request body instead of in a header. For that API, see Claude on Amazon Bedrock (bedrock-runtime). For the models to use with each earlier version, see Earlier tool versions.
Thinking block bound to a different conversation
This 400 invalid_request_error means a thinking block you sent back failed the prefix check. Compare system, tools, and the messages before the block with what you sent when the model produced it. For which changes matter, see What counts as a change. The error message starts with the position of the first failing block:
messages.{i}.content.{j}: Invalid `signature` in `thinking` block. The block is bound to a different conversation. Remove the block, or set `thinking.block_binding.prefix_mismatch_behavior` to "drop_block".Resending the same history fails the same way. Fixing the code that made the edit doesn’t help this conversation if the edit is still in its history. To continue, do one of the following:
- Send the
thinking-binding-controls-2026-08-01beta header and setthinking.block_binding.prefix_mismatch_behaviorto"drop_block", on the retry and on every later request in that conversation. On Claude Sonnet 5.5 and Claude Haiku 5.5,block_bindingworks only withthinking: {"type": "adaptive"}. - Strip the block the error names and every
thinkingandredacted_thinkingblock after it, in that message and in every later message. Retry, and leave the stripped blocks out of later requests.
To stop new conversations from failing, keep the history append-only. See the fix for an invalid thinking block signature in Troubleshooting thinking.
Sending thinking.block_binding without the thinking-binding-controls-2026-08-01 beta header returns a 400 invalid_request_error whose message ends in:
block_binding: Extra inputs are not permittedAdd the header, turn thinking on, or remove the field.
Outbound web identity federation disabled (Claude Platform on AWS)
If every request to Claude Platform on AWS returns "Outbound web identity federation is disabled for your account", run aws iam enable-outbound-web-identity-federation once for each AWS account. See Enable outbound web identity federation for details.
Next steps
Symptom-first fixes for thinking configuration 400 errors, empty thinking blocks, and max_tokens stops.
To mitigate misuse and manage capacity on the API, limits are in place on how much an organization can use the Claude API.
Use the SDK to catch Claude API errors by error code, HTTP status, or connection failure and to handle an error that arrives in a stream.
Was this page helpful?