Follow Discord
Sweep 22 Oct 2026 · 04:32Z Build v2.1.308 527 read Stable v2.1.308 Latest v2.1.308 Next v2.1.308 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One capture · api

One read of Claude Developer Platformapi-20261021T193714Z

242 pages moved out of 808 read.

Pages moved 242 significant first
Pages read 808 in this capture
Captured 19:37 UTC
Corpus hash 851c97e9b6f0 corpus-hash

What this read moved

51-75 of 242, page 3 of 10

This capture is too large to show at once. Changes 51-75 of 242 are below, significant first; the rest are on the following screens.

api/errors Changed · +15 / -15 lines

from line 31
3131* 529 - `overloaded_error`: The API is temporarily overloaded.
3232 
3333 <Warning>
34 529 errors can occur when the API experiences high traffic across all users.
34 A 529 error can occur when the API experiences high traffic across all users.
3535 
36 In rare cases, if your organization has a sharp increase in usage, you might see 429 errors because of acceleration limits on the API. To avoid hitting acceleration limits, ramp up your traffic gradually and maintain consistent usage patterns.
36 In rare cases, if your organization has a sharp increase in usage, you might see 429 errors because of acceleration limits on the API. To avoid hitting acceleration limits, increase your traffic gradually and maintain consistent usage patterns.
3737 </Warning>
3838 
3939The official SDK automatically retries transient failures (such as connection errors, rate limits, and 5xx server errors) with exponential backoff, twice by default, honoring the `retry-after` header when present. The SDK client accepts `max_retries` (typescript, java, php: `maxRetries`; csharp: `MaxRetries`; go: `option.WithMaxRetries`) to configure or disable this behavior.
from line 260
260260 
261261Avoid setting a large `max_tokens` value without using the [streaming Messages API](https://platform.claude.com/docs/en/build-with-claude/streaming) or [Message Batches API](https://platform.claude.com/docs/en/api/messages/batches/create):
262262 
263* Some networks may 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.
263* 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.
264264* Networks differ in reliability. The [Message Batches API](https://platform.claude.com/docs/en/api/messages/batches/create) can help you manage the risk of network issues by allowing you to poll for results rather than requiring an uninterrupted network connection.
265265 
266266If you are building a direct API integration, setting a [TCP socket keep-alive](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/programming.html) can reduce the impact of idle connection timeouts on some networks.
267267 
268The [SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) validate that your non-streaming Messages API requests are not expected to exceed a 10-minute timeout. They also set a socket option for TCP keep-alive.
268The [Claude SDK](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) 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.
269269 
270270If 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:
271271 
from line 422
422422 ```
423423</CodeGroup>
424424 
425See [Streaming Messages](https://platform.claude.com/docs/en/build-with-claude/streaming#get-the-final-message-without-handling-events) for more details.
425See [Streaming messages](https://platform.claude.com/docs/en/build-with-claude/streaming#get-the-final-message-without-handling-events) for more details.
426426 
427427## Common validation errors
428428 
from line 450
450450`thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.
451451```
452452 
453With tool use, every `thinking` and `redacted_thinking` block from the assistant turn must be passed back exactly as received, including blocks whose `thinking` field is empty. Pass thinking blocks back unchanged, and if your application filters content blocks by type before resending, include both `thinking` and `redacted_thinking`. See [Troubleshooting thinking](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-blocks-modified), [Preserving thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#preserving-thinking-blocks), and [Preserved thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-thinking).
453With tool use, every `thinking` and `redacted_thinking` block from the assistant turn must be passed back exactly as received, including blocks whose `thinking` field is empty. Pass thinking blocks back unchanged, and if your application filters content blocks by type before resending, include both `thinking` and `redacted_thinking`. See the [fix for modified thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-blocks-modified) in Troubleshooting thinking, and also [Preserving thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#preserving-thinking-blocks) and [Preserved thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-thinking).
454454 
455455### Extended thinking not supported
456456 
from line 460
460460"thinking.type.enabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.
461461```
462462 
463Use [adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking) instead. [Migrating to adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking#migrating-to-adaptive-thinking) shows the parameter mapping, and [Troubleshooting thinking](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-enabled) covers the symptom-first fix.
463Use [adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking) instead. [Migrating to adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking#migrating-to-adaptive-thinking) shows the parameter mapping, and Troubleshooting thinking covers the [symptom-first fix for the extended thinking error](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-enabled).
464464 
465465### Adaptive thinking not supported
466466 
from line 470
470470adaptive thinking is not supported on this model
471471```
472472 
473Use `thinking: {"type": "enabled", "budget_tokens": N}` on these models; see [Extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking) for the configuration and [Troubleshooting thinking](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-adaptive) for the symptom-first fix.
473Use `thinking: {"type": "enabled", "budget_tokens": N}` on these models; see [Extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking) for the configuration and the [symptom-first fix for the adaptive thinking error](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-adaptive) in Troubleshooting thinking.
474474 
475475### Thinking cannot be disabled
476476 
from line 506
506506 
507507Claude 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.
508508 
509In 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 reject `"enabled"` with a 400 error. To vary effort per turn, use adaptive thinking.
509In 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 reject `"enabled"` with a 400 error. To vary effort for each turn, use adaptive thinking.
510510 
511511Sending `thinking: {"type": "between_tools"}` to any model other than Claude Sonnet 5.5 returns a 400 `invalid_request_error`:
512512 
from line 514
514514"thinking.type.between_tools" is not supported for this model.
515515```
516516 
517For the fixes, see [Troubleshooting thinking](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-between-tools), which covers the `between_tools` and effort errors.
517For the fixes, see the [`between_tools` and effort errors](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-between-tools) in Troubleshooting thinking.
518518 
519Omit 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 [Troubleshooting thinking](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-disabled).
519Omit 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](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-type-disabled) in Troubleshooting thinking.
520520 
521521### Forced tool use not supported
522522 
from line 546
546546messages.{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".
547547```
548548 
549Without the `thinking-binding-controls-2026-08-01` beta header the message also names that header. Keep the conversation history append-only, or send the beta header with `prefix_mismatch_behavior: "drop_block"` to drop the block and continue. On Claude Sonnet 5.5 and Claude Haiku 5.5, `block_binding` works only with `thinking: {"type": "adaptive"}`. With `between_tools` on Claude Sonnet 5.5, or `thinking: {"type": "disabled"}` on Claude Haiku 5.5, keep the history append-only, or strip the thinking blocks from the edited turn on. A block from a model the target model can't read is dropped rather than rejected. See [Keeping the prefix unchanged](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#prefix-check) and [Troubleshooting thinking](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-block-signature).
549Without the `thinking-binding-controls-2026-08-01` beta header, the message also names that header. Keep the conversation history append-only, or send the beta header with `prefix_mismatch_behavior: "drop_block"` to drop the block and continue. On Claude Sonnet 5.5 and Claude Haiku 5.5, `block_binding` works only with `thinking: {"type": "adaptive"}`. With `between_tools` on Claude Sonnet 5.5, or `thinking: {"type": "disabled"}` on Claude Haiku 5.5, keep the history append-only, or strip the thinking blocks from the edited turn on. A block from a model the target model can't read is dropped rather than rejected. See [Keeping the prefix unchanged](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#prefix-check) and the [fix for an invalid thinking block signature](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#error-thinking-block-signature) in Troubleshooting thinking.
550550 
551551Sending `thinking.block_binding` without the `thinking-binding-controls-2026-08-01` [beta header](https://platform.claude.com/docs/en/api/beta-headers) returns a 400 `invalid_request_error` whose message ends in:
552552 
from line 558
558558 
559559### Outbound web identity federation disabled (Claude Platform on AWS)
560560 
561If every request to [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws) returns `"Outbound web identity federation is disabled for your account"`, run `aws iam enable-outbound-web-identity-federation` once per AWS account. See [Enable outbound web identity federation](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#enable-outbound-web-identity-federation) for details.
561If every request to [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/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](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#enable-outbound-web-identity-federation) for details.
562562 
563563## Next steps
564564 

api/opentelemetry/spans Changed · +14 / -14 lines

from line 71
7171 
7272### Content attributes
7373 
74Attributes tagged with <Badge>Content</Badge> are only on spans in content mode, from the SDK and the API alike. See [how the content modes differ in the guide](https://platform.claude.com/docs/en/manage-claude/opentelemetry#choose-a-content-mode). When this content is too large, the SDK and the API [shorten it](https://platform.claude.com/docs/en/manage-claude/opentelemetry#content-limits) and set `anthropic.content.truncated` to `true`. If Anthropic's safeguards withhold content from a response, the API's spans don't include that content either.
74Attributes tagged with <Badge>Content</Badge> are only on spans in content mode, from the SDK and the API alike. See [how the content modes differ in the guide](https://platform.claude.com/docs/en/manage-claude/opentelemetry#choose-a-content-mode). When this content is too large, the SDK and the API shorten it to fit the [content limits](https://platform.claude.com/docs/en/manage-claude/opentelemetry#content-limits) and set `anthropic.content.truncated` to `true`. If Anthropic's safeguards withhold content from a response, the API's spans don't include that content either.
7575 
7676The message attributes are JSON strings in the message format of the OpenTelemetry GenAI conventions. Each Anthropic content block becomes one GenAI conventions message part, on the Messages API and in Managed Agents message events such as `agent.message`:
7777 
from line 207
207207 
208208 * The [`anthropic.sessions.create`](https://platform.claude.com/docs/en/api/opentelemetry/spans#anthropic-sessions-create) span, for the first turn of a session that was created with non-empty [`initial_events`](https://platform.claude.com/docs/en/api/beta/sessions/create#create.initial_events).
209209 * The [`anthropic.sessions.events.send`](https://platform.claude.com/docs/en/api/opentelemetry/spans#anthropic-sessions-events-send) span for the request in which the event was sent, for a turn that started because of an event, for example a [`user.message`](https://platform.claude.com/docs/en/api/beta/sessions/events#beta_managed_agents_user_message_event) event.
210 * The [`anthropic.sessions.update`](https://platform.claude.com/docs/en/api/opentelemetry/spans#anthropic-sessions-update) span, for a turn that resumes because the session budget was raised or removed through the request.
210 * The [`anthropic.sessions.update`](https://platform.claude.com/docs/en/api/opentelemetry/spans#anthropic-sessions-update) span, for a turn that resumes because the request raises or removes the session budget.
211211 * The `anthropic.session.turn` span for the turn of [the agent that the session runs](https://platform.claude.com/docs/en/managed-agents/multiagent-orchestration) during which that agent started this turn, for a turn on another thread.
212212 * The `anthropic.session.turn` span for the turn that produced the reply, for a turn that starts because an agent on another thread replied, such as an agent that the primary agent called.
213213 * None, for any other turn, such as a turn that starts because a [workflow run](https://platform.claude.com/docs/en/managed-agents/workflow-runs) ended.
from line 439
439439 
440440Every SDK span for a request, including [`anthropic.messages.create`](https://platform.claude.com/docs/en/api/opentelemetry/spans#anthropic-messages-create), [`anthropic.messages.count_tokens`](https://platform.claude.com/docs/en/api/opentelemetry/spans#anthropic-messages-count-tokens), and [`anthropic.messages.batches.<method>`](https://platform.claude.com/docs/en/api/opentelemetry/spans#anthropic-messages-batches-method), has the following attributes:
441441 
442| Attribute | Type | Description |
443| --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
444| `gen_ai.conversation.id` | `string` | The conversation ID passed with the [`conversation_id` (typescript, java, php: `conversationId`; csharp: `ConversationId`; go: `option.WithOpenTelemetryConversationID()`) option](https://platform.claude.com/docs/en/manage-claude/opentelemetry/sdk#configure-the-sdk). Without one, the session thread ID on the Managed Agents requests that [Session attributes](https://platform.claude.com/docs/en/api/opentelemetry/spans#session-attributes) lists, and absent on other requests. |
445| `anthropic.<resource>.id` | `string` | One attribute for each ID in the request's path and one for the ID of an object that the method creates. The name comes from the path, in the singular, for example `anthropic.session.id` or `anthropic.session.thread.id`. |
446| `gen_ai.agent.id` | `string` | The agent ID, on the agent methods. |
447| `gen_ai.memory.store.id` | `string` | The memory store ID, on the memory store methods. |
448| `gen_ai.memory.record.id` | `string` | The memory ID, on the memory methods. |
449| `http.request.resend_count` | `int` | The number of times that the SDK resent the request, for any reason, such as a retry. Absent when the SDK didn't resend it. |
450| `error.type` | `string` | A failed call's [error type](https://platform.claude.com/docs/en/api/errors#http-errors), for example `rate_limit_error`. The HTTP status code, for example `502`, when the error response doesn't have an error type. `connection_error`, `client_timeout_error`, or `client_error` when the call failed in the SDK. `api_error` when the server ended a stream early. |
451| `server.address` | `string` | The host of the client's base URL, `api.anthropic.com` by default. On a cloud platform's client, that platform's host. |
452| `url.query` | `string` | The URL's query string, with only the query parameters that the endpoint defines. Absent when there are none. In metadata-only mode, absent when the query has a sensitive parameter, such as `email`. |
453| `url.full` | `string` | The URL, made of `url.scheme`, `server.address`, the port when the base URL has one, `url.path`, and `url.query`. In metadata-only mode, absent whenever that mode leaves out `url.query`. |
442| Attribute | Type | Description |
443| --------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
444| `gen_ai.conversation.id` | `string` | The conversation ID passed with the [`conversation_id` (typescript, java, php: `conversationId`; csharp: `ConversationId`; go: `option.WithOpenTelemetryConversationID()`) option](https://platform.claude.com/docs/en/manage-claude/opentelemetry/sdk#configure-the-sdk). Without one, the session thread ID on requests to one session thread, and on the request in which the session tool runner sends a tool's result. Absent on other requests. |
445| `anthropic.<resource>.id` | `string` | One attribute for each ID in the request's path and one for the ID of an object that the method creates. The name comes from the path, in the singular, for example `anthropic.session.id` or `anthropic.session.thread.id`. |
446| `gen_ai.agent.id` | `string` | The agent ID, on the agent methods. |
447| `gen_ai.memory.store.id` | `string` | The memory store ID, on the memory store methods. |
448| `gen_ai.memory.record.id` | `string` | The memory ID, on the memory methods. |
449| `http.request.resend_count` | `int` | The number of times that the SDK resent the request, for any reason, such as a retry. Absent when the SDK didn't resend it. |
450| `error.type` | `string` | A failed call's [error type](https://platform.claude.com/docs/en/api/errors#http-errors), for example `rate_limit_error`. The HTTP status code, for example `502`, when the error response doesn't have an error type. `connection_error`, `client_timeout_error`, or `client_error` when the call failed in the SDK. `api_error` when the server ended a stream early. |
451| `server.address` | `string` | The host of the client's base URL, `api.anthropic.com` by default. On a cloud platform's client, that platform's host. |
452| `url.query` | `string` | The URL's query string, with only the query parameters that the endpoint defines. Absent when there are none. In metadata-only mode, absent when the query has a sensitive parameter, such as `email`. |
453| `url.full` | `string` | The URL, made of `url.scheme`, `server.address`, the port when the base URL has one, `url.path`, and `url.query`. In metadata-only mode, absent whenever that mode leaves out `url.query`. |
454454 

api/overview Changed · +29 / -29 lines

## Claude API versus cloud platforms ## Claude API vs cloud platforms

from line 23
2323 
2424The Claude API includes the following APIs:
2525 
26* **[Messages API](https://platform.claude.com/docs/en/api/messages/create)**: Send messages to Claude for conversational interactions (`POST /v1/messages`)
27* **[Message Batches API](https://platform.claude.com/docs/en/api/messages/batches/create)**: Process large volumes of Messages requests asynchronously with 50% cost reduction (`POST /v1/messages/batches`)
28* **[Token Counting API](https://platform.claude.com/docs/en/api/messages/count_tokens)**: Count tokens in a message before sending to manage costs and rate limits (`POST /v1/messages/count_tokens`)
29* **[Models API](https://platform.claude.com/docs/en/api/models/list)**: List available Claude models and their details (`GET /v1/models`)
30* **[Files API](https://platform.claude.com/docs/en/api/files/upload)**: Upload and manage files for use across multiple API calls (`POST /v1/files`, `GET /v1/files`)
31* **[Skills API](https://platform.claude.com/docs/en/api/skills/create)**: Create and manage custom agent skills (`POST /v1/skills`, `GET /v1/skills`)
26* **[Messages API](https://platform.claude.com/docs/en/api/messages/create):** Send messages to Claude for conversational interactions (`POST /v1/messages`)
27* **[Message Batches API](https://platform.claude.com/docs/en/api/messages/batches/create):** Process large volumes of Messages requests asynchronously with a 50 percent cost reduction (`POST /v1/messages/batches`)
28* **[Token Counting API](https://platform.claude.com/docs/en/api/messages/count_tokens):** Count tokens in a message before sending to manage costs and rate limits (`POST /v1/messages/count_tokens`)
29* **[Models API](https://platform.claude.com/docs/en/api/models/list):** List available Claude models and their details (`GET /v1/models`)
30* **[Files API](https://platform.claude.com/docs/en/api/files/upload):** Upload and manage files for use across multiple API calls (`POST /v1/files`, `GET /v1/files`)
31* **[Skills API](https://platform.claude.com/docs/en/api/skills/create):** Create and manage custom agent skills (`POST /v1/skills`, `GET /v1/skills`)
3232 
3333The following APIs are in beta:
3434 
35* **[Agents API](https://platform.claude.com/docs/en/managed-agents/agent-setup)**: Define reusable, versioned agent configurations for Claude Managed Agents (`POST /v1/agents`, `GET /v1/agents`)
36* **[Sessions API](https://platform.claude.com/docs/en/managed-agents/sessions)**: Run stateful agent sessions in managed cloud sandboxes (`POST /v1/sessions`, `GET /v1/sessions/{id}/events/stream`)
37* **[Environments API](https://platform.claude.com/docs/en/managed-agents/environments)**: Configure sandbox templates for agent sessions (`POST /v1/environments`, `GET /v1/environments`)
35* **[Agents API](https://platform.claude.com/docs/en/managed-agents/agent-setup):** Define reusable, versioned agent configurations for Claude Managed Agents (`POST /v1/agents`, `GET /v1/agents`)
36* **[Sessions API](https://platform.claude.com/docs/en/managed-agents/sessions):** Run stateful agent sessions in managed cloud sandboxes (`POST /v1/sessions`, `GET /v1/sessions/{id}/events/stream`)
37* **[Environments API](https://platform.claude.com/docs/en/managed-agents/environments):** Configure sandbox templates for agent sessions (`POST /v1/environments`, `GET /v1/environments`)
3838 
3939For the complete API reference with all endpoints, parameters, and response schemas, explore the API reference pages listed in the navigation. To access beta features, see [Beta headers](https://platform.claude.com/docs/en/api/beta-headers).
4040 
from line 42
4242 
4343For details on each authentication method and when to use it, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). Requests to the Claude API include these headers:
4444 
45| Header | Value | Required |
46| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
47| `Authorization` | `Bearer <token>`, where `<token>` is your API key or a short-lived access token obtained from `POST /v1/oauth/token` through [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) | Yes, unless `x-api-key` is set |
48| `x-api-key` | Your API key from Console. Legacy fallback for `Authorization`, still supported | No |
49| `anthropic-workspace-id` | ID of the [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces) the request runs in (for example, `wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ`). See [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace). | Required with a multi-workspace API key. Optional for other API keys. A key created for a single workspace runs in that workspace when you omit the header. Not used with Workload Identity Federation tokens, which select a workspace at token exchange. |
50| `anthropic-version` | API version (for example, `2026-10-21`) | Yes |
51| `content-type` | `application/json` | Yes |
45| Header | Value | Required |
46| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
47| `Authorization` | `Bearer <token>`, where `<token>` is your API key or a short-lived access token obtained from `POST /v1/oauth/token` through [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) | Yes, unless `x-api-key` is set |
48| `x-api-key` | Your API key from Console. Legacy fallback for `Authorization`, still supported | No |
49| `anthropic-workspace-id` | ID of the [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces) the request runs in (for example, `wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ`). See [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace). | Required with an API key that isn't scoped to a workspace. Optional for other API keys. A key created for a single workspace runs in that workspace when you omit the header. Not used with Workload Identity Federation tokens, which select a workspace at token exchange. |
50| `anthropic-version` | API version (for example, `2026-10-21`) | Yes |
51| `content-type` | `application/json` | Yes |
5252 
5353If you are using the [Client SDKs](https://platform.claude.com/docs/en/api/overview#client-sdks), the SDK sends the authentication, version, and content-type headers automatically; you pass `anthropic-workspace-id` yourself when your key needs it. For API versioning details, see [API versions](https://platform.claude.com/docs/en/api/versioning).
5454 
from line 70
7070* Streaming support
7171* Request timeouts and connection management
7272 
73For a list of client SDKs, see [Client SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview).
73For a list of client SDKs, see [SDKs, CLI, and libraries](https://platform.claude.com/docs/en/cli-sdks-libraries/overview).
7474 
75## Claude API vs cloud platforms
75## Claude API versus cloud platforms
7676 
7777Claude is available through the direct Claude API and through cloud platforms. Choose based on your infrastructure, feature availability, compliance requirements, and pricing preferences.
7878 
from line 105
105105 
106106### Request size limits
107107 
108| Endpoint | Maximum request size |
109| --------------------------------------------------------------------------------------------- | -------------------- |
110| Messages, Token Counting | 32 MB |
111| [Message Batches API](https://platform.claude.com/docs/en/build-with-claude/batch-processing) | 256 MB |
112| [Files API](https://platform.claude.com/docs/en/build-with-claude/files) | 500 MB |
113| Sessions, Agents, Environments | 32 MB |
108| Endpoint | Maximum request size |
109| -------------------------------------------------------------------------------------------------------------------- | -------------------- |
110| Messages, Token Counting | 32 MB |
111| Message Batches API (see [Batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing)) | 256 MB |
112| [Files API](https://platform.claude.com/docs/en/build-with-claude/files) | 500 MB |
113| Sessions, Agents, Environments | 32 MB |
114114 
115115If you exceed these limits, you'll receive a 413 `request_too_large` error.
116116 
from line 148
148148 
149149To go back a page, pass `prev_page` as the `page` parameter. `prev_page` is `null` when you're on the first page. Not all list endpoints support `prev_page`. Only `GET /v1/sessions` returns `prev_page`; on list endpoints that do not support backward pagination, the field is absent from the response rather than `null`. For a request walkthrough, see [Listing sessions](https://platform.claude.com/docs/en/managed-agents/session-operations#listing-sessions).
150150 
151The SDK provides an auto-paginating iterator that follows `next_page` for you. For example, `for session in client.beta.sessions.list()` (typescript: `for await (const session of client.beta.sessions.list())`; go: `client.Beta.Sessions.ListAutoPaging()`; java: `client.beta().sessions().list().autoPager()`; csharp: `(await client.Beta.Sessions.List()).Paginate()`; php: `$client->beta->sessions->list()->pagingEachItem()`; ruby: `client.beta.sessions.list.auto_paging_each`) walks through every session. SDK auto-pagination is forward-only; to go back a page, read `prev_page` from the response and pass it back as the `page` parameter yourself. See [client SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) for details.
151The SDK provides an auto-paginating iterator that follows `next_page` for you. For example, `for session in client.beta.sessions.list()` (typescript: `for await (const session of client.beta.sessions.list())`; go: `client.Beta.Sessions.ListAutoPaging()`; java: `client.beta().sessions().list().autoPager()`; csharp: `(await client.Beta.Sessions.List()).Paginate()`; php: `$client->beta->sessions->list()->pagingEachItem()`; ruby: `client.beta.sessions.list.auto_paging_each`) walks through every session. SDK auto-pagination is forward-only; to go back a page, read `prev_page` from the response and pass it back as the `page` parameter yourself. See [SDKs, CLI, and libraries](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) for details.
152152 
153153<Note>
154 Some list endpoints use a different cursor scheme. The [Message Batches API](https://platform.claude.com/docs/en/build-with-claude/batch-processing), the [Models API](https://platform.claude.com/docs/en/api/models/list), and several [Admin API](https://platform.claude.com/docs/en/manage-claude/admin-api) endpoints take `after_id` and `before_id` query parameters instead of `page`. Their responses return `has_more`, `first_id`, and `last_id` instead of `next_page`. See the reference page for each endpoint for its exact pagination fields.
154 Some list endpoints use a different cursor scheme. The Message Batches API (see [Batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing)), the [Models API](https://platform.claude.com/docs/en/api/models/list), and several [Admin API](https://platform.claude.com/docs/en/manage-claude/admin-api) endpoints take `after_id` and `before_id` query parameters instead of `page`. Their responses return `has_more`, `first_id`, and `last_id` instead of `next_page`. See the reference page for each endpoint for its exact pagination fields.
155155</Note>
156156 
157157## Rate limits and availability
from line 160
160160 
161161The API enforces rate limits and spend limits to prevent misuse and manage capacity. Limits are organized into usage tiers; your organization is placed on a tier automatically and can move to a higher tier over time. Each tier has:
162162 
163* **Spend limits**: Maximum monthly cost for API usage
164* **Rate limits**: Maximum number of requests per minute (RPM) and tokens per minute (TPM)
163* **Spend limits:** Maximum monthly cost for API usage
164* **Rate limits:** Maximum number of requests per minute (RPM) and tokens per minute (TPM)
165165 
166In the Console, you can view your rate limits on the [Rate limits](https://platform.claude.com/usage/limits) page and your spend limits on the [Billing](https://platform.claude.com/settings/billing) page. For higher rate limits or a higher monthly spend cap, use **Request tier increase** on the Rate limits page.
166In the Console, you can view your rate limits on the [Rate limits](https://platform.claude.com/usage/limits) page and your spend limits on the [Billing](https://platform.claude.com/settings/billing) page. For higher rate limits or a higher monthly spend cap, use **Request tier increase** on the **Rate limits** page.
167167 
168168For detailed information about limits, tiers, and the token bucket algorithm used for rate limiting, see [Rate limits](https://platform.claude.com/docs/en/api/rate-limits).
169169 

api/rate-limits Changed · +16 / -16 lines

## Setting lower limits for workspaces ## Setting lower limits for Workspaces

from line 13
13131. **Spend limits** set a maximum monthly cost an organization can incur for API usage.
14142. **Rate limits** set the maximum number of API requests an organization can make over a defined period of time.
1515 
16The API enforces service-configured limits at the organization level, but you may also set user-configurable limits for your organization's workspaces.
16The API enforces service-configured limits at the organization level, but you can also set user-configurable limits for your organization's workspaces.
1717 
1818## About rate limits
1919 
from line 80
8080 </Step>
8181</Steps>
8282 
83When usage reaches a spend limit you set, requests return HTTP 400 with error type `invalid_request_error`. The message begins `You have reached your specified API usage limits`, or `You have reached your specified workspace API usage limits` for a workspace limit, and states when access resumes. Raise or remove the limit to restore access sooner.
83When usage reaches a spend limit you set, requests return HTTP 400 with error type `invalid_request_error`. The message starts with `You have reached your specified API usage limits`, or `You have reached your specified workspace API usage limits` for a workspace limit, and states when access resumes. Raise or remove the limit to restore access sooner.
8484 
8585Limits on the [Claude Code workspace](https://platform.claude.com/docs/en/manage-claude/workspaces#claude-code-workspace) are checked separately: Claude Code requests over that workspace's limit can instead receive a 429 that carries a `retry-after` header.
8686 
8787## Rate limits
8888 
89The rate limits for the Messages API are measured in requests per minute (RPM), input tokens per minute (ITPM), and output tokens per minute (OTPM) for each model class. If you exceed any of the rate limits you will get a [429 error](https://platform.claude.com/docs/en/api/errors) describing which rate limit was exceeded. When the response has a `retry-after` header, wait that many seconds before retrying.
89The rate limits for the Messages API are measured in requests per minute (RPM), input tokens per minute (ITPM), and output tokens per minute (OTPM) for each model class. If you exceed any of the rate limits, you will get a [429 error](https://platform.claude.com/docs/en/api/errors) describing which rate limit was exceeded. When the response has a `retry-after` header, wait that many seconds before retrying.
9090 
9191<Note>
92 You might also encounter 429 errors because of acceleration limits on the API if your organization has a sharp increase in usage. To avoid hitting acceleration limits, ramp up your traffic gradually and maintain consistent usage patterns.
92 You might also encounter 429 errors because of acceleration limits on the API if your organization has a sharp increase in usage. To avoid hitting acceleration limits, increase your traffic gradually and maintain consistent usage patterns.
9393</Note>
9494 
9595### Cache-aware ITPM
9696 
97Many API providers use a combined "tokens per minute" (TPM) limit that may include all tokens, both cached and uncached, input and output. **For most Claude models, only uncached input tokens count toward your ITPM rate limits.** This is a key advantage that makes the rate limits effectively higher than they might initially appear.
97Many API providers use a combined "tokens per minute" (TPM) limit that might include all tokens, both cached and uncached, input and output. **For most Claude models, only uncached input tokens count toward your ITPM rate limits.** This is a key advantage that makes the rate limits effectively higher than they might initially appear.
9898 
9999ITPM rate limits are estimated at the beginning of each request, and the estimate is adjusted during the request to reflect the actual number of input tokens used.
100100 
from line 111
111111 total_input_tokens = cache_read_input_tokens + cache_creation_input_tokens + input_tokens
112112 ```
113113 
114 This means when you have cached content, `input_tokens` will typically be much smaller than your total input. For example, with a 200k token cached document and a 50 token user question, you'd see `input_tokens: 50` even though the total input is 200,050 tokens.
114 This means when you have cached content, `input_tokens` will typically be much smaller than your total input. For example, with a 200k-token cached document and a 50-token user question, you'd see `input_tokens: 50` even though the total input is 200,050 tokens.
115115 
116116 For rate limit purposes on most models, only `input_tokens` + `cache_creation_input_tokens` count toward your ITPM limit, making [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) an effective way to increase your effective throughput.
117117</Note>
118118 
119**Example:** With a 2,000,000 ITPM limit and an 80% cache hit rate, you could effectively process 10,000,000 total input tokens per minute (2M uncached + 8M cached), because cached tokens don't count toward your rate limit.
119**Example:** With a 2,000,000 ITPM limit and an 80 percent cache hit rate, you could effectively process 10,000,000 total input tokens per minute (2M uncached + 8M cached), because cached tokens don't count toward your rate limit.
120120 
121121<Note>
122122 Claude Haiku 3.5 (marked with footnote 4 in the following rate limit tables) also counts `cache_read_input_tokens` toward ITPM rate limits.
from line 124
124124 For all other models, cached input tokens do not count toward rate limits and are billed at the [cache read rate](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing), a fraction of the base input price. This means you can achieve significantly higher effective throughput by using [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching).
125125</Note>
126126 
127To make the most of your rate limits, cache repeated content such as system instructions and prompts, large context documents, tool definitions, and conversation history; see [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for guidance. With effective caching, you can substantially increase your actual throughput without raising your rate limits. Monitor your cache hit rate on the [Usage page](https://platform.claude.com/usage) in the Claude Console to tune your caching strategy.
127To get the highest throughput within your rate limits, cache repeated content such as system instructions and prompts, large context documents, tool definitions, and conversation history; see [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for guidance. With effective caching, you can substantially increase your actual throughput without raising your rate limits. Monitor your cache hit rate on the [Usage](https://platform.claude.com/usage) page in the Claude Console to tune your caching strategy.
128128 
129129OTPM rate limits are evaluated in real time as output tokens are produced, counting only the actual tokens generated. The `max_tokens` parameter does not factor into OTPM rate limit calculations, so there is no rate limit downside to setting a higher `max_tokens` value.
130130 
from line 195
195195 
196196### Message Batches API
197197 
198The Message Batches API has its own set of rate limits which are shared across all models. These include a requests per minute (RPM) limit to all API endpoints and a limit on the number of batch requests that can be in the processing queue at the same time. A "batch request" here refers to part of a Message Batch. You may create a Message Batch containing thousands of batch requests, each of which count toward this limit. A batch request is considered part of the processing queue when it has yet to be successfully processed by the model.
198The Message Batches API has its own set of rate limits, which are shared across all models. These include a requests per minute (RPM) limit to all API endpoints and a limit on the number of batch requests that can be in the processing queue at the same time. A "batch request" here refers to part of a Message Batch. You can create a Message Batch containing thousands of batch requests, each of which counts toward this limit. A batch request is considered part of the processing queue when it has yet to be successfully processed by the model.
199199 
200200<Tabs>
201201 <Tab title="Start tier">
from line 223
223223 
224224### Managed Agents
225225 
226[Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview) endpoints are rate-limited per organization. These limits are separate from the Messages API rate limits above.
226[Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview) endpoints are rate-limited for each organization. These limits are separate from the Messages API rate limits described earlier on this page.
227227 
228228| Operation | Limit |
229229| ------------------------------------------------------------------ | ------------------------- |
from line 244
244244 
245245You can monitor your rate limit usage on the [Usage](https://platform.claude.com/usage) page of the [Claude Console](https://platform.claude.com/).
246246 
247In addition to providing token and request charts, the Usage page provides two separate rate limit charts. Use these charts to see what headroom you have to grow, identify when you may be hitting peak use, understand what rate limits to request, and learn how to improve your caching rates. The charts visualize a number of metrics for a given rate limit (for example, per model):
247In addition to providing token and request charts, the Usage page provides two separate rate limit charts. Use these charts to see what headroom you have to grow, identify when you might be hitting peak use, understand what rate limits to request, and learn how to improve your caching rates. The charts visualize a number of metrics for a given rate limit (for example, for each model):
248248 
249249* The **Rate Limit - Input Tokens** chart includes:
250250 
from line 265
265265 **[Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws):** The **Request tier increase** flow is not available. Contact your Anthropic account representative or [Anthropic support](https://support.claude.com), and include the models you need raised, your peak input and output tokens per minute for each model, and roughly what share of your input is cached or repeated context. See [Rate limits and quotas on Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#rate-limits-and-quotas).
266266</Note>
267267 
268## Setting lower limits for Workspaces
268## Setting lower limits for workspaces
269269 
270270For more about workspaces, see [Workspaces](https://platform.claude.com/docs/en/manage-claude/workspaces).
271271 
272To protect Workspaces in your Organization from potential overuse, you can set custom spend and rate limits per Workspace.
272To protect Workspaces in your Organization from potential overuse, you can set custom spend and rate limits for each Workspace.
273273 
274274Example: If your Organization's limit is 40,000 input tokens per minute and 8,000 output tokens per minute, you might limit one Workspace to 30,000 input tokens per minute. This protects other Workspaces from potential overuse and ensures a more equitable distribution of resources across your Organization. The remaining unused tokens per minute (or more, if that Workspace doesn't use the limit) are then available for other Workspaces to use.
275275 
from line 277
277277 
278278* You can't set spend limits on the default Workspace.
279279* If not set, Workspace limits match the Organization's limit.
280* Workspace limits are set per limiter type (such as requests per minute, input tokens per minute, or output tokens per minute).
280* Workspace limits are set for each limiter type (such as requests per minute, input tokens per minute, or output tokens per minute).
281281* Organization-wide limits always apply, even if Workspace limits add up to more.
282282 
283283To read your current organization and workspace rate limits programmatically, use the [Rate Limits API](https://platform.claude.com/docs/en/manage-claude/rate-limits-api).

api/service-tiers Changed · +4 / -4 lines

from line 36
3636**Input tokens**
3737 
3838* Cache reads as 0.1 tokens per token read from the cache
39* Cache writes as 1.25 tokens per token written to the cache with a 5 minute TTL
40* Cache writes as 2.00 tokens per token written to the cache with a 1 hour TTL
39* Cache writes as 1.25 tokens per token written to the cache with a 5-minute TTL
40* Cache writes as 2.00 tokens per token written to the cache with a 1-hour TTL
4141* For [US-only inference](https://platform.claude.com/docs/en/manage-claude/data-residency) (`inference_geo: "us"`) requests on Claude 4.6 and later models, input tokens are 1.1 tokens per token
4242* All other input tokens are 1 token per token
4343 
from line 183
183183The `service_tier` parameter accepts the following values:
184184 
185185* `"auto"` (default) - Uses the Priority Tier capacity if available, falling back to your other capacity if not
186* `"standard_only"` - Only use standard tier capacity, useful if you don't want to use your Priority Tier capacity
186* `"standard_only"` - Uses only standard tier capacity, useful if you don't want to use your Priority Tier capacity
187187 
188188The response `usage` object also includes the service tier assigned to the request:
189189 
from line 223
223223* A commitment duration (1, 3, 6, or 12 months)
224224* A specific model version
225225 
226Priority Tier targets 99.5% uptime with prioritized computational resources. Requests beyond your committed capacity automatically fall back to standard tier.
226Priority Tier targets 99.5 percent uptime with prioritized computational resources. Requests beyond your committed capacity automatically fall back to standard tier.
227227 
228228### Supported models
229229 

build-with-claude/batch-processing Changed · +121 / -123 lines

from line 1
11---
22title: Batch processing
33url: https://platform.claude.com/docs/en/build-with-claude/batch-processing
4description: Process large volumes of Messages requests asynchronously with the Message Batches API, cutting costs by 50% and increasing throughput.
4description: Process large volumes of Messages requests asynchronously with the Message Batches API, cutting costs by 50 percent and increasing throughput.
55---
66 
77Batch processing is a powerful approach for handling large volumes of requests efficiently. Instead of processing requests one at a time with immediate responses, batch processing allows you to submit multiple requests together for asynchronous processing. This pattern is particularly useful when:
from line 42
4242 
4343* A Message Batch is limited to either 100,000 Message requests or 256 MB in size, whichever is reached first.
4444* The system processes each batch as fast as possible, with most batches completing within 1 hour. You can access batch results when all messages have completed or after 24 hours, whichever comes first. Batches expire if processing does not complete within 24 hours.
45* Batch results are available for 29 days after creation. After that, you may still view the Batch, but its results will no longer be available for download.
45* Batch results are available for 29 days after creation. After that, you can still view the Batch, but its results will no longer be available for download.
4646* Batches are scoped to a [Workspace](https://platform.claude.com/settings/workspaces) in the Claude Console. You may view all batches (and their results) that were created within the Workspace your request runs in.
47* Rate limits apply to both Batches API HTTP requests and the number of requests within a batch waiting to be processed. See [Message Batches API rate limits](https://platform.claude.com/docs/en/api/rate-limits#message-batches-api). Additionally, processing may be slowed down based on current demand and your request volume. In that case, you may see more requests expiring after 24 hours.
47* Rate limits apply to both Batches API HTTP requests and the number of requests within a batch waiting to be processed. See [Message Batches API rate limits](https://platform.claude.com/docs/en/api/rate-limits#message-batches-api). Additionally, processing might be slowed down based on current demand and your request volume. In that case, you might see more requests expiring after 24 hours.
4848* Because of high throughput and concurrent processing, batches may go slightly over the [spend limit](https://platform.claude.com/settings/billing) configured in the Claude Console for your Workspace.
4949* Each batched request must have `max_tokens` of at least `1`. `max_tokens: 0` ([cache pre-warming](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pre-warming-the-cache)) is not supported inside a batch, because an ephemeral cache entry written during batch processing would likely expire before the follow-up request runs.
5050 
from line 67
6767 
6868A small number of Messages API parameters are **not** supported in batch requests. Including any of these returns a validation error:
6969 
70| Parameter | Why |
71| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
72| `stream: true` | Batch results come back as a single file, not a stream. |
73| `speed` ([Fast mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode)) | Fast mode tunes synchronous latency, which doesn't apply to asynchronous batch processing. |
74| `max_tokens: 0` | See [Batch limitations](https://platform.claude.com/docs/en/build-with-claude/batch-processing#batch-limitations). |
70| Parameter | Why |
71| -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
72| `stream: true` | Batch results come back as a single file, not a stream. |
73| `speed` ([Fast mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode)) | Fast mode tunes synchronous latency, which doesn't apply to asynchronous batch processing. |
74| `fallbacks` ([Server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback)) | Server-side fallback doesn't apply to batches. To retry refused requests, see [Refusals in Message Batches](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusals-in-message-batches). |
75| `max_tokens: 0` | See [Batch limitations](https://platform.claude.com/docs/en/build-with-claude/batch-processing#batch-limitations). |
7576 
7677<Tip>
7778 Because batches can take longer than 5 minutes to process, consider using the [1-hour cache duration](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration) with prompt caching for better cache hit rates when processing batches with shared context.
from line 80
7980 
8081## Pricing
8182 
82The Batches API offers significant cost savings. All usage is charged at 50% of the standard API prices.
83The Batches API offers significant cost savings. All usage is charged at 50 percent of the standard API prices.
8384 
8485| Model | Batch input | Batch output |
8586| :----------------------------------------------------------------------------------------------------------------------------------- | :----------- | :------------ |
from line 124
123124<CodeGroup>
124125 ```bash cURL
125126 curl https://api.anthropic.com/v1/messages/batches \
126 --header "x-api-key: $ANTHROPIC_API_KEY" \
127 --header "anthropic-version: 2023-06-01" \
128 --header "content-type: application/json" \
129 --data \
130 '{
127 -H "x-api-key: $ANTHROPIC_API_KEY" \
128 -H "anthropic-version: 2023-06-01" \
129 -H "content-type: application/json" \
130 -d '{
131131 "requests": [
132 {
133 "custom_id": "my-first-request",
134 "params": {
135 "model": "claude-opus-5-5",
136 "max_tokens": 1024,
137 "messages": [
138 {"role": "user", "content": "Hello, world"}
139 ]
140 }
141 },
142 {
143 "custom_id": "my-second-request",
144 "params": {
145 "model": "claude-opus-5-5",
146 "max_tokens": 1024,
147 "messages": [
148 {"role": "user", "content": "Hi again, friend"}
149 ]
150 }
132 {
133 "custom_id": "my-first-request",
134 "params": {
135 "model": "claude-opus-5-5",
136 "max_tokens": 1024,
137 "messages": [
138 {"role": "user", "content": "Hello, world"}
139 ]
151140 }
141 },
142 {
143 "custom_id": "my-second-request",
144 "params": {
145 "model": "claude-opus-5-5",
146 "max_tokens": 1024,
147 "messages": [
148 {"role": "user", "content": "Hi again, friend"}
149 ]
150 }
151 }
152152 ]
153 }'
153 }'
154154 ```
155155 
156156 ```bash CLI
from line 453
453453 ```bash cURL
454454 # Check the status; repeat until processing_status is "ended"
455455 curl "https://api.anthropic.com/v1/messages/batches/$MESSAGE_BATCH_ID" \
456 --header "x-api-key: $ANTHROPIC_API_KEY" \
457 --header "anthropic-version: 2023-06-01"
456 -H "x-api-key: $ANTHROPIC_API_KEY" \
457 -H "anthropic-version: 2023-06-01"
458458 ```
459459 
460460 ```bash CLI
from line 603
603603 # last_id as after_id to fetch the next page. (The SDKs and the CLI
604604 # perform automatic pagination.)
605605 curl -s "https://api.anthropic.com/v1/messages/batches?limit=20" \
606 --header "x-api-key: $ANTHROPIC_API_KEY" \
607 --header "anthropic-version: 2023-06-01"
606 -H "x-api-key: $ANTHROPIC_API_KEY" \
607 -H "anthropic-version: 2023-06-01"
608608 ```
609609 
610610 ```bash CLI
from line 717
717717 # Streams the batch's .jsonl results, one result per line.
718718 # For per-result handling (retries, validation errors), use the Claude SDK.
719719 curl "https://api.anthropic.com/v1/messages/batches/msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d/results" \
720 --header "anthropic-version: 2023-06-01" \
721 --header "x-api-key: $ANTHROPIC_API_KEY"
720 -H "anthropic-version: 2023-06-01" \
721 -H "x-api-key: $ANTHROPIC_API_KEY"
722722 ```
723723 
724724 ```bash CLI
725 # Prints one result per line, e.g. `{"custom_id":"test-1","result":{"type":"succeeded",…}}`.
725 # Prints one result per line, for example `{"custom_id":"test-1","result":{"type":"succeeded",…}}`.
726726 # For per-result handling (retries, validation errors), use the SDK
727727 # examples in the other tabs.
728728 ant messages:batches results \
from line 938
938938 
939939<CodeGroup>
940940 ```bash cURL
941 curl --request POST https://api.anthropic.com/v1/messages/batches/$MESSAGE_BATCH_ID/cancel \
942 --header "x-api-key: $ANTHROPIC_API_KEY" \
943 --header "anthropic-version: 2023-06-01"
941 curl -X POST https://api.anthropic.com/v1/messages/batches/$MESSAGE_BATCH_ID/cancel \
942 -H "x-api-key: $ANTHROPIC_API_KEY" \
943 -H "anthropic-version: 2023-06-01"
944944 ```
945945 
946946 ```bash CLI
from line 1038
10381038 
10391039### Using prompt caching with Message Batches
10401040 
1041The Message Batches API supports prompt caching, allowing you to potentially reduce costs and processing time for batch requests. The pricing discounts from prompt caching and Message Batches can stack, providing even greater cost savings when both features are used together. However, because batch requests are processed asynchronously and concurrently, cache hits are provided on a best-effort basis. Users typically experience cache hit rates ranging from 30% to 98%, depending on their traffic patterns.
1041The Message Batches API supports prompt caching, allowing you to potentially reduce costs and processing time for batch requests. The pricing discounts from prompt caching and Message Batches can stack, providing even greater cost savings when both features are used together. However, because batch requests are processed asynchronously and concurrently, cache hits are provided on a best-effort basis. Users typically experience cache hit rates ranging from 30 percent to 98 percent, depending on their traffic patterns.
10421042 
10431043To maximize the likelihood of cache hits in your batch requests:
10441044 
from line 1051
10511051<CodeGroup>
10521052 ```bash cURL
10531053 curl https://api.anthropic.com/v1/messages/batches \
1054 --header "x-api-key: $ANTHROPIC_API_KEY" \
1055 --header "anthropic-version: 2023-06-01" \
1056 --header "content-type: application/json" \
1057 --data \
1058 '{
1054 -H "x-api-key: $ANTHROPIC_API_KEY" \
1055 -H "anthropic-version: 2023-06-01" \
1056 -H "content-type: application/json" \
1057 -d '{
10591058 "requests": [
1060 {
1061 "custom_id": "my-first-request",
1062 "params": {
1063 "model": "claude-opus-5-5",
1064 "max_tokens": 1024,
1065 "system": [
1066 {
1067 "type": "text",
1068 "text": "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1069 },
1070 {
1071 "type": "text",
1072 "text": "<the entire contents of Pride and Prejudice>",
1073 "cache_control": {"type": "ephemeral"}
1074 }
1075 ],
1076 "messages": [
1077 {"role": "user", "content": "Analyze the major themes in Pride and Prejudice."}
1078 ]
1059 {
1060 "custom_id": "my-first-request",
1061 "params": {
1062 "model": "claude-opus-5-5",
1063 "max_tokens": 1024,
1064 "system": [
1065 {
1066 "type": "text",
1067 "text": "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1068 },
1069 {
1070 "type": "text",
1071 "text": "<the entire contents of Pride and Prejudice>",
1072 "cache_control": {"type": "ephemeral"}
10791073 }
1080 },
1081 {
1082 "custom_id": "my-second-request",
1083 "params": {
1084 "model": "claude-opus-5-5",
1085 "max_tokens": 1024,
1086 "system": [
1087 {
1088 "type": "text",
1089 "text": "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1090 },
1091 {
1092 "type": "text",
1093 "text": "<the entire contents of Pride and Prejudice>",
1094 "cache_control": {"type": "ephemeral"}
1095 }
1096 ],
1097 "messages": [
1098 {"role": "user", "content": "Write a summary of Pride and Prejudice."}
1099 ]
1074 ],
1075 "messages": [
1076 {"role": "user", "content": "Analyze the major themes in Pride and Prejudice."}
1077 ]
1078 }
1079 },
1080 {
1081 "custom_id": "my-second-request",
1082 "params": {
1083 "model": "claude-opus-5-5",
1084 "max_tokens": 1024,
1085 "system": [
1086 {
1087 "type": "text",
1088 "text": "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1089 },
1090 {
1091 "type": "text",
1092 "text": "<the entire contents of Pride and Prejudice>",
1093 "cache_control": {"type": "ephemeral"}
11001094 }
1095 ],
1096 "messages": [
1097 {"role": "user", "content": "Write a summary of Pride and Prejudice."}
1098 ]
11011099 }
1100 }
11021101 ]
1103 }'
1102 }'
11041103 ```
11051104 
11061105 ```bash CLI
from line 1542
15431542 
15441543All [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) (web search, web fetch, code execution, MCP connectors, advisor, and tool search) work in batch requests. The batch worker runs the same server-side agentic loop as the synchronous Messages API.
15451544 
1546Because there is no open connection to maintain, the batch loop runs **more iterations per turn** than a synchronous request before it returns `stop_reason: "pause_turn"`. If a batch result comes back with `pause_turn`, the turn did not finish; you can continue it by submitting the paused assistant content in a follow-up request (batch or synchronous) exactly as shown in the [pause\_turn continuation pattern](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools#the-server-side-loop-and-pause-turn).
1545Because there is no open connection to maintain, the batch loop runs **more iterations per turn** than a synchronous request before it returns `stop_reason: "pause_turn"`. If a batch result comes back with `pause_turn`, the turn did not complete; you can continue it by submitting the paused assistant content in a follow-up request (batch or synchronous) exactly as shown in the [pause\_turn continuation pattern](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools#the-server-side-loop-and-pause-turn).
15471546 
1548The batch worker additionally throttles `web_search` per organization so that highly concurrent batch processing does not exhaust your organization's web-search rate limit. The batch retries throttled requests automatically; you don't need to handle this yourself, but very large web-search batches might take longer to complete.
1547The batch worker additionally throttles `web_search` for each organization so that highly concurrent batch processing does not exhaust your organization's web-search rate limit. The batch retries throttled requests automatically; you don't need to handle this yourself, but very large web-search batches might take longer to complete.
15491548 
15501549### Extended output (beta)
15511550 
from line 1556
15571556 
15581557Use extended output for long-form generation such as book-length drafts and technical documentation, exhaustive structured data extraction, large code-generation scaffolds, and long reasoning chains.
15591558 
1560A single 300k-token generation can take over an hour to complete, so plan your batch submissions with the 24-hour processing window in mind. Standard batch pricing (50% of standard API prices) applies.
1559A single 300k-token generation can take over an hour to complete, so plan your batch submissions with the 24-hour processing window in mind. Standard batch pricing (50 percent of standard API prices) applies.
15611560 
15621561<CodeGroup>
15631562 ```bash cURL
15641563 curl https://api.anthropic.com/v1/messages/batches \
1565 --header "x-api-key: $ANTHROPIC_API_KEY" \
1566 --header "anthropic-version: 2023-06-01" \
1567 --header "anthropic-beta: output-300k-2026-03-24" \
1568 --header "content-type: application/json" \
1569 --data \
1570 '{
1564 -H "x-api-key: $ANTHROPIC_API_KEY" \
1565 -H "anthropic-version: 2023-06-01" \
1566 -H "anthropic-beta: output-300k-2026-03-24" \
1567 -H "content-type: application/json" \
1568 -d '{
15711569 "requests": [
1572 {
1573 "custom_id": "long-form-request",
1574 "params": {
1575 "model": "claude-opus-5-5",
1576 "max_tokens": 300000,
1577 "messages": [
1578 {"role": "user", "content": "Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices."}
1579 ]
1580 }
1570 {
1571 "custom_id": "long-form-request",
1572 "params": {
1573 "model": "claude-opus-5-5",
1574 "max_tokens": 300000,
1575 "messages": [
1576 {"role": "user", "content": "Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices."}
1577 ]
15811578 }
1579 }
15821580 ]
1583 }'
1581 }'
15841582 ```
15851583 
15861584 ```bash CLI
from line 1786
17881786 
17891787### Best practices for effective batching
17901788 
1791To get the most out of the Batches API:
1789To use the Batches API effectively:
17921790 
17931791* Monitor batch processing status regularly and implement appropriate retry logic for failed requests.
1794* Use meaningful `custom_id` values to easily match results with requests, since order is not guaranteed.
1792* Use meaningful `custom_id` values to easily match results with requests, because order is not guaranteed.
17951793* Consider breaking very large datasets into multiple batches for better manageability.
17961794* Dry run a single request shape with the Messages API to avoid validation errors.
17971795 
from line 1797
17991797 
18001798If experiencing unexpected behavior:
18011799 
1802* Verify that the total batch request size doesn't exceed 256 MB. If the request size is too large, you may get a 413 `request_too_large` error.
1800* Verify that the total batch request size doesn't exceed 256 MB. If the request size is too large, you might get a 413 `request_too_large` error.
18031801* Check that you're using [supported models](https://platform.claude.com/docs/en/build-with-claude/batch-processing#supported-models) for all requests in the batch.
18041802* Ensure each request in the batch has a unique `custom_id`.
18051803* Ensure that it has been less than 29 days since batch `created_at` (not processing `ended_at`) time. If over 29 days have passed, results will no longer be viewable.
from line 1807
18091807 
18101808## Batch storage and privacy
18111809 
1812* **Workspace isolation**: Batches are isolated within the Workspace they are created in. They can only be accessed by API requests in that same Workspace, or users with permission to view Workspace batches in the Console.
1810* **Workspace isolation:** Batches are isolated within the Workspace they are created in. They can only be accessed by API requests in that same Workspace, or users with permission to view Workspace batches in the Console.
18131811 
1814* **Result availability**: Batch results are available for 29 days after the batch is created, allowing ample time for retrieval and processing.
1812* **Result availability:** Batch results are available for 29 days after the batch is created, allowing ample time for retrieval and processing.
18151813 
18161814## Data retention
18171815 
from line 1821
18231821 
18241822<AccordionGroup>
18251823 <Accordion title="How long does it take for a batch to process?">
1826 Batches may take up to 24 hours for processing, but many finish sooner. Actual processing time depends on the size of the batch, current demand, and your request volume. It is possible for a batch to expire and not complete within 24 hours.
1824 Batches might take up to 24 hours for processing, but many complete sooner. Actual processing time depends on the size of the batch, current demand, and your request volume. It is possible for a batch to expire and not complete within 24 hours.
18271825 </Accordion>
18281826 
18291827 <Accordion title="Is the Batches API available for all models?">
from line 1829
18311829 </Accordion>
18321830 
18331831 <Accordion title="Can I use the Message Batches API with other API features?">
1834 Yes, the Message Batches API supports nearly all features available in the Messages API, including most beta features. A small number of parameters (`stream`, `speed`, and `max_tokens: 0`) are not supported. See [What can be batched](https://platform.claude.com/docs/en/build-with-claude/batch-processing#what-can-be-batched) for the full list.
1832 Yes, the Message Batches API supports nearly all features available in the Messages API, including most beta features. A small number of parameters (`stream`, `speed`, `fallbacks`, and `max_tokens: 0`) are not supported. See [What can be batched](https://platform.claude.com/docs/en/build-with-claude/batch-processing#what-can-be-batched) for the full list.
18351833 </Accordion>
18361834 
18371835 <Accordion title="How does the Message Batches API affect pricing?">
1838 The Message Batches API offers a 50% discount on all usage compared to standard API prices. This applies to input tokens, output tokens, and any special tokens. For more on pricing, visit [Pricing](https://claude.com/pricing#anthropic-api).
1836 The Message Batches API offers a 50 percent discount on all usage compared to standard API prices. This applies to input tokens, output tokens, and any special tokens. For more on pricing, visit [Pricing](https://claude.com/pricing#anthropic-api).
18391837 </Accordion>
18401838 
18411839 <Accordion title="Can I update a batch after it's been submitted?">
1842 No, once a batch has been submitted, it cannot be modified. If you need to make changes, you should cancel the current batch and submit a new one. Note that cancellation may not take immediate effect.
1840 No, once a batch has been submitted, it cannot be modified. If you need to make changes, you should cancel the current batch and submit a new one. Note that cancellation might not take immediate effect.
18431841 </Accordion>
18441842 
18451843 <Accordion title="Are there Message Batches API rate limits and do they interact with the Messages API rate limits?">
from line 1854
18561854 1. Batches and their results are isolated within the Workspace in which they were created. This means they can only be accessed by API requests in that same Workspace.
18571855 2. Each request within a batch is processed independently, with no data leakage between requests.
18581856 3. Results are only available for a limited time (29 days), and follow Anthropic's [data retention policy](https://support.claude.com/en/articles/7996866-how-long-do-you-store-personal-data).
1859 4. Downloading batch results in the Console can be disabled on the organization-level or on a per-workspace basis.
1857 4. Downloading batch results in the Console can be disabled on the organization level or on a per-workspace basis.
18601858 </Accordion>
18611859 
18621860 <Accordion title="Can I use prompt caching in the Message Batches API?">
1863 Yes, it is possible to use prompt caching with Message Batches API. However, because asynchronous batch requests can be processed concurrently and in any order, cache hits are provided on a best-effort basis.
1861 Yes, it is possible to use prompt caching with the Message Batches API. However, because asynchronous batch requests can be processed concurrently and in any order, cache hits are provided on a best-effort basis.
18641862 </Accordion>
18651863</AccordionGroup>
18661864 
from line 1866
18681866 
18691867<CardGroup cols={2}>
18701868 <Card title="Search results" icon="magnifying-glass" href="https://platform.claude.com/docs/en/build-with-claude/search-results">
1871 Enable natural citations for RAG applications by providing search results with source attribution.
1869 Get natural citations for RAG applications by providing search results with source attribution.
18721870 </Card>
18731871 
18741872 <Card title="Prompt caching" icon="database" href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching">

build-with-claude/cache-diagnostics Changed · +7 / -7 lines

from line 702
702702<Tabs>
703703 <Tab title="cURL">
704704 <Info>
705 This workflow doesn't translate well to a one-off shell command. See the SDK tabs for the loop pattern; the per-turn HTTP request is identical to [Basic usage](https://platform.claude.com/docs/en/build-with-claude/cache-diagnostics#basic-usage).
705 This workflow doesn't translate well to a one-off shell command. Use the Claude SDK to run the loop; the per-turn HTTP request is identical to [Basic usage](https://platform.claude.com/docs/en/build-with-claude/cache-diagnostics#basic-usage).
706706 </Info>
707707 </Tab>
708708 
709709 <Tab title="CLI">
710710 <Info>
711 This workflow doesn't translate well to a one-off shell command. See the SDK tabs for the loop pattern; the per-turn CLI invocation is identical to [Basic usage](https://platform.claude.com/docs/en/build-with-claude/cache-diagnostics#basic-usage).
711 This workflow doesn't translate well to a one-off shell command. Use the Claude SDK to run the loop; the per-turn CLI command is identical to [Basic usage](https://platform.claude.com/docs/en/build-with-claude/cache-diagnostics#basic-usage).
712712 </Info>
713713 </Tab>
714714 
from line 968
968968| Value | Meaning |
969969| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
970970| `null` | The request did not include the `diagnostics` object, `previous_message_id` was `null` (first turn, nothing to compare), or a comparison ran and found no divergence. |
971| `{"cache_miss_reason": null}` | The comparison was still running when the response was serialized. This can happen when the response starts very quickly. Treat it as inconclusive and check the next turn. |
971| `{"cache_miss_reason": null}` | The comparison was still running when the response was serialized. This can occur when the response starts very quickly. Treat it as inconclusive and check the next turn. |
972972| `{"cache_miss_reason": {...}}` | A `cache_miss_reason` is attached. For `*_changed` types this identifies the first divergence point; `previous_message_not_found` and `unavailable` are cases where no comparison was produced. |
973973 
974974When `cache_miss_reason` is non-null, it looks like this:
from line 996
996996 
997997## Cache miss reason types
998998 
999`cache_miss_reason` is a discriminated union on `type`. The response reports the earliest divergence only, so fix it first; later ones may be hidden behind it.
999`cache_miss_reason` is a discriminated union on `type`. The response reports the earliest divergence only, so fix it first; later ones might be hidden behind it.
10001000 
10011001| Type | What it means | What to change |
10021002| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
from line 1013
10131013 
10141014## Reading diagnostics alongside usage
10151015 
1016`diagnostics` answers "did my request change?" while `usage.cache_read_input_tokens` answers "did the cache hit?". Combining them tells you where to look.
1016`diagnostics` answers "did my request change?" whereas `usage.cache_read_input_tokens` answers "did the cache hit?" Combining them tells you where to look.
10171017 
10181018This matrix applies to turns where you passed a real `previous_message_id`. On the first turn (`previous_message_id: null`), `diagnostics` is always `null` and `cache_read_input_tokens` is normally zero because the cache is being written, not read; no troubleshooting is needed. The matrix also does not apply when `cache_miss_reason` is `null` (the comparison is still pending; check the next turn) or when its `type` is `previous_message_not_found` or `unavailable` (no comparison was produced).
10191019 
from line 1021
10211021| ----------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
10221022| `null` | high | Working as expected. Your prefix is stable and the cache hit. |
10231023| `null` | low or zero | Your requests match but the cache entry was no longer available. Consider shortening gaps between turns or using the [1-hour cache TTL](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration). |
1024| `cache_miss_reason` is a `*_changed` type | low or zero | Your bug. The request changed; fix the cause indicated by `type`. |
1024| `cache_miss_reason` is a `*_changed` type | low or zero | The request changed; fix the cause indicated by `type`. |
10251025| `cache_miss_reason` is a `*_changed` type | high | Rare. A change occurred late in the prompt but an earlier `cache_control` breakpoint still hit. Worth fixing, but low impact. |
10261026 
10271027## Limitations
from line 1029
10291029* **Claude API only:** Not available on Amazon Bedrock or Google Cloud.
10301030* **Limited retention:** Fingerprints for `previous_message_id` lookup expire after a short period. Run diagnostic comparisons between closely spaced requests.
10311031* **Same workspace:** The previous request must have run in the same organization and workspace. To check, compare the `anthropic-workspace-id` [response header](https://platform.claude.com/docs/en/api/overview#response-headers) on the two responses.
1032* **Comparison horizon:** For very long conversations where the only change is deep in the message list, the response may be `unavailable` rather than a precise location.
1032* **Comparison horizon:** For very long conversations where the only change is deep in the message list, the response might be `unavailable` rather than a precise location.
10331033* **Best-effort:** Diagnostics never blocks or fails your request. If diagnostic information is not available, the response returns `unavailable`, or `cache_miss_reason: null` when the comparison was still running.
10341034 
10351035## Data retention

build-with-claude/citations Changed · +3 / -3 lines

from line 311
311311 
312312 Compared to prompting Claude to cite sources, the citations feature offers the following advantages:
313313 
314 * **Cost savings:** If your prompt-based approach asks Claude to output direct quotes, you may see cost savings because `cited_text` does not count toward your output tokens.
314 * **Cost savings:** If your prompt-based approach asks Claude to output direct quotes, you might see cost savings because `cited_text` does not count toward your output tokens.
315315 * **Better citation reliability:** Because the API parses citations into the response formats described in the following sections and extracts `cited_text` directly, citations are guaranteed to contain valid pointers to the provided documents.
316316 * **Improved citation quality:** In Anthropic's evaluations, the citations feature is significantly more likely to cite the most relevant quotes from documents than purely prompt-based approaches.
317317</Tip>
from line 338
338338 </Step>
339339 
340340 <Step title="Claude provides cited response">
341 * Responses may now include multiple text blocks where each text block can contain a claim that Claude is making and a list of citations that support the claim.
341 * Responses might now include multiple text blocks where each text block can contain a claim that Claude is making and a list of citations that support the claim.
342342 
343343 * Citations reference specific locations in source documents. The format of these citations is dependent on the type of document being cited from.
344344 
from line 988
988988 
989989### PDF documents
990990 
991PDF documents can be provided as base64-encoded data, a URL, or by `file_id`. PDF text is extracted and chunked into sentences. As image citations are not yet supported, PDFs that are scans of documents and do not contain extractable text are not citable.
991PDF documents can be provided as base64-encoded data, as a URL, or by `file_id`. PDF text is extracted and chunked into sentences. As image citations are not yet supported, PDFs that are scans of documents and do not contain extractable text are not citable.
992992 
993993<Tabs>
994994 <Tab title="Base64">

build-with-claude/claude-in-amazon-bedrock Changed · +6 / -6 lines

from line 16
1616 
1717## Prerequisites
1818 
19Before you begin, ensure you have:
19Before you start, ensure you have:
2020 
21* An AWS account with [Amazon Bedrock model access](https://console.aws.amazon.com/bedrock/home#/modelaccess) enabled for the Claude models you intend to use.
22* The [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) installed and configured (optional, for credential management).
21* An AWS account with [Amazon Bedrock model access](https://console.aws.amazon.com/bedrock/home#/modelaccess) enabled for the Claude models you intend to use
22* The [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) installed and configured (optional, for credential management)
2323 
2424Claude Mythos Preview additionally requires a dedicated AWS account that has been allowlisted by the Bedrock Marketplace team. Your Anthropic account executive can submit your account ID for allowlisting (typically processed within 24 hours), and AWS sends a welcome email once it's complete.
2525 
from line 37
3737 </Step>
3838 
3939 <Step title="Developer: pass the role">
40 When calling the API, Bedrock assumes the service role on your behalf. See the [Amazon Bedrock documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-mantle.html) for how to associate the role with your requests.
40 When you call the API, Bedrock assumes the service role on your behalf. See the [Amazon Bedrock documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-mantle.html) for how to associate the role with your requests.
4141 </Step>
4242</Steps>
4343 
from line 390
390390Claude in Amazon Bedrock is available in the following AWS regions. Amazon Bedrock offers two endpoint types:
391391 
392392* **Global:** dynamic routing across all available regions for maximum availability. No pricing premium.
393* **Regional:** the endpoint resolves to the single AWS region you specify, for data-residency requirements. Regional endpoints carry a 10% pricing premium over global endpoints. To route across multiple regions within a geography, use an [inference profile](https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference.html) (US, EU, JP, or AU). Regions marked **In-region only** in the table support direct single-region routing without an inference profile.
393* **Regional:** the endpoint resolves to the single AWS region you specify, for data-residency requirements. Regional endpoints carry a 10 percent pricing premium over global endpoints. To route across multiple regions within a geography, use an [inference profile](https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference.html) (US, EU, JP, or AU). Regions marked **In-region only** in the table support direct single-region routing without an inference profile.
394394 
395395The global endpoint is available for Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Sonnet 5.5, Claude Sonnet 5, Claude Haiku 5.5, and Claude Haiku 4.5. For Claude Fable 5.1, regional endpoints are currently available in `us-east-1` only. Claude Mythos Preview is regional only and is available in `us-east-1`.
396396 

build-with-claude/claude-in-microsoft-foundry Changed · +7 / -7 lines

from line 27
2727 
2828## Prerequisites
2929 
30Before you begin, ensure you have:
30Before you start, ensure you have:
3131 
3232* An active Azure subscription
3333* Access to the [Foundry portal](https://ai.azure.com/)
from line 36
3636 
3737## Install an SDK
3838 
39Anthropic's [client SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) support Foundry through a platform-specific package or client class. The examples on this page also show requests with cURL and the ant CLI. To set up the CLI, see [CLI quickstart](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/quickstart).
39Anthropic's [client SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) support Foundry through a platform-specific package or client class. The examples on this page also show requests with cURL and the `ant` CLI. To set up the CLI, see [CLI quickstart](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/quickstart).
4040 
4141<Note>
4242 Foundry is supported by the C#, Go, Java, PHP, Python, and TypeScript SDKs. Foundry is not currently available in the Ruby SDK.
from line 129
129129 
130130## Provisioning
131131 
132Foundry uses a two-level hierarchy: **resources** contain your security and billing configuration, while **deployments** are the model instances you call through the API. You'll first create a Foundry resource, then create one or more Claude deployments within it.
132Foundry uses a two-level hierarchy: **resources** contain your security and billing configuration, whereas **deployments** are the model instances you call through the API. You'll first create a Foundry resource, then create one or more Claude deployments within it.
133133 
134134### Provisioning Foundry resources
135135 
from line 151
151151 
1521522. Search for and select a Claude model (for example, claude-opus-5-5). Each model appears once in the catalog regardless of how many hosting options it supports.
153153 
1543. On the model card, select **Deploy**, then **Custom settings** to open the deployment settings pane. If you choose **Default settings** instead, the deployment is automatically configured as Hosted on Azure for models available in both hosting options.
1543. On the model card, select **Deploy**, then **Custom settings** to open the deployment settings pane. If you select **Default settings** instead, the deployment is automatically configured as Hosted on Azure for models available in both hosting options.
155155 
1561564. On your first Claude deployment, review the Azure Marketplace terms, select an industry, and select **Agree and Proceed** to accept the terms and subscribe to the Azure Marketplace offer.
157157 
from line 158
1581585. Configure the deployment:
159159 
160160 * **Deployment name:** Defaults to the model ID, but you can customize it (for example, `my-claude-deployment`). The deployment name cannot be changed after creation.
161 * **Region scope:** Select Global, or for models hosted on Azure, Data Zone. Selecting Data Zone creates a US Data Zone Standard deployment, which keeps inference within the United States and is equivalent to setting [`inference_geo: "us"`](https://platform.claude.com/docs/en/manage-claude/data-residency#inference-geo) on the Claude API. For Claude Sonnet 5.5, select Global.
161 * **Region scope:** Select **Global**, or for models hosted on Azure, **Data Zone**. Selecting **Data Zone** creates a US Data Zone Standard deployment, which keeps inference within the United States and is equivalent to setting [`inference_geo: "us"`](https://platform.claude.com/docs/en/manage-claude/data-residency#inference-geo) on the Claude API. For Claude Sonnet 5.5, select **Global**.
162162 * **Model version:** Expand **Model version settings** and select a version from the **Model version** dropdown menu. Each [hosting option](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options) is listed as a separate model version, labeled with its hosting option (for example, version 1 for Hosted on Anthropic, version 2 for Hosted on Azure).
163163 
1641646. Select **Deploy** and wait for provisioning to complete.
from line 757
757757 
758758**Error:** `403 Forbidden`
759759 
760* **Solution:** Your Azure account may lack the necessary permissions. Ensure you have the appropriate Azure RBAC role assigned (for example, **Foundry User** (formerly Azure AI User) or **Cognitive Services User**).
760* **Solution:** Your Azure account might lack the necessary permissions. Ensure you have the appropriate Azure RBAC role assigned (for example, **Foundry User** (formerly Azure AI User) or **Cognitive Services User**).
761761 
762762### Rate limiting
763763 
from line 779
779779 
780780**Error:** `Invalid model parameter`
781781 
782* **Solution:** The model parameter should contain your deployment name, which can be customized in the Foundry portal. Verify the deployment exists and is properly configured.
782* **Solution:** The `model` parameter should contain your deployment name, which can be customized in the Foundry portal. Verify the deployment exists and is properly configured.
783783 
784784## Next steps
785785 

build-with-claude/claude-on-amazon-bedrock-legacy Changed · +14 / -14 lines

from line 19
1919## Install and configure the AWS CLI
2020 
21211. [Install a version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) at or newer than version `2.13.23`.
222. Configure your AWS credentials using the AWS configure command (see [Configure the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)) or find your credentials by navigating to "Command line or programmatic access" within your AWS dashboard and following the directions in the modal window.
222. Configure your AWS credentials using the AWS configure command (see [Configure the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)) or find your credentials by navigating to **Command line or programmatic access** within your AWS dashboard and following the directions in the modal window.
23233. Verify that your credentials are working:
2424 
2525```bash AWS CLI
from line 28
2828 
2929## Install an SDK for accessing Bedrock
3030 
31Anthropic's [client SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) support Bedrock. You can also use an AWS SDK like `boto3` directly.
31Anthropic's [client SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) support Bedrock. You can also use an AWS SDK such as `boto3` directly.
3232 
3333<Tabs>
3434 <Tab title="Python">
from line 56
5656 </Tab>
5757 
5858 <Tab title="Java">
59 <CodeGroup>
59 <CodeGroup exclude="shell, python, typescript, csharp, go, php, ruby">
6060 ```groovy Gradle
6161 implementation("com.anthropic:anthropic-java:3.0.0")
6262 implementation("com.anthropic:anthropic-java-bedrock:3.0.0")
from line 130
130130 
131131### Subscribe to Anthropic models
132132 
133Go to the [AWS Console > Bedrock > Model Access](https://console.aws.amazon.com/bedrock/home?region=us-west-2#/modelaccess) and request access to Anthropic models. Note that Anthropic model availability varies by region. See [AWS documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/models-regions.html) for latest information.
133Go to the [AWS Console > Bedrock > Model Access](https://console.aws.amazon.com/bedrock/home?region=us-west-2#/modelaccess) and request access to Anthropic models. Note that Anthropic model availability varies by region. See the [AWS documentation on model availability by region](https://docs.aws.amazon.com/bedrock/latest/userguide/models-regions.html) for the latest information.
134134 
135135#### API model IDs
136136 
from line 146
146146Invocation of model ID anthropic.claude-sonnet-4-5-20250929-v1:0 with on-demand throughput isn't supported. Retry your request with the ID or ARN of an inference profile that contains this model.
147147```
148148 
149To invoke these models, pass an inference profile instead of the base model ID. The inference profile ID is the base model ID with a prefix from a column marked "Yes" in the following table, for example us.anthropic.claude-sonnet-4-5-20250929-v1:0. You can also pass the full inference profile ARN, in the form `arn:aws:bedrock:{region}:{account-id}:inference-profile/{inference-profile-id}`. For AWS's authoritative list of available inference profiles, see [Supported Regions and models for inference profiles](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html). To learn how the prefixes affect routing and pricing, see the [Global versus regional endpoints](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy#global-vs-regional-endpoints) section.
149To call these models, pass an inference profile instead of the base model ID. The inference profile ID is the base model ID with a prefix from a column marked "Yes" in the following table, for example us.anthropic.claude-sonnet-4-5-20250929-v1:0. You can also pass the full inference profile ARN, in the form `arn:aws:bedrock:{region}:{account-id}:inference-profile/{inference-profile-id}`. For AWS's authoritative list of available inference profiles, see [Supported Regions and models for inference profiles](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html). To learn how the prefixes affect routing and pricing, see the [Global versus regional endpoints](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy#global-vs-regional-endpoints) section.
150150 
151151| Model | Base Bedrock model ID | `global` | `us` | `eu` | `jp` | `apac` |
152152| :---------------------------------------------------------------------------------------------------- | :------------------------------------------ | :------- | :--- | :--- | :--- | :----- |
from line 162
162162 
163163The following examples show how to print a list of all the Claude models available through Bedrock:
164164 
165<CodeGroup>
165<CodeGroup exclude="shell">
166166 ```bash AWS CLI
167167 aws bedrock list-foundation-models --region=us-west-2 --by-provider anthropic --query "modelSummaries[*].modelId"
168168 ```
from line 311
311311<Tabs>
312312 <Tab title="cURL">
313313 <Note>
314 Calling the `InvokeModel` API with AWS credentials requires SigV4 request signing, which the SDKs in the other tabs handle automatically. For a Bedrock endpoint you can call with a self-contained cURL command, see [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#making-your-first-request).
314 Calling the `InvokeModel` API with AWS credentials requires SigV4 request signing, which the SDK handles automatically. For a Bedrock endpoint you can call with a self-contained cURL command, see [Making your first request with Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#making-your-first-request).
315315 </Note>
316316 </Tab>
317317 
from line 769
769769 
770770Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5.5, Claude Sonnet 5, Claude Sonnet 4.6, and Claude Haiku 5.5 have a [1M-token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows) on Amazon Bedrock. Other Claude models, including Sonnet 4.5 (deprecated) and Sonnet 4 (deprecated), have a 200k-token context window.
771771 
772Bedrock limits request payloads to 20 MB. When sending large documents or many images, you may reach this limit before the token limit.
772Bedrock limits request payloads to 20 MB. When sending large documents or many images, you might reach this limit before the token limit.
773773 
774774## Global versus regional endpoints
775775 
from line 778
778778* **Global endpoints:** Dynamic routing for maximum availability
779779* **Regional endpoints:** Guaranteed data routing through specific geographic regions
780780 
781Regional endpoints include a 10% pricing premium over global endpoints.
781Regional endpoints include a 10 percent pricing premium over global endpoints.
782782 
783783<Note>
784784 This applies to Claude Sonnet 4.5 (deprecated) and future models only. Older models (Claude Sonnet 4 (deprecated) and earlier) maintain their existing pricing structures.
from line 790
790790 
791791* Provide maximum availability and uptime
792792* Dynamically route requests to regions with available capacity
793* No pricing premium
794* Best for applications where data residency is flexible
793* Carry no pricing premium
794* Work best for applications where data residency is flexible
795795 
796796**Regional endpoints (CRIS):**
797797 
from line 798
798798* Route traffic through specific geographic regions
799799* Required for data residency and compliance requirements
800800* Available for US, EU, Japan, and Asia-Pacific
801* 10% pricing premium reflects infrastructure costs for dedicated regional capacity
801* 10 percent pricing premium reflects infrastructure costs for dedicated regional capacity
802802 
803803### Implementation
804804 
from line 809
809809<Tabs>
810810 <Tab title="cURL">
811811 <Note>
812 Calling the `InvokeModel` API with AWS credentials requires SigV4 request signing, which the SDKs in the other tabs handle automatically. For a Bedrock endpoint you can call with a self-contained cURL command, see [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#making-your-first-request).
812 Calling the `InvokeModel` API with AWS credentials requires SigV4 request signing, which the SDK handles automatically. For a Bedrock endpoint you can call with a self-contained cURL command, see [Making your first request with Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#making-your-first-request).
813813 </Note>
814814 </Tab>
815815 
from line 960
960960<Tabs>
961961 <Tab title="cURL">
962962 <Note>
963 Calling the `InvokeModel` API with AWS credentials requires SigV4 request signing, which the SDKs in the other tabs handle automatically. For a Bedrock endpoint you can call with a self-contained cURL command, see [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#making-your-first-request).
963 Calling the `InvokeModel` API with AWS credentials requires SigV4 request signing, which the SDK handles automatically. For a Bedrock endpoint you can call with a self-contained cURL command, see [Making your first request with Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#making-your-first-request).
964964 </Note>
965965 </Tab>
966966 

build-with-claude/claude-on-vertex-ai Changed · +7 / -7 lines

from line 390
390390 
391391Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5.5, Claude Sonnet 5, Claude Sonnet 4.6, and Claude Haiku 5.5 have a [1M-token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows) on Agent Platform. Other Claude models, including Sonnet 4.5 (deprecated) and Sonnet 4 (deprecated), have a 200k-token context window.
392392 
393Agent Platform limits request payloads to 30 MB. When sending large documents or many images, you might reach this limit before the token limit.
393Agent Platform limits request payloads to 30 MB. When sending large documents or many images, you might reach this limit before the token limit.
394394 
395395## Global, multi-region, and regional endpoints
396396 
from line 400
400400* **Multi-region endpoints:** Dynamic routing within a geographic area (for example, the United States or the European Union) for data residency with high availability
401401* **Regional endpoints:** Guaranteed data routing through specific geographic regions
402402 
403Regional and multi-region endpoints include a 10% pricing premium over global endpoints.
403Regional and multi-region endpoints include a 10 percent pricing premium over global endpoints.
404404 
405405<Note>
406406 This applies to Claude Sonnet 4.5 (deprecated) and future models only. Older models (Claude Sonnet 4 (deprecated), Opus 4 (deprecated), and earlier) maintain their existing pricing structures.
from line 412
412412 
413413* Provide maximum availability and uptime
414414* Dynamically route requests to regions with available capacity
415* No pricing premium
416* Best for applications where data residency is flexible
417* Only supports pay-as-you-go traffic (provisioned throughput requires regional endpoints)
415* Carry no pricing premium
416* Work best for applications where data residency is flexible
417* Only support pay-as-you-go traffic (provisioned throughput requires regional endpoints)
418418 
419419**Multi-region endpoints:**
420420 
421421* Dynamically route requests across regions within a geographic area (currently `us` and `eu`)
422422* Useful when you need data residency within a broad geography but want higher availability than a single region
423* 10% pricing premium over global endpoints
423* 10 percent pricing premium over global endpoints
424424* Only supports pay-as-you-go traffic (provisioned throughput requires regional endpoints)
425425 
426426**Regional endpoints:**
from line 428
428428* Route traffic through specific geographic regions
429429* Required for single-region data residency, strict compliance mandates, or provisioned throughput
430430* Support both pay-as-you-go and provisioned throughput
431* 10% pricing premium reflects infrastructure costs for dedicated regional capacity
431* 10 percent pricing premium reflects infrastructure costs for dedicated regional capacity
432432 
433433### Implementation
434434 

build-with-claude/claude-platform-on-aws Changed · +52 / -52 lines

from line 14
1414 
1515Claude models run on Anthropic-managed infrastructure. This is a commercial integration for billing and access through AWS. Anthropic is the data processor for inference inputs and outputs. AWS processes billing and identity metadata under the marketplace model. Customers using Claude through Claude Platform on AWS are subject to Anthropic's [data use terms](https://www.anthropic.com/legal).
1616 
17Anthropic uses AWS infrastructure to process your API requests, run model inference, and store your workspace content (such as prompts, outputs, files, Skills, and batches). For workspaces created before September 18, 2026, 00:00 UTC, Anthropic might process requests, store data, and run inference outside AWS. In either case, subservices might change without notice. Set the [`inference_geo`](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#data-residency) parameter per request to pin inference to a specific geography.
17Anthropic uses AWS infrastructure to process your API requests, run model inference, and store your workspace content (such as prompts, outputs, files, Skills, and batches). For workspaces created before September 18, 2026, 00:00 UTC, Anthropic might process requests, store data, and run inference outside AWS. In either case, subservices might change without notice. Set the [`inference_geo`](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#data-residency) parameter for each request to pin inference to a specific geography.
1818 
1919Claude Platform on AWS follows the same data retention policy as the first-party Claude API. Zero Data Retention (ZDR) is available on request. Contact your Anthropic account representative to enable it for your organization.
2020 
from line 45
4545 
4646**Which offering are you using?** Claude is available through several distinct products:
4747 
48* **Claude Platform on AWS** (this page): The Claude API platform billed through AWS Marketplace. Managed in the [Claude Console](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#using-the-claude-console) and the AWS Console.
48* **Claude Platform on AWS (this page):** The Claude API platform billed through AWS Marketplace. Managed in the [Claude Console](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#using-the-claude-console) and the AWS Console.
4949* **[Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock):** An AWS-native service. Managed in the Amazon Bedrock console and billed as AWS service usage.
5050* **Claude Enterprise procured through AWS Marketplace:** A [claude.ai](https://claude.ai) plan (the Claude chat product), not an API platform. Managed at claude.ai, and its account and migration behavior differ from what this page describes. See the [Claude Help Center](https://support.claude.com).
5151* **Direct Anthropic accounts:** The first-party Claude API and claude.ai plans billed by Anthropic. Managed in the Claude Console and at claude.ai.
from line 52
5252 
5353## Set up your account
5454 
55Setting up Claude Platform on AWS happens in four phases: sign up on the AWS Console service page, complete your Anthropic organization setup, note your workspace ID, and sign in to the Claude Console.
55Setting up Claude Platform on AWS takes four phases: sign up on the AWS Console service page, complete your Anthropic organization setup, note your workspace ID, and sign in to the Claude Console.
5656 
5757<Note>
5858 Signing up through the AWS Console provisions a new Anthropic organization tied to your AWS account. This organization is separate from any existing organizations your company has with Anthropic, including Claude Enterprise organizations procured through AWS Marketplace. API keys, workspaces, and Claude Console settings from a first-party Anthropic organization don't carry over.
from line 63
6363<Steps>
6464 <Step title="Sign up in the AWS Console">
6565 1. Open the [AWS Console](https://console.aws.amazon.com/) and navigate to the **Claude Platform on AWS** service page.
66 2. Choose **Sign up**.
66 2. Click **Sign up**.
6767 3. On the Sign-up page, review the terms (Anthropic's End User License Agreement, the AWS Privacy Notice, and the AWS Customer Agreement) and select the agreement checkbox.
68 4. Choose **Continue**.
68 4. Click **Continue**.
6969 
7070 The page shows a **Sign-up in progress** banner. Stay on the page. Sign-up takes a few minutes while AWS handles the AWS Marketplace subscription for you, then redirects you automatically.
7171 
from line 79
7979 <Step title="Set up your Anthropic organization">
8080 After sign-up completes, you're redirected to `platform.claude.com/partner-signup`.
8181 
82 1. Enter the email address of your organization's owner and choose **Get started**.
83 2. Check that email inbox for a setup link and follow it. If your browser shows a **Signed in as a different account** page, choose **Log out and continue**.
84 3. Complete the organization details form (organization name, entity type, country, intended use) and choose **Complete setup**.
82 1. Enter the email address of your organization's owner and click **Get started**.
83 2. Check that email inbox for a setup link and follow it. If your browser shows a **Signed in as a different account** page, click **Log out and continue**.
84 3. Complete the organization details form (organization name, entity type, country, intended use) and click **Complete setup**.
8585 
86 Completing setup creates your Anthropic organization and accepts Anthropic's Commercial Terms of Service and Usage Policy. The AWS Console service page now shows a left navigation with **Home**, **API keys**, **Quickstart**, and **Workspaces**.
86 Completing setup creates your Anthropic organization and accepts Anthropic's Commercial Terms of Service and Usage Policy. The AWS Console service page now shows a sidebar with **Home**, **API keys**, **Quickstart**, and **Workspaces**.
8787 </Step>
8888 
8989 <Step title="Create your workspace and note its ID">
90 After you complete setup, the AWS Console prompts you to create a workspace. See [Workspaces](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#workspaces) for details on region binding, IAM resource scoping, and creating additional workspaces.
90 After you complete setup, the AWS Console prompts you to create a workspace. See [Workspace scoping](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#workspace-scoping) for details on region binding and IAM resource scoping, and [Managing workspaces](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#managing-workspaces) for creating additional workspaces.
9191 
9292 Find the workspace ID under **Workspaces** on the AWS Console **Claude Platform on AWS** service page or in the [Claude Console](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#using-the-claude-console). Workspace IDs use the format `wrkspc_` followed by an alphanumeric identifier.
9393 </Step>
from line 95
9595 <Step title="Sign in to the Claude Console">
9696 Access to the Claude Console is federated through AWS IAM:
9797 
98 1. Assume an IAM role with the `aws-external-anthropic:AssumeConsole` permission. See [IAM actions for Claude Platform on AWS](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions#console-access).
98 1. Assume an IAM role with the `aws-external-anthropic:AssumeConsole` permission. See [Console access](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions#console-access).
9999 2. From the **Claude Platform on AWS** service page, choose **Open Claude Console**. The AWS Console issues a JWT and redirects you to `platform.claude.com`.
100100 3. On first sign-in, you're prompted for an email address. Enter your work email. The platform provisions your Claude Console user just-in-time.
101101 
from line 116
116116 
117117Once the new organization is running, the differences are concentrated in billing and authentication, which are handled through AWS:
118118 
119* **Billing** moves to AWS Marketplace: usage is billed in Claude Consumption Units rather than prepaid credits (see [Billing](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#billing)), and you set spend limits on the Billing page (see [Spend limits](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#spend-limits)). During the transition, billing stays separate: the existing organization continues to be billed as it is today.
120* **Authentication and access** move to AWS: requests authenticate with AWS credentials or with API keys generated in the AWS Console, not the Claude Console (see [Authentication](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#authentication)). Organization membership is managed through AWS IAM rather than the Claude Console (see [Available pages](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#available-pages)), and Anthropic's client SDKs provide platform-specific client classes (see [Install an SDK](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#install-an-sdk)).
119* **Billing** moves to AWS Marketplace: usage is billed in Claude Consumption Units rather than prepaid credits (see [Billing](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#billing)), and you set spend limits on the **Billing** page (see [Spend limits](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#spend-limits)). During the transition, billing stays separate: the existing organization continues to be billed as it is today.
120* **Authentication and access** move to AWS: requests authenticate with AWS credentials or with API keys generated in the AWS Console, not the Claude Console (see [Authentication](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#authentication)). Organization membership is managed through AWS IAM rather than the Claude Console (see [Available pages](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#available-pages)), and the SDK provides a platform-specific client class (see [Install an SDK](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#install-an-sdk)).
121121* **Day-to-day API usage** works the way it does on the first-party Claude API, except where noted in the [feature limitations](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#features-not-supported). Before shifting production traffic, check your rate limits: new organizations are placed on the Start tier, and limit increases go through your Anthropic account representative (see [Rate limits and quotas](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#rate-limits-and-quotas)).
122122 
123123For Claude Enterprise (claude.ai) organizations, which behave differently, see the [offering comparison](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#claude-platform-on-aws-vs-amazon-bedrock).
from line 124
124124 
125125### Troubleshooting account setup
126126 
127* **"Sign-up failed: Failed to enable OutboundWebIdentityFederation":** If you see this banner on first submit, choose **Continue** again. The IAM enablement can take a moment to take effect.
127* **"Sign-up failed: Failed to enable OutboundWebIdentityFederation":** If you see this banner on first submit, click **Continue** again. The IAM enablement can take a moment to take effect.
128128* **No progress indicator during sign-up:** Sign-up takes a few minutes. The page shows a static **Sign-up in progress** banner without a progress bar while AWS provisions your account.
129* **"Signed in as a different account" after following the setup link:** Choose **Log out and continue**. The page reauthenticates you with the email address you entered.
129* **"Signed in as a different account" after following the setup link:** Click **Log out and continue**. The page reauthenticates you with the email address you entered.
130130* **"Not found" message during sign-in:** This message might appear briefly during redirect. You can dismiss it.
131131* **Usage page shows no data after your first API call:** Usage data can take a few minutes to appear in the Claude Console.
132132* **"Outbound web identity federation is disabled" on your first API call:** Enable federation once per account. See [Enable outbound web identity federation](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#enable-outbound-web-identity-federation).
from line 143
143143 
144144### Enable outbound web identity federation
145145 
146The Claude Platform on AWS gateway calls `sts:GetWebIdentityToken` server-side to mint a JWT it forwards to Anthropic. This STS capability is **disabled by default** on every AWS account. Enable it once per account:
146The Claude Platform on AWS gateway calls `sts:GetWebIdentityToken` server-side to mint a JWT it forwards to Anthropic. This STS capability is **disabled by default** on every AWS account. Enable it once for each account:
147147 
148148```bash CLI
149149aws iam enable-outbound-web-identity-federation
from line 197
197197 
198198For simpler integration paths (local development and scripts), you can authenticate with an API key instead of SigV4. Set the `ANTHROPIC_AWS_API_KEY` environment variable or pass `api_key` (typescript, php: `apiKey`; go: `APIKey`; java: `.apiKey()`; csharp: `AwsClientOptions.ApiKey`) when you create the client.
199199 
200Generate API keys in the **AWS Console** under **Claude Platform on AWS → API keys**. Choose **Generate a key**, then copy the key value. Grant the `aws-external-anthropic:CallWithBearerToken` IAM action to the principals that should be allowed to use API key authentication.
200Generate API keys in the **AWS Console** under **Claude Platform on AWS → API keys**. Click **Generate a key**, then copy the key value. Grant the `aws-external-anthropic:CallWithBearerToken` IAM action to the principals that should be allowed to use API key authentication.
201201 
202202<Note>
203 API keys for Claude Platform on AWS are managed in the AWS Console, not the Claude Console. Keys created in the standard [Claude Console](https://platform.claude.com/) (for first-party API access) don't work with the Claude Platform on AWS endpoint.
203 API keys for Claude Platform on AWS are managed in the AWS Console, not the Claude Console. Keys created in the standard Claude Console at [platform.claude.com](https://platform.claude.com) (for first-party API access) don't work with the Claude Platform on AWS endpoint.
204204</Note>
205205 
206206#### Short-term API keys
from line 337
337337</Tabs>
338338 
339339<Note>
340 SDK clients for Claude Platform on AWS are in beta.
340 The SDK client for Claude Platform on AWS is in beta.
341341</Note>
342342 
343343## Available models
from line 600
600600 The AWS region your workspace is bound to controls which gateway endpoint you call and where AWS-side resources (IAM, CloudTrail, billing) are scoped. It does not pin where model inference runs. To pin inference to a specific geography, set `inference_geo` on each request or configure a workspace default.
601601</Note>
602602 
603Set the inference geography per request with the `inference_geo` parameter:
603Set the inference geography for each request with the `inference_geo` parameter:
604604 
605605<Note>
606606 The `inference_geo` parameter is supported on Claude 4.6 and later models. Requests with `inference_geo` on Claude Opus 4.5, Claude Sonnet 4.5 (deprecated), or Claude Haiku 4.5 return a 400 error. See [Data residency](https://platform.claude.com/docs/en/manage-claude/data-residency) for model availability details.
from line 772
772772 
773773### Workspace scoping
774774 
775Workspaces are bound to a single AWS region. A workspace created in `us-west-2` can only be accessed through the `us-west-2` endpoint. Usage, quotas, cost, files, batches, and Skills all roll up per workspace, giving you per-region breakdowns in the Claude Console.
775Workspaces are bound to a single AWS region. A workspace created in `us-west-2` can only be accessed through the `us-west-2` endpoint. Usage, quotas, cost, files, batches, and Skills all roll up by workspace, giving you per-region breakdowns in the Claude Console.
776776 
777777Workspaces also serve as the primary IAM resource for Claude Platform on AWS. You grant or deny access to specific workspaces through AWS IAM policies using the workspace ARN. The ARN's resource segment is the same `wrkspc_`-prefixed ID you pass in the `anthropic-workspace-id` header:
778778 
from line 800
800800 
801801Access to the Claude Console is federated through AWS IAM. See [Set up your account](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#set-up-your-account) for the full first-time sign-in flow. In short:
802802 
8031. Assume an IAM role with the `aws-external-anthropic:AssumeConsole` permission. See [IAM actions for Claude Platform on AWS](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions#console-access).
8031. Assume an IAM role with the `aws-external-anthropic:AssumeConsole` permission. See [Console access](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions#console-access).
8048042. Navigate to the Claude Platform on AWS page in the [AWS Console](https://console.aws.amazon.com/).
8053. Choose **Open Claude Console**. The AWS Console issues a JWT and redirects you to `platform.claude.com`.
8053. Click **Open Claude Console**. The AWS Console issues a JWT and redirects you to `platform.claude.com`.
8068064. On first sign-in, you're prompted for an email address. Enter your work email. The platform provisions your Claude Console user just-in-time.
807807 
808808Two Claude Console roles are available: **Admin** and **Developer**. The Admin role grants access to all Claude Console pages and settings available for Claude Platform on AWS. The Developer role grants read access to usage, cost, rate limit, and workspace information. Contact your Anthropic account representative to assign the Admin or Developer role to a principal.
from line 809
809809 
810810### Available pages
811811 
812The **Through AWS gateway** column indicates whether the page reads and writes data through the AWS gateway (and is therefore governed by [IAM actions](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions)). Pages marked **No** read organization-level metadata directly from Anthropic and bypass IAM action checks.
812The **Through AWS gateway** column indicates whether the page reads and writes data through the AWS gateway (and is therefore governed by [IAM actions for Claude Platform on AWS](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions)). Pages marked **No** read organization-level metadata directly from Anthropic and bypass IAM action checks.
813813 
814| Page | Available | Through AWS gateway | Notes |
815| --------------------- | ------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
816| **Usage** | Yes | No | View token usage by model, workspace, and dimension. Data can take a few minutes to appear after a request. |
817| **Cost** | Yes | No | View cost breakdowns by model and workspace. AWS Cost Explorer shows the aggregated [Claude Consumption Unit (CCU)](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#billing) line item. |
818| **Rate limits** | Yes | No | View rate limits (read-only). Tier increases go through your Anthropic account representative; see [Rate limits and quotas](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#rate-limits-and-quotas). |
819| **Workspaces** | Yes | Yes (except spend limits) | View per-region workspaces. With the Admin role, you can also create, rename, and archive workspaces, and set per-workspace [spend limits](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#spend-limits). |
820| **Encryption keys** | Yes | Yes | A section of the [Data retention](https://platform.claude.com/settings/privacy#encryption-keys) page (`platform.claude.com/settings/privacy`) in the Claude Console, shown while **Organization** is selected in the dropdown menu at the top of the page. Register AWS KMS keys for [CMEK](https://platform.claude.com/docs/en/manage-claude/cmek-claude-platform-on-aws) there (Admin role). To attach a registered key to a workspace, select the workspace from that dropdown menu, then select the key under **Encryption key**. |
821| **Files** | Yes | Yes | View and manage uploaded files. |
822| **Skills** | Yes | Yes | View and manage Agent Skills. |
823| **Batches** | Yes | Yes | View and manage batch processing jobs. |
824| **Agents** | Yes | Yes | View and manage agent definitions. |
825| **Sessions** | Yes | Yes | View agent sessions and event history. |
826| **Environments** | Yes | Yes | View and manage cloud sandbox configurations for sessions. |
827| **Credential vaults** | Yes | Yes | View and manage credential vaults for session authentication. |
828| **Memory stores** | Yes | Yes | View and manage persistent agent memory. |
829| **Webhooks** | Yes | Yes | View and manage webhook endpoints. |
830| **API keys** | No | N/A | Manage API keys in the AWS Console (**Claude Platform on AWS → API keys**). See [API key authentication](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#api-key-authentication). |
831| **Members** | No | N/A | Not applicable. AWS IAM manages access. |
832| **Billing** | Yes (limited) | No | Set an organization monthly spend limit; see [Spend limits](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#spend-limits). AWS Marketplace manages invoicing. View cost breakdowns on the Cost page. |
833| **Claude Code** | No | N/A | View Claude Code usage on the Usage page. |
814| Page | Available | Through AWS gateway | Notes |
815| --------------------- | ------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
816| **Usage** | Yes | No | View token usage by model, workspace, and dimension. Data can take a few minutes to appear after a request. |
817| **Cost** | Yes | No | View cost breakdowns by model and workspace. AWS Cost Explorer shows the aggregated [Claude Consumption Unit (CCU)](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#billing) line item. |
818| **Rate limits** | Yes | No | View rate limits (read-only). Tier increases go through your Anthropic account representative; see [Rate limits and quotas](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#rate-limits-and-quotas). |
819| **Workspaces** | Yes | Yes (except spend limits) | View per-region workspaces. With the Admin role, you can also create, rename, and archive workspaces, and set per-workspace [spend limits](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#spend-limits). |
820| **Encryption keys** | Yes | Yes | A section of the [Data retention](https://platform.claude.com/settings/privacy#encryption-keys) page (`platform.claude.com/settings/privacy`) in the Claude Console, shown while **Organization** is selected in the dropdown menu at the top of the page. Register AWS KMS keys there (Admin role), as described in [Set up CMEK on Claude Platform on AWS](https://platform.claude.com/docs/en/manage-claude/cmek-claude-platform-on-aws). To attach a registered key to a workspace, select the workspace from that dropdown menu, then select the key under **Encryption key**. |
821| **Files** | Yes | Yes | View and manage uploaded files. |
822| **Skills** | Yes | Yes | View and manage Agent Skills. |
823| **Batches** | Yes | Yes | View and manage batch processing jobs. |
824| **Agents** | Yes | Yes | View and manage agent definitions. |
825| **Sessions** | Yes | Yes | View agent sessions and event history. |
826| **Environments** | Yes | Yes | View and manage cloud sandbox configurations for sessions. |
827| **Credential vaults** | Yes | Yes | View and manage credential vaults for session authentication. |
828| **Memory stores** | Yes | Yes | View and manage persistent agent memory. |
829| **Webhooks** | Yes | Yes | View and manage webhook endpoints. |
830| **API keys** | No | N/A | Manage API keys in the AWS Console (**Claude Platform on AWS → API keys**). See [API key authentication](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#api-key-authentication). |
831| **Members** | No | N/A | Not applicable. AWS IAM manages access. |
832| **Billing** | Yes (limited) | No | Set an organization monthly spend limit; see [Spend limits](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#spend-limits). AWS Marketplace manages invoicing. View cost breakdowns on the **Cost** page. |
833| **Claude Code** | No | N/A | View Claude Code usage on the **Usage** page. |
834834 
835835### Switching organizations
836836 
from line 840
840840 
841841Organizations on Claude Platform on AWS are placed on the Start tier. Anthropic manages rate limits directly, not through AWS quota systems.
842842 
843Organizations on Claude Platform on AWS can move to a higher usage tier automatically as they build a history of paid AWS Marketplace invoices. The self-service **Request tier increase** flow in the Claude Console is not available: the Rate limits page directs you to your Anthropic account representative instead.
843Organizations on Claude Platform on AWS can move to a higher usage tier automatically as they build a history of paid AWS Marketplace invoices. The self-service **Request tier increase** flow in the Claude Console is not available: the **Rate limits** page directs you to your Anthropic account representative instead.
844844 
845845To request higher limits, contact your Anthropic account representative or [Anthropic support](https://support.claude.com). Include the following in your request:
846846 
from line 860
860860 
861861The Start, Build, and Scale usage tiers each carry a monthly spend cap; see the [per-tier spend caps](https://platform.claude.com/docs/en/api/rate-limits#spend-limits) for current values. When your organization's usage for the calendar month reaches its tier's cap, API requests fail with the [spend-cap error](https://platform.claude.com/docs/en/api/rate-limits#reaching-your-spend-cap) until 00:00 UTC on the first day of the next month, and retrying sooner doesn't succeed. The spend cap and rate limits belong to the same tier. To raise the cap, or to restore access after reaching it, request a tier increase through your Anthropic account representative or [Anthropic support](https://support.claude.com) (see [Rate limits and quotas](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#rate-limits-and-quotas)).
862862 
863You can also set your own monthly spend limits below the cap, after adding at least one recipient under **Email recipients** on the Billing page:
863You can also set your own monthly spend limits below the cap, after adding at least one recipient under **Email recipients** on the **Billing** page:
864864 
865865* **Organization spend limit:** Go to [Settings > Billing](https://platform.claude.com/settings/billing) in the [Claude Console](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#using-the-claude-console) to set a monthly spend limit.
866866* **Workspace spend limits:** On the [Workspaces](https://platform.claude.com/settings/workspaces) page (`platform.claude.com/settings/workspaces`) in the Claude Console, select a workspace. In the panel that opens, click **Spend limits**.
from line 867
867867 
868868When usage reaches a limit you set, requests fail with HTTP 400 (see the [spend limit error](https://platform.claude.com/docs/en/api/rate-limits#setting-your-own-spend-limit)) until 00:00 UTC on the first day of the next month, or until you raise or remove the limit.
869869 
870Spend is calculated at list prices and can take about 2 hours to reflect recent usage, so usage can exceed the cap or a limit before requests start failing. The overshoot is billed. When the tier cap or an organization spend limit stops your requests, an email notice goes to the recipients listed under **Email recipients** on the Billing page. Role-based recipients, such as all admins, aren't available on Claude Platform on AWS. The tier-cap notice also goes to the email address used at AWS Marketplace sign-up.
870Spend is calculated at list prices and can take about 2 hours to reflect recent usage, so usage can exceed the cap or a limit before requests start failing. The overshoot is billed. When the tier cap or an organization spend limit stops your requests, an email notice goes to the recipients listed under **Email recipients** on the **Billing** page. Role-based recipients, such as all admins, aren't available on Claude Platform on AWS. The tier-cap notice also goes to the email address used at AWS Marketplace sign-up.
871871 
872872## Monitoring and logging
873873 
from line 1099
10991099| **Region availability** | See [Amazon Bedrock regions](https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html) | See [Amazon Bedrock regions](https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html) | All AWS commercial regions |
11001100| **Anthropic organization** | None required | None required | New organization created at sign-up. Existing organizations can't be converted (see [Moving from an existing Anthropic organization](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#moving-from-an-existing-anthropic-organization)) |
11011101 
1102If you're on the current Bedrock integration, the request body format is already the Messages API. The changes are the base URL, SigV4 service name, model IDs, and adding the `anthropic-workspace-id` header. If you're on the legacy InvokeModel or Converse API, you'll also rewrite the request and response shapes to the Messages API format. See [Claude on Amazon Bedrock (Opus 4.6 and earlier)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy) for the request-shape mapping.
1102If you're on the current Bedrock integration, the request body format is already the Messages API. The changes are the base URL, SigV4 service name, model IDs, and the added `anthropic-workspace-id` header. If you're on the legacy InvokeModel or Converse API, you'll also rewrite the request and response shapes to the Messages API format. See [Claude on Amazon Bedrock (Opus 4.6 and earlier)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy) for the request-shape mapping.
11031103 
11041104### What you gain
11051105 
from line 1120
11201120### Migration pitfalls
11211121 
11221122<Warning>
1123 **Enable outbound web identity federation first.** If your AWS account has not previously used Claude Platform on AWS, you must [enable outbound web identity federation](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#enable-outbound-web-identity-federation) once per account before making requests. Without this step, all requests fail with a federation error (see [Enable outbound web identity federation](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#enable-outbound-web-identity-federation) for the exact error and remediation). This step is not required for Bedrock.
1123 **Enable outbound web identity federation first.** If your AWS account has not previously used Claude Platform on AWS, you must [enable outbound web identity federation](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#enable-outbound-web-identity-federation) once for each account before making requests. Without this step, all requests fail with a federation error (see [Enable outbound web identity federation](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#enable-outbound-web-identity-federation) for the exact error and remediation). This step is not required for Bedrock.
11241124</Warning>
11251125 
11261126<Warning>
from line 1185
11851185 
11861186### Managed policies
11871187 
1188AWS provides five managed policies (`AnthropicFullAccess`, `AnthropicReadOnlyAccess`, `AnthropicInferenceAccess`, `AnthropicLimitedAccess`, and `AnthropicSelfHostedEnvironmentAccess`) for common access patterns. For the actions each policy grants, the complete list of IAM actions, the route-to-action mapping, and additional policy examples, see [IAM actions for Claude Platform on AWS](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions#managed-policies).
1188AWS provides five managed policies (`AnthropicFullAccess`, `AnthropicReadOnlyAccess`, `AnthropicInferenceAccess`, `AnthropicLimitedAccess`, and `AnthropicSelfHostedEnvironmentAccess`) for common access patterns. For the actions each policy grants, see [Managed policies](https://platform.claude.com/docs/en/api/claude-platform-on-aws-iam-actions#managed-policies) in IAM actions for Claude Platform on AWS. The same page has the complete list of IAM actions, the route-to-action mapping, and additional policy examples.
11891189 
11901190## Next steps
11911191 

build-with-claude/compaction-background Changed · +3 / -3 lines

from line 41
4141For example, if the compaction request held messages 1 to 5 and the conversation gained messages 6 to 8 while it ran, after the swap your history is the block followed by messages 6 to 8.
4242 
4343<Frame>
44 ![Background compaction timeline: the compaction request is sent with messages 1 to 5 while the conversation continues on its full history and gains messages 6 to 8; when the block arrives, it replaces messages 1 to 5 at the front of the history, and the history becomes the block followed by messages 6 to 8](https://platform.claude.com/docs/images/compaction-background-timeline.svg)
44 ![Background compaction: while a compaction request for messages 1 to 5 runs, 6 to 8 arrive; then the block replaces 1 to 5](https://platform.claude.com/docs/images/compaction-background-timeline.svg)
4545</Frame>
4646 
4747If the response has any other `stop_reason`, no summary was produced, which counts as a failure in step 2. Keep the full history; [Handle a missing summary or an error](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#when-no-summary-comes-back) lists the causes and what to do for each.
from line 535
535535</CodeGroup>
536536 
537537* **Deciding when to compact:** The size check also requires that no compaction request is pending.
538* **Starting the request:** Where the loop waits for the compaction response, this version records how many messages the history holds, starts the request on a copy of the history with each language's own concurrency tool, and goes on to the next turn without waiting.
539* **Checking for the result:** At the top of each turn, the program checks whether the pending request has finished. If it has, the program makes the swap before it sends that turn's request.
538* **Starting the request:** Where the loop waits for the compaction response, this version records how many messages the history holds, starts the request on a copy of the history with the language's own concurrency tool, and goes on to the next turn without waiting.
539* **Checking for the result:** At the top of each turn, the program checks whether the pending request has completed. If it has, the program makes the swap before it sends that turn's request.
540540* **Making the swap:** Where the loop replaces the whole history with the returned message, this version's swap function replaces only the messages the request held, counted from the front, and keeps everything appended since.
541541* **Ending the loop:** If the compaction request is still pending when the loop ends, the program waits for it and makes the swap, so a summary that is still on its way isn't lost before you save or continue the conversation.
542542 

build-with-claude/compaction-on-demand Changed · +17 / -17 lines

from line 27
2727 Microsoft Foundry: beta
2828---
2929 
30With on-demand compaction, your application decides when a conversation is summarized: you send one request with the `compaction` parameter, and Claude returns a summary in place of a reply.
30With on-demand compaction, your application determines when a conversation is summarized: you send one request with the `compaction` parameter, and Claude returns a summary in place of a reply.
3131 
3232## How on-demand compaction works
3333 
3434A compaction request is separate from your conversation turns. You send the conversation as it stands with the `compaction` parameter, and the response contains a single `compaction` block. The block holds the summary as text you can read, and a signature. Send it in future requests exactly as it came.
3535 
36From then on the block takes the place of the messages it summarizes. It goes first in `messages`, the summarized messages are removed, and your next turn follows it. Claude sees the summary where those messages were.
36From then on the block takes the place of the messages it summarizes. It goes first in `messages`, the summarized messages are removed, and your next turn follows it. Claude receives the summary where those messages were.
3737 
3838<Frame>
39 ![On-demand compaction: a request that carries four messages and the compaction parameter returns one compaction block and no reply; on the next request the block comes first in messages in place of those four messages, followed by the next user turn](https://platform.claude.com/docs/images/compaction-on-demand-swap.svg)
39 ![On-demand compaction: a request with four messages returns one compaction block, which replaces them in the next request](https://platform.claude.com/docs/images/compaction-on-demand-swap.svg)
4040</Frame>
4141 
4242## Request a summary
from line 343
343343 
344344* Put the block first in `messages`, either as an `assistant` message of its own or as the first content block of the first message, whether that is a `user` or `assistant` message.
345345* Remove the summarized messages. If any remain in front of the block, the request returns a 400 error (`compaction_block_misplaced`).
346* Send exactly one `compaction` block per request, on every later request.
346* Send exactly one `compaction` block in each request, on every later request.
347347 
348348<Warning>
349349 Two mistakes in the swap raise no error. If summarized messages remain after the block, the API sends them to Claude again. If a later request leaves the block out, Claude gets no summary.
from line 758
758758 
759759The check on `stop_reason` comes before the code looks for the block; [Handle a missing summary or an error](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#when-no-summary-comes-back) says why. The history is replaced, not appended to: the returned message replaces every message the request carried, under the rules in [Continue from the summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#continue-from-the-summary). When no summary comes back, the loop keeps its history and asks again after the next turn.
760760 
761The SDK [tool runner](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner) in Python, TypeScript, C#, Go, Java, PHP, and Ruby can send the compaction request for you. When you decide to compact, call `compact_before_next_turn()` (typescript, java, php: `compactBeforeNextTurn()`; csharp, go: `CompactBeforeNextTurn()`) on the runner. Once the current turn and its tool calls finish, the runner sends the compaction request and replaces its history with the returned message. Create the runner with the `compact-2026-09-04` beta, because the runner doesn't add it.
761The SDK [tool runner](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner) in Python, TypeScript, C#, Go, Java, PHP, and Ruby can send the compaction request for you. When you decide to compact, call `compact_before_next_turn()` (typescript, java, php: `compactBeforeNextTurn()`; csharp, go: `CompactBeforeNextTurn()`) on the runner. Once the current turn and its tool calls complete, the runner sends the compaction request and replaces its history with the returned message. Create the runner with the `compact-2026-09-04` beta, because the runner doesn't add it.
762762 
763763The runner builds the compaction request from its own parameters and leaves `context_management` out. It also leaves out `stop_sequences`, a `tool_choice` of type `any` or `tool`, and a structured-output `output_config.format`, which the API rejects on a compaction request. [Request a summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#request-a-summary) explains why. The runner sends them again on its later requests. SDK versions before Python 1.8.0, TypeScript 0.128.0, C# 12.50.0, Go 1.75.0, and Java 2.65.0 send them on the compaction request too. On those versions, a runner that sets any of these parameters gets a 400 error. The runner sends a [task budget](https://platform.claude.com/docs/en/build-with-claude/task-budgets) unchanged. If `output_config.task_budget` sets `remaining`, the compaction request returns a 400 error, so leave `remaining` unset, as [Limits and interactions with other features](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#how-it-fits-with-the-rest-of-the-api) says. The runner refuses to compact while its `context_management` has a compaction edit, so use one kind of compaction on a runner.
764764 
765765### When to compact
766766 
767You can send a compaction request after any completed turn, so your code decides when.
767You can send a compaction request after any completed turn, so your code determines when.
768768 
769769To estimate how large the next request will be, add `input_tokens` and `output_tokens` from the last response's `usage`, as the loop does. With [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#tracking-cache-performance), `input_tokens` counts only the tokens after the last cache breakpoint, so add `cache_read_input_tokens` and `cache_creation_input_tokens` as well. You can also send the same messages to the [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) endpoint.
770770 
from line 803
803803 
804804A compaction request, or a request that carries a block, can also fail outright. Most 400 errors have a message that says what to remove or resend. Some also carry an `error.details.error_code` that starts with `compaction_`. Parameter errors, such as a field that can't be combined with `compaction`, carry the message only.
805805 
806| Error | Cause | What to do |
807| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
808| 529 `overloaded_error`, `error.details.error_code` `compaction_unavailable` | A transient server problem while producing a block, or while reading one you sent back. | Retry the request. |
809| 400 `compaction_block_misplaced` | Summarized messages remain in front of the block. | Remove them, so the block comes first in `messages`. |
810| 400 `compaction_signature_invalid` or `compaction_content_mismatch` | The block's `signature` or `content` was changed after the API returned it. | Send the block exactly as returned, including its `signature`. |
811| 400 | The request carries more than one `compaction` block. | Send exactly one, the newest. |
812| 400 | The last `assistant` turn ends in a tool call with no result yet. | Send that turn's tool results, then compact. |
813| 400 `compaction_nothing_to_summarize` | `messages` has no `user` or `assistant` content, for example an empty list. | Send at least one `user` or `assistant` message. |
814| 400 on the compaction request, with a message that says the `compaction` parameter `requires anthropic-beta: compact-2026-09-04` | The compaction request left out the beta header. | Add the beta header; see [Request a summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#request-a-summary). |
815| 400 on a later request that carries the block: a validation error that says `compaction` is not one of the expected content block types. The message doesn't mention the header | That request left out the beta header. | Add the beta header to every request that carries the block; see [Request a summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#request-a-summary). |
816| 400 validation error, such as `messages.0.content.0.compaction.citations: Extra inputs are not permitted` | A block was sent back with fields the API didn't return, such as `citations: null`. | Send the block exactly as returned; see [Continue from the summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#continue-from-the-summary). |
806| Error | Cause | What to do |
807| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
808| 529 `overloaded_error`, `error.details.error_code` `compaction_unavailable` | A transient server problem while producing a block, or while reading one you sent back. | Retry the request. |
809| 400 `compaction_block_misplaced` | Summarized messages remain in front of the block. | Remove them, so the block comes first in `messages`. |
810| 400 `compaction_signature_invalid` or `compaction_content_mismatch` | The block's `signature` or `content` was changed after the API returned it. | Send the block exactly as returned, including its `signature`. |
811| 400 | The request carries more than one `compaction` block. | Send exactly one, the newest. |
812| 400 | The last `assistant` turn ends in a tool call with no result yet. | Send that turn's tool results, then compact. |
813| 400 `compaction_nothing_to_summarize` | `messages` has no `user` or `assistant` content, for example an empty list. | Send at least one `user` or `assistant` message. |
814| 400 on the compaction request, with a message that says the `compaction` parameter `requires anthropic-beta: compact-2026-09-04` | The compaction request left out the beta header. | Add the beta header; see [Request a summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#request-a-summary). |
815| 400 on a later request that carries the block: a validation error that says `compaction` is not one of the expected content block types. The message doesn't mention the header. | That request left out the beta header. | Add the beta header to every request that carries the block; see [Request a summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#request-a-summary). |
816| 400 validation error, such as `messages.0.content.0.compaction.citations: Extra inputs are not permitted` | A block was sent back with fields the API didn't return, such as `citations: null`. | Send the block exactly as returned; see [Continue from the summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#continue-from-the-summary). |
817817 
818818## Count compaction usage
819819 

build-with-claude/compaction-threshold Changed · +17 / -17 lines

from line 263
263263 
264264 response = client.beta.messages.create(
265265 betas: ["compact-2026-01-12"],
266 model: "claude-opus-5-5",
266 model: Anthropic::Model::CLAUDE_OPUS_5_5,
267267 max_tokens: 4096,
268268 messages: messages,
269269 context_management: {
from line 483
483483 
484484 response = client.beta.messages.create(
485485 betas: ["compact-2026-01-12"],
486 model: "claude-opus-5-5",
486 model: Anthropic::Model::CLAUDE_OPUS_5_5,
487487 max_tokens: 4096,
488488 messages: messages,
489489 context_management: {
from line 704
704704 
705705 response = client.beta.messages.create(
706706 betas: ["compact-2026-01-12"],
707 model: "claude-opus-5-5",
707 model: Anthropic::Model::CLAUDE_OPUS_5_5,
708708 max_tokens: 4096,
709709 messages: [
710710 { role: "user", content: "Help me build a Python web scraper" },
from line 1037
10371037 
10381038 response = client.beta.messages.create(
10391039 betas: ["compact-2026-01-12"],
1040 model: "claude-opus-5-5",
1040 model: Anthropic::Model::CLAUDE_OPUS_5_5,
10411041 max_tokens: 4096,
10421042 messages: messages,
10431043 context_management: {
from line 1055
10551055 
10561056 response = client.beta.messages.create(
10571057 betas: ["compact-2026-01-12"],
1058 model: "claude-opus-5-5",
1058 model: Anthropic::Model::CLAUDE_OPUS_5_5,
10591059 max_tokens: 4096,
10601060 messages: messages,
10611061 context_management: {
from line 1070
10701070 
10711071#### Enforcing a total token budget
10721072 
1073When a model works on long tasks with many tool-use iterations, total token consumption can grow significantly. You can combine `pause_after_compaction` with a compaction counter to estimate cumulative usage and gracefully wrap up the task once a budget is reached.
1073When a model works on long tasks with many tool-use iterations, total token consumption can grow significantly. You can combine `pause_after_compaction` with a compaction counter to estimate cumulative usage and gracefully end the task once a budget is reached.
10741074 
10751075This example appears in the SDK languages only: its value is the budget-tracking logic around the request. The raw request combines the `trigger` from [Trigger configuration](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold#trigger-configuration) with `pause_after_compaction` from [Pausing after compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold#pausing-after-compaction).
10761076 
from line 1330
13301330 
13311331 response = client.beta.messages.create(
13321332 betas: ["compact-2026-01-12"],
1333 model: "claude-opus-5-5",
1333 model: Anthropic::Model::CLAUDE_OPUS_5_5,
13341334 max_tokens: 4096,
13351335 messages: messages,
13361336 context_management: {
from line 1617
16171617 
16181618 response = client.beta.messages.create(
16191619 betas: ["compact-2026-01-12"],
1620 model: "claude-opus-5-5",
1620 model: Anthropic::Model::CLAUDE_OPUS_5_5,
16211621 max_tokens: 4096,
16221622 messages: messages,
16231623 context_management: {
from line 1631
16311631 
16321632 next_response = client.beta.messages.create(
16331633 betas: ["compact-2026-01-12"],
1634 model: "claude-opus-5-5",
1634 model: Anthropic::Model::CLAUDE_OPUS_5_5,
16351635 max_tokens: 4096,
16361636 messages: messages,
16371637 context_management: {
from line 1648
16481648When the API receives a `compaction` block, all content blocks before it are ignored. You can either:
16491649 
16501650* Keep the original messages in your list and let the API handle removing the compacted content
1651* Manually drop the compacted messages and only include the compaction block onwards
1651* Manually drop the compacted messages and only include the compaction block onward
16521652 
16531653On Claude Fable 5.1, Claude Mythos 5.1, Claude Opus 5.5, Claude Sonnet 5.5, and Claude Haiku 5.5, thinking blocks from before a `compaction` block aren't carried forward, so the summary is all the model has of that earlier work. If you write your own `instructions`, tell the model what the summary must retain; see [Tell the model what to preserve in compaction summaries](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-fable-5-1#tell-the-model-what-to-preserve-in-compaction-summaries).
16541654 
from line 1959
19591959 
19601960 stream = client.beta.messages.stream(
19611961 betas: ["compact-2026-01-12"],
1962 model: "claude-opus-5-5",
1962 model: Anthropic::Model::CLAUDE_OPUS_5_5,
19631963 max_tokens: 4096,
19641964 messages: messages,
19651965 context_management: {
from line 2229
22292229 
22302230 response = client.beta.messages.create(
22312231 betas: ["compact-2026-01-12"],
2232 model: "claude-opus-5-5",
2232 model: Anthropic::Model::CLAUDE_OPUS_5_5,
22332233 max_tokens: 4096,
22342234 system: [
22352235 {
from line 2454
24542454 
24552455 count_response = client.beta.messages.count_tokens(
24562456 betas: ["compact-2026-01-12"],
2457 model: "claude-opus-5-5",
2457 model: Anthropic::Model::CLAUDE_OPUS_5_5,
24582458 messages: messages,
24592459 context_management: {
24602460 edits: [{ type: "compact_20260112" }]
from line 2740
27402740 
27412741 response = client.beta.messages.create(
27422742 betas: ["compact-2026-01-12"],
2743 model: "claude-opus-5-5",
2743 model: Anthropic::Model::CLAUDE_OPUS_5_5,
27442744 max_tokens: 4096,
27452745 messages: messages,
27462746 context_management: {
from line 3300
33003300 
33013301 response = client.beta.messages.create(
33023302 betas: ["compact-2026-01-12"],
3303 model: "claude-opus-5-5",
3303 model: Anthropic::Model::CLAUDE_OPUS_5_5,
33043304 max_tokens: 4096,
33053305 messages: messages,
33063306 context_management: {
from line 3331
33313331 
33323332 response = client.beta.messages.create(
33333333 betas: ["compact-2026-01-12"],
3334 model: "claude-opus-5-5",
3334 model: Anthropic::Model::CLAUDE_OPUS_5_5,
33353335 max_tokens: 4096,
33363336 messages: messages_after_compaction,
33373337 context_management: {
from line 3375
33753375 Learn about context window sizes and management strategies.
33763376 </Card>
33773377 
3378 <Card title="Session memory compaction cookbook" icon="book" href="https://platform.claude.com/cookbook/misc-session-memory-compaction">
3378 <Card title="Session memory compaction recipe" icon="book" href="https://platform.claude.com/cookbook/misc-session-memory-compaction">
33793379 Explore a practical implementation that manages long-running conversations with instant session memory compaction using background threading and prompt caching.
33803380 </Card>
33813381</CardGroup>

build-with-claude/context-editing Changed · +262 / -260 lines

### Context editing occurs server-side ### Context editing happens server-side

The two sides of this change are more than 400 edits apart, too far apart to line up, so this is the differ's own diff of it and the words inside a line are not marked.

from line 14
1414 For most use cases, [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) is the primary strategy for managing context in long-running conversations. The strategies on this page are useful for specific scenarios where you need more fine-grained control over what content is cleared.
1515</Note>
1616 
17Context editing allows you to selectively clear specific content from conversation history as it grows. Beyond optimizing costs and staying within limits, this is about actively curating what Claude sees: context is a finite resource with diminishing returns, and irrelevant content degrades model focus. Context editing gives you fine-grained runtime control over that curation. For the broader principles behind context management, see [Effective context engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents). This page covers:
18 
19* **Tool result clearing** - Best for agentic workflows with heavy tool use where old tool results are no longer needed
20* **Thinking block clearing** - For managing thinking blocks from earlier turns, with options to preserve recent thinking for context continuity
21* **Client-side SDK compaction** - An SDK-based alternative for summary-based context management (server-side compaction is generally preferred)
17Context editing allows you to selectively clear specific content from conversation history as it grows. Beyond optimizing costs and staying within limits, this is about actively curating what Claude receives: context is a finite resource with diminishing returns, and irrelevant content degrades model focus. Context editing gives you fine-grained runtime control over that curation. For the broader principles behind context management, see [Effective context engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents). This page covers:
18 
19* **Tool result clearing:** Best for agentic workflows with heavy tool use where old tool results are no longer needed
20* **Thinking block clearing:** For managing thinking blocks from earlier turns, with options to preserve recent thinking for context continuity
21* **Client-side SDK compaction:** An SDK-based alternative for summary-based context management (server-side compaction is generally preferred)
2222 
2323| Approach | Where it runs | Strategies | How it works |
2424| --------------- | ------------- | ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
from line 35
3535 
3636### Tool result clearing
3737 
38The `clear_tool_uses_20250919` strategy clears tool results when conversation context grows beyond your configured threshold. This is particularly useful for agentic workflows with heavy tool use. Older tool results (like file contents or search results) are no longer needed once Claude has processed them.
38The `clear_tool_uses_20250919` strategy clears tool results when conversation context grows beyond your configured threshold. This is particularly useful for agentic workflows with heavy tool use. Older tool results (such as file contents or search results) are no longer needed once Claude has processed them.
3939 
4040When activated, the API automatically clears the oldest tool results in chronological order. The API replaces each cleared result with placeholder text indicating to Claude that it was removed. By default, only tool results are cleared. You can optionally clear both tool results and tool calls (the tool use parameters) by setting `clear_tool_inputs` to true.
4141 
from line 56
5656 Use this strategy to override the default. If your code runs across multiple model tiers, set `keep` explicitly rather than relying on the per-model default.
5757</Tip>
5858 
59An assistant conversation turn may include multiple content blocks (for example, when using tools) and multiple thinking blocks (for example, with [interleaved thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#interleaved-thinking)).
60 
61### Context editing happens server-side
59An assistant conversation turn might include multiple content blocks (for example, when using tools) and multiple thinking blocks (for example, with [interleaved thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#interleaved-thinking)).
60 
61### Context editing occurs server-side
6262 
6363Context editing is applied server-side before the prompt reaches Claude. Your client application maintains the full, unmodified conversation history. You do not need to sync your client state with the edited version. Continue managing your full conversation history locally as you normally would.
6464 
from line 70
7070 
7171* **Tool result clearing:** Invalidates cached prompt prefixes when content is cleared. To account for this, clear enough tokens to make the cache invalidation worthwhile. Use the `clear_at_least` parameter to ensure a minimum number of tokens is cleared each time. You'll incur cache write costs each time content is cleared, but subsequent requests can reuse the newly cached prefix.
7272 
73* **Thinking block clearing:** When thinking blocks are **kept** in context (not cleared), the prompt cache is preserved, enabling cache hits and reducing input token costs. When thinking blocks are **cleared**, the cache is invalidated at the point where clearing occurs. Configure the `keep` parameter based on whether you want to prioritize cache performance or context window availability.
73* **Thinking block clearing:** When thinking blocks are **kept** in context (not cleared), the prompt cache is preserved, allowing cache hits and reducing input token costs. When thinking blocks are **cleared**, the cache is invalidated at the point where clearing occurs. Configure the `keep` parameter based on whether you want to prioritize cache performance or context window availability.
7474 
7575## Supported models
7676 
from line 83
8383<CodeGroup>
8484 ```bash cURL
8585 curl https://api.anthropic.com/v1/messages \
86 --header "x-api-key: $ANTHROPIC_API_KEY" \
87 --header "anthropic-version: 2023-06-01" \
88 --header "content-type: application/json" \
89 --header "anthropic-beta: context-management-2025-06-27" \
90 --data '{
91 "model": "claude-opus-5-5",
92 "max_tokens": 4096,
93 "messages": [
94 {
95 "role": "user",
96 "content": "Search for recent developments in AI"
97 }
98 ],
99 "tools": [
100 {
101 "type": "web_search_20250305",
102 "name": "web_search"
103 }
104 ],
105 "context_management": {
106 "edits": [
107 {"type": "clear_tool_uses_20250919"}
108 ]
109 }
110 }'
86 -H "x-api-key: $ANTHROPIC_API_KEY" \
87 -H "anthropic-version: 2023-06-01" \
88 -H "content-type: application/json" \
89 -H "anthropic-beta: context-management-2025-06-27" \
90 -d '{
91 "model": "claude-opus-5-5",
92 "max_tokens": 4096,
93 "messages": [
94 {
95 "role": "user",
96 "content": "Search for recent developments in AI"
97 }
98 ],
99 "tools": [
100 {
101 "type": "web_search_20250305",
102 "name": "web_search"
103 }
104 ],
105 "context_management": {
106 "edits": [
107 {"type": "clear_tool_uses_20250919"}
108 ]
109 }
110 }'
111111 ```
112112 
113113 ```bash CLI
from line 296
296296<CodeGroup>
297297 ```bash cURL
298298 curl https://api.anthropic.com/v1/messages \
299 --header "x-api-key: $ANTHROPIC_API_KEY" \
300 --header "anthropic-version: 2023-06-01" \
301 --header "content-type: application/json" \
302 --header "anthropic-beta: context-management-2025-06-27" \
303 --data '{
304 "model": "claude-opus-5-5",
305 "max_tokens": 4096,
306 "messages": [
307 {
308 "role": "user",
309 "content": "Create a simple command line calculator app using Python"
310 }
311 ],
312 "tools": [
313 {
314 "type": "text_editor_20250728",
315 "name": "str_replace_based_edit_tool",
316 "max_characters": 10000
317 },
318 {
319 "type": "web_search_20250305",
320 "name": "web_search",
321 "max_uses": 3
322 }
323 ],
324 "context_management": {
325 "edits": [
326 {
327 "type": "clear_tool_uses_20250919",
328 "trigger": {
329 "type": "input_tokens",
330 "value": 30000
331 },
332 "keep": {
333 "type": "tool_uses",
334 "value": 3
335 },
336 "clear_at_least": {
337 "type": "input_tokens",
338 "value": 5000
339 },
340 "exclude_tools": ["web_search"]
341 }
342 ]
299 -H "x-api-key: $ANTHROPIC_API_KEY" \
300 -H "anthropic-version: 2023-06-01" \
301 -H "content-type: application/json" \
302 -H "anthropic-beta: context-management-2025-06-27" \
303 -d '{
304 "model": "claude-opus-5-5",
305 "max_tokens": 4096,
306 "messages": [
307 {
308 "role": "user",
309 "content": "Create a simple command line calculator app using Python"
310 }
311 ],
312 "tools": [
313 {
314 "type": "text_editor_20250728",
315 "name": "str_replace_based_edit_tool",
316 "max_characters": 10000
317 },
318 {
319 "type": "web_search_20250305",
320 "name": "web_search",
321 "max_uses": 3
322 }
323 ],
324 "context_management": {
325 "edits": [
326 {
327 "type": "clear_tool_uses_20250919",
328 "trigger": {
329 "type": "input_tokens",
330 "value": 30000
331 },
332 "keep": {
333 "type": "tool_uses",
334 "value": 3
335 },
336 "clear_at_least": {
337 "type": "input_tokens",
338 "value": 5000
339 },
340 "exclude_tools": ["web_search"]
343341 }
344 }'
342 ]
343 }
344 }'
345345 ```
346346 
347347 ```bash CLI
from line 699
699699<CodeGroup>
700700 ```bash cURL
701701 curl https://api.anthropic.com/v1/messages \
702 --header "x-api-key: $ANTHROPIC_API_KEY" \
703 --header "anthropic-version: 2023-06-01" \
704 --header "content-type: application/json" \
705 --header "anthropic-beta: context-management-2025-06-27" \
706 --data '{
707 "model": "claude-opus-5-5",
708 "max_tokens": 16000,
709 "messages": [{"role": "user", "content": "Hello"}],
710 "context_management": {
711 "edits": [
712 {
713 "type": "clear_thinking_20251015",
714 "keep": {
715 "type": "thinking_turns",
716 "value": 2
717 }
718 }
719 ]
702 -H "x-api-key: $ANTHROPIC_API_KEY" \
703 -H "anthropic-version: 2023-06-01" \
704 -H "content-type: application/json" \
705 -H "anthropic-beta: context-management-2025-06-27" \
706 -d '{
707 "model": "claude-opus-5-5",
708 "max_tokens": 16000,
709 "messages": [{"role": "user", "content": "Hello"}],
710 "context_management": {
711 "edits": [
712 {
713 "type": "clear_thinking_20251015",
714 "keep": {
715 "type": "thinking_turns",
716 "value": 2
717 }
720718 }
721 }'
719 ]
720 }
721 }'
722722 ```
723723 
724724 ```bash CLI
from line 928
928928<CodeGroup>
929929 ```bash cURL
930930 curl https://api.anthropic.com/v1/messages \
931 --header "x-api-key: $ANTHROPIC_API_KEY" \
932 --header "anthropic-version: 2023-06-01" \
933 --header "content-type: application/json" \
934 --header "anthropic-beta: context-management-2025-06-27" \
935 --data '{
936 "model": "claude-opus-5-5",
937 "max_tokens": 16000,
938 "messages": [{"role": "user", "content": "Hello"}],
939 "context_management": {
940 "edits": [
941 {
942 "type": "clear_thinking_20251015",
943 "keep": {
944 "type": "thinking_turns",
945 "value": 3
946 }
947 }
948 ]
931 -H "x-api-key: $ANTHROPIC_API_KEY" \
932 -H "anthropic-version: 2023-06-01" \
933 -H "content-type: application/json" \
934 -H "anthropic-beta: context-management-2025-06-27" \
935 -d '{
936 "model": "claude-opus-5-5",
937 "max_tokens": 16000,
938 "messages": [{"role": "user", "content": "Hello"}],
939 "context_management": {
940 "edits": [
941 {
942 "type": "clear_thinking_20251015",
943 "keep": {
944 "type": "thinking_turns",
945 "value": 3
946 }
949947 }
950 }'
948 ]
949 }
950 }'
951951 ```
952952 
953953 ```bash CLI
from line 1140
11401140<CodeGroup>
11411141 ```bash cURL
11421142 curl https://api.anthropic.com/v1/messages \
1143 --header "x-api-key: $ANTHROPIC_API_KEY" \
1144 --header "anthropic-version: 2023-06-01" \
1145 --header "content-type: application/json" \
1146 --header "anthropic-beta: context-management-2025-06-27" \
1147 --data '{
1148 "model": "claude-opus-5-5",
1149 "max_tokens": 16000,
1150 "messages": [{"role": "user", "content": "Hello"}],
1151 "context_management": {
1152 "edits": [
1153 {
1154 "type": "clear_thinking_20251015",
1155 "keep": "all"
1156 }
1157 ]
1143 -H "x-api-key: $ANTHROPIC_API_KEY" \
1144 -H "anthropic-version: 2023-06-01" \
1145 -H "content-type: application/json" \
1146 -H "anthropic-beta: context-management-2025-06-27" \
1147 -d '{
1148 "model": "claude-opus-5-5",
1149 "max_tokens": 16000,
1150 "messages": [{"role": "user", "content": "Hello"}],
1151 "context_management": {
1152 "edits": [
1153 {
1154 "type": "clear_thinking_20251015",
1155 "keep": "all"
11581156 }
1159 }'
1157 ]
1158 }
1159 }'
11601160 ```
11611161 
11621162 ```bash CLI
from line 1340
13401340<CodeGroup>
13411341 ```bash cURL
13421342 curl https://api.anthropic.com/v1/messages \
1343 --header "x-api-key: $ANTHROPIC_API_KEY" \
1344 --header "anthropic-version: 2023-06-01" \
1345 --header "content-type: application/json" \
1346 --header "anthropic-beta: context-management-2025-06-27" \
1347 --data '{
1348 "model": "claude-opus-5-5",
1349 "max_tokens": 16000,
1350 "messages": [
1351 {
1352 "role": "user",
1353 "content": "Search for the latest developments in quantum error correction and summarize the key breakthroughs."
1354 }
1355 ],
1356 "tools": [
1357 {
1358 "type": "web_search_20250305",
1359 "name": "web_search",
1360 "max_uses": 5
1361 }
1362 ],
1363 "context_management": {
1364 "edits": [
1365 {
1366 "type": "clear_thinking_20251015",
1367 "keep": {
1368 "type": "thinking_turns",
1369 "value": 2
1370 }
1371 },
1372 {
1373 "type": "clear_tool_uses_20250919",
1374 "trigger": {
1375 "type": "input_tokens",
1376 "value": 50000
1377 },
1378 "keep": {
1379 "type": "tool_uses",
1380 "value": 5
1381 }
1382 }
1383 ]
1343 -H "x-api-key: $ANTHROPIC_API_KEY" \
1344 -H "anthropic-version: 2023-06-01" \
1345 -H "content-type: application/json" \
1346 -H "anthropic-beta: context-management-2025-06-27" \
1347 -d '{
1348 "model": "claude-opus-5-5",
1349 "max_tokens": 16000,
1350 "messages": [
1351 {
1352 "role": "user",
1353 "content": "Search for the latest developments in quantum error correction and summarize the key breakthroughs."
1354 }
1355 ],
1356 "tools": [
1357 {
1358 "type": "web_search_20250305",
1359 "name": "web_search",
1360 "max_uses": 5
1361 }
1362 ],
1363 "context_management": {
1364 "edits": [
1365 {
1366 "type": "clear_thinking_20251015",
1367 "keep": {
1368 "type": "thinking_turns",
1369 "value": 2
1370 }
1371 },
1372 {
1373 "type": "clear_tool_uses_20250919",
1374 "trigger": {
1375 "type": "input_tokens",
1376 "value": 50000
1377 },
1378 "keep": {
1379 "type": "tool_uses",
1380 "value": 5
1381 }
13841382 }
1385 }'
1383 ]
1384 }
1385 }'
13861386 ```
13871387 
13881388 ```bash CLI
from line 1413
14131413 ```
14141414 
14151415 ```python Python
1416 client = anthropic.Anthropic()
1417 
14161418 response = client.beta.messages.create(
14171419 model="claude-opus-5-5",
14181420 max_tokens=16000,
from line 1725
17231725 
17241726| Configuration option | Default | Description |
17251727| -------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1726| `trigger` | 100,000 input tokens | Defines when the context editing strategy activates. Once the prompt exceeds this threshold, clearing begins. You can specify this value in either `input_tokens` or `tool_uses`. |
1728| `trigger` | 100,000 input tokens | Defines when the context editing strategy activates. Once the prompt exceeds this threshold, clearing starts. You can specify this value in either `input_tokens` or `tool_uses`. |
17271729| `keep` | 3 tool uses | Defines how many recent tool use/result pairs to keep after clearing occurs. The API removes the oldest tool interactions first, preserving the most recent ones. |
17281730| `clear_at_least` | None | Ensures a minimum number of tokens is cleared each time the strategy activates. If the API can't clear at least the specified amount, the strategy will not be applied. This helps determine if context clearing is worth breaking your prompt cache. |
17291731| `exclude_tools` | None | List of tool names whose tool uses and results should never be cleared. Useful for preserving important context. |
from line 1792
17901792<CodeGroup>
17911793 ```bash cURL
17921794 curl https://api.anthropic.com/v1/messages/count_tokens \
1793 --header "x-api-key: $ANTHROPIC_API_KEY" \
1794 --header "anthropic-version: 2023-06-01" \
1795 --header "content-type: application/json" \
1796 --header "anthropic-beta: context-management-2025-06-27" \
1797 --data '{
1798 "model": "claude-opus-5-5",
1799 "messages": [
1800 {
1801 "role": "user",
1802 "content": "Continue our conversation..."
1803 }
1804 ],
1805 "context_management": {
1806 "edits": [
1807 {
1808 "type": "clear_tool_uses_20250919",
1809 "trigger": {
1810 "type": "input_tokens",
1811 "value": 30000
1812 },
1813 "keep": {
1814 "type": "tool_uses",
1815 "value": 5
1816 }
1817 }
1818 ]
1795 -H "x-api-key: $ANTHROPIC_API_KEY" \
1796 -H "anthropic-version: 2023-06-01" \
1797 -H "content-type: application/json" \
1798 -H "anthropic-beta: context-management-2025-06-27" \
1799 -d '{
1800 "model": "claude-opus-5-5",
1801 "messages": [
1802 {
1803 "role": "user",
1804 "content": "Continue our conversation..."
1805 }
1806 ],
1807 "context_management": {
1808 "edits": [
1809 {
1810 "type": "clear_tool_uses_20250919",
1811 "trigger": {
1812 "type": "input_tokens",
1813 "value": 30000
1814 },
1815 "keep": {
1816 "type": "tool_uses",
1817 "value": 5
1818 }
18191819 }
1820 }'
1820 ]
1821 }
1822 }'
18211823 ```
18221824 
18231825 ```bash CLI
from line 2083
20812083 
20822084## Using with the memory tool
20832085 
2084Context editing can be combined with the [memory tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool). When your conversation context approaches the configured clearing threshold, Claude receives an automatic warning to preserve important information. This enables Claude to save tool results or context to its memory files before they're cleared from the conversation history.
2086Context editing can be combined with the [memory tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool). When your conversation context approaches the configured clearing threshold, Claude receives an automatic warning to preserve important information. This allows Claude to save tool results or context to its memory files before they're cleared from the conversation history.
20852087 
20862088This combination allows you to:
20872089 
2088* **Preserve important context:** Claude can write essential information from tool results to memory files before those results are cleared
2089* **Maintain long-running workflows:** Enable agentic workflows that would otherwise exceed context limits by offloading information to persistent storage
2090* **Access information on demand:** Claude can look up previously cleared information from memory files when needed, rather than keeping everything in the active context window
2090* **Preserve important context:** Claude can write essential information from tool results to memory files before those results are cleared.
2091* **Maintain long-running workflows:** Claude can continue agentic workflows that would otherwise exceed context limits by offloading information to persistent storage.
2092* **Access information on demand:** Claude can look up previously cleared information from memory files when needed, rather than keeping everything in the active context window.
20912093 
20922094For example, in a file editing workflow where Claude performs many operations, Claude can summarize completed changes to memory files as the context grows. When tool results are cleared, Claude retains access to that information through its memory system and can continue working effectively.
20932095 
from line 2098
20962098<CodeGroup>
20972099 ```bash cURL
20982100 curl https://api.anthropic.com/v1/messages \
2099 --header "x-api-key: $ANTHROPIC_API_KEY" \
2100 --header "anthropic-version: 2023-06-01" \
2101 --header "content-type: application/json" \
2102 --header "anthropic-beta: context-management-2025-06-27" \
2103 --data '{
2104 "model": "claude-opus-5-5",
2105 "max_tokens": 4096,
2106 "messages": [
2107 {
2108 "role": "user",
2109 "content": "Hello"
2110 }
2111 ],
2112 "tools": [
2113 {
2114 "type": "memory_20250818",
2115 "name": "memory"
2116 }
2117 ],
2118 "context_management": {
2119 "edits": [
2120 {"type": "clear_tool_uses_20250919"}
2121 ]
2122 }
2123 }'
2101 -H "x-api-key: $ANTHROPIC_API_KEY" \
2102 -H "anthropic-version: 2023-06-01" \
2103 -H "content-type: application/json" \
2104 -H "anthropic-beta: context-management-2025-06-27" \
2105 -d '{
2106 "model": "claude-opus-5-5",
2107 "max_tokens": 4096,
2108 "messages": [
2109 {
2110 "role": "user",
2111 "content": "Hello"
2112 }
2113 ],
2114 "tools": [
2115 {
2116 "type": "memory_20250818",
2117 "name": "memory"
2118 }
2119 ],
2120 "context_management": {
2121 "edits": [
2122 {"type": "clear_tool_uses_20250919"}
2123 ]
2124 }
2125 }'
21242126 ```
21252127 
21262128 ```bash CLI
from line 2308
23062308<Warning>
23072309 **Anthropic recommends server-side compaction over SDK compaction.** [Server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) handles context management automatically with less integration complexity, better token usage calculation, and no client-side limitations. Use SDK compaction only if you specifically need client-side control over the summarization process.
23082310 
2309 The `compaction_control` parameter is deprecated in the TypeScript and Ruby SDKs and will be removed in a future version. The SDKs emit a deprecation warning when it is enabled. The Python SDK removed it in v1.0. To use server-side compaction with a tool runner, pass the `compact_20260112` edit in the request's `context_management` parameter.
2311 The `compaction_control` parameter is deprecated in the TypeScript and Ruby SDKs and will be removed in a future version. The TypeScript and Ruby SDKs emit a deprecation warning when it is enabled. The Python SDK removed it in v1.0. To use server-side compaction with a tool runner, pass the `compact_20260112` edit in the request's `context_management` parameter.
23102312</Warning>
23112313 
23122314<Note>
from line 2324
232223241. **Threshold check:** The SDK calculates total tokens as `input_tokens + cache_creation_input_tokens + cache_read_input_tokens + output_tokens` (see [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for the cache token fields).
232323252. **Summary generation:** When the threshold is exceeded, a summary prompt is injected as a user turn, and Claude generates a structured summary wrapped in `<summary></summary>` tags.
232423263. **Context replacement:** The SDK extracts the summary and replaces the entire message history with it.
23254. **Continuation:** The conversation resumes from the summary, with Claude picking up where it left off.
23274. **Continuation:** The conversation resumes from the summary, with Claude continuing from where it stopped.
23262328 
23272329### Using compaction
23282330 
from line 2345
23432345 
23442346 <Tab title="Python">
23452347 <Note>
2346 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2348 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23472349 </Note>
23482350 </Tab>
23492351 
from line 2369
23672369 
23682370 <Tab title="C#">
23692371 <Note>
2370 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2372 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23712373 </Note>
23722374 </Tab>
23732375 
23742376 <Tab title="Go">
23752377 <Note>
2376 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2378 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23772379 </Note>
23782380 </Tab>
23792381 
23802382 <Tab title="Java">
23812383 <Note>
2382 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2384 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23832385 </Note>
23842386 </Tab>
23852387 
23862388 <Tab title="PHP">
23872389 <Note>
2388 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2390 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23892391 </Note>
23902392 </Tab>
23912393 
from line 2477
24752477 
24762478 <Tab title="Python">
24772479 <Note>
2478 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2480 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
24792481 </Note>
24802482 </Tab>
24812483 
from line 2502
25002502 
25012503 <Tab title="C#">
25022504 <Note>
2503 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2505 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25042506 </Note>
25052507 </Tab>
25062508 
25072509 <Tab title="Go">
25082510 <Note>
2509 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2511 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25102512 </Note>
25112513 </Tab>
25122514 
25132515 <Tab title="Java">
25142516 <Note>
2515 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2517 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25162518 </Note>
25172519 </Tab>
25182520 
25192521 <Tab title="PHP">
25202522 <Note>
2521 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2523 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25222524 </Note>
25232525 </Tab>
25242526 
from line 2563
25612563 
25622564 <Tab title="Python">
25632565 <Note>
2564 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2566 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25652567 </Note>
25662568 </Tab>
25672569 
from line 2591
25892591 
25902592 <Tab title="C#">
25912593 <Note>
2592 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2594 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25932595 </Note>
25942596 </Tab>
25952597 
25962598 <Tab title="Go">
25972599 <Note>
2598 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2600 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25992601 </Note>
26002602 </Tab>
26012603 
26022604 <Tab title="Java">
26032605 <Note>
2604 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2606 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26052607 </Note>
26062608 </Tab>
26072609 
26082610 <Tab title="PHP">
26092611 <Note>
2610 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2612 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26112613 </Note>
26122614 </Tab>
26132615 
from line 2655
26532655 
26542656 <Tab title="Python">
26552657 <Note>
2656 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2658 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26572659 </Note>
26582660 </Tab>
26592661 
from line 2688
26862688 
26872689 <Tab title="C#">
26882690 <Note>
2689 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2691 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26902692 </Note>
26912693 </Tab>
26922694 
26932695 <Tab title="Go">
26942696 <Note>
2695 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2697 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26962698 </Note>
26972699 </Tab>
26982700 
26992701 <Tab title="Java">
27002702 <Note>
2701 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2703 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
27022704 </Note>
27032705 </Tab>
27042706 
27052707 <Tab title="PHP">
27062708 <Note>
2707 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2709 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
27082710 </Note>
27092711 </Tab>
27102712 
from line 2750
274827504. **Next Steps:** Specific actions needed, blockers, and priority order.
274927515. **Context to Preserve:** User preferences, domain-specific details, and commitments made.
27502752 
2751This structure enables Claude to resume work efficiently without losing important context or repeating mistakes.
2753This structure allows Claude to resume work efficiently without losing important context or repeating mistakes.
27522754 
27532755<Accordion title="View full default prompt">
27542756 ```text wrap
from line 2795
27932795 Compaction requires special consideration when using server-side tools such as [web search](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool) or [web fetch](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool).
27942796</Warning>
27952797 
2796When using server-side tools, the SDK may incorrectly calculate token usage, causing compaction to trigger at the wrong time.
2798When using server-side tools, the SDK might incorrectly calculate token usage, causing compaction to trigger at the wrong time.
27972799 
27982800For example, after a web search operation, the API response might show:
27992801 
from line 2810
28082810}
28092811```
28102812 
2811The SDK calculates total usage as 63,000 + 0 + 270,000 + 1,400 = 334,400 tokens. However, the `cache_read_input_tokens` value includes accumulated reads from multiple internal API calls made by the server-side tool, not your actual conversation context. Your real context length might only be the 63,000 `input_tokens`, but the SDK sees 334k and triggers compaction prematurely.
2813The SDK calculates total usage as 63,000 + 0 + 270,000 + 1,400 = 334,400 tokens. However, the `cache_read_input_tokens` value includes accumulated reads from multiple internal API calls made by the server-side tool, not your actual conversation context. Your real context length might only be the 63,000 `input_tokens`, but the SDK calculates 334k and triggers compaction prematurely.
28122814 
28132815**Workarounds:**
28142816 
2815* Use the [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) endpoint to get accurate context length
2816* Avoid compaction when using server-side tools extensively
2817* Use the [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) endpoint to get accurate context length.
2818* Avoid compaction when using server-side tools extensively.
28172819 
28182820#### Tool use edge cases
28192821 
28202822 

build-with-claude/effort Changed · +9 / -9 lines

from line 199
199199 client = Anthropic::Client.new
200200 
201201 message = client.messages.create(
202 model: "claude-opus-5-5",
202 model: Anthropic::Model::CLAUDE_OPUS_5_5,
203203 max_tokens: 4096,
204204 messages: [
205205 { role: "user", content: "Analyze the trade-offs between microservices and monolithic architectures" }
from line 229
229229* Tool calls and function arguments
230230* Thinking (when active)
231231 
232Because effort applies to every output token, it works whether or not thinking is enabled. Lower effort also means fewer and terser tool calls.
232Because effort applies to every output token, it works with or without thinking. Lower effort also means fewer and terser tool calls.
233233 
234234### Effort levels
235235 
from line 301
301301| `xhigh` | The recommended starting point for coding and agentic work, and for exploratory tasks such as repeated tool calling, detailed web search, and knowledge-base search. Expect meaningfully higher token usage than `high`. |
302302| `max` | Reserve for frontier problems. On most workloads `max` adds significant cost for relatively small quality gains, and on some structured-output or less intelligence-sensitive tasks it can lead to overthinking. |
303303 
304Claude Opus 4.7 also respects effort levels more strictly than Claude Opus 4.6, especially at `low` and `medium`. At lower effort levels, the model scopes its work to what was asked rather than doing more than requested. If you observe shallow reasoning on complex problems with Claude Opus 4.7, raise effort rather than prompting around it. If you must keep effort low for latency, add targeted guidance like "This task involves multistep reasoning. Think carefully before responding."
304Claude Opus 4.7 also respects effort levels more strictly than Claude Opus 4.6, especially at `low` and `medium`. At lower effort levels, the model scopes its work to what was asked rather than doing more than requested. If you observe shallow reasoning on complex problems with Claude Opus 4.7, raise effort rather than prompting around it. If you must keep effort low for latency, add targeted guidance such as "This task involves multistep reasoning. Think carefully before responding."
305305 
306306When running Claude Opus 4.7 at `xhigh` or `max` effort, set a large `max_tokens` so the model has room to think and act across subagents and tool calls. Starting at 64k tokens and tuning from there is a reasonable default.
307307 
from line 311
311311 
312312To turn off up-front thinking, send `thinking: {"type": "between_tools"}` instead of `"disabled"`. It's the lowest thinking setting on Claude Sonnet 5.5, and it works at `low`, `medium`, and `high` effort. At `xhigh` or `max`, a request with it returns a 400 error, so use adaptive thinking at those levels: omit the `thinking` field or send `thinking: {"type": "adaptive"}`. See [Running without up-front thinking](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#running-without-up-front-thinking).
313313 
314Claude Sonnet 5.5 also supports [changing effort mid-conversation](https://platform.claude.com/docs/en/build-with-claude/effort#change-effort-mid-conversation-beta) with a per-message `output_config`, which preserves the prompt cache. 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. To vary effort per turn, use adaptive thinking. See [Prompting Claude Sonnet 5.5](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#calibrate-effort).
314Claude Sonnet 5.5 also supports [changing effort mid-conversation](https://platform.claude.com/docs/en/build-with-claude/effort#change-effort-mid-conversation-beta) with a per-message `output_config`, which preserves the prompt cache. 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. To vary effort for each turn, use adaptive thinking. See [Prompting Claude Sonnet 5.5](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#calibrate-effort).
315315 
316316### Recommended effort levels for Claude Sonnet 5
317317 
from line 327
327327 
328328Sonnet 4.6 defaults to `high` effort. Explicitly set effort when using Sonnet 4.6 to avoid unexpected latency:
329329 
330* **Medium effort** (recommended default): Best balance of speed, cost, and performance for most applications. Suitable for agentic coding, tool-heavy workflows, and code generation.
330* **Medium effort (recommended default):** Best balance of speed, cost, and performance for most applications. Suitable for agentic coding, tool-heavy workflows, and code generation.
331331* **Low effort:** For high-volume or latency-sensitive workloads. Suitable for chat and non-coding use cases where faster turnaround is prioritized.
332332* **High effort:** For complex reasoning and tasks where quality matters more than speed or cost.
333333* **Max effort:** For tasks requiring the absolute highest capability with no constraints on token spending.
from line 349
349349* Proceed directly to action without preamble
350350* Use terse confirmation messages after completion
351351 
352Higher effort levels may:
352Higher effort levels might:
353353 
354354* Make more tool calls
355355* Explain the plan before taking action
from line 374
374374 
375375Per-message effort is in beta. On the Claude API and [Google Cloud](https://platform.claude.com/docs/en/build-with-claude/claude-on-vertex-ai), it's available on Claude Fable 5.1, Claude Mythos 5.1, Claude Opus 5.5, Claude Opus 5, Claude Sonnet 5.5, and Claude Haiku 5.5. On [Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock), it's available on Claude Fable 5.1, Claude Mythos 5.1, and Claude Opus 5.5. It requires the [beta header](https://platform.claude.com/docs/en/api/beta-headers) `mid-conversation-output-config-2026-07-01`. With the Amazon Bedrock [InvokeModel API](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy), it's available on Claude Fable 5.1 and Claude Opus 5.5, and you send that value in the `anthropic_beta` array of the request body instead.
376376 
377Without the beta value, a per-message `output_config` returns a 400 error: `messages.N.output_config: Extra inputs are not permitted`, where `N` is the index of the `system` message in `messages`. With the beta value, models without per-message effort, including Claude Fable 5, return a 400 error: `output_config.effort requires a model that supports per-turn effort; this model does not`. On Amazon Bedrock, those models and Claude Opus 5 return the `Extra inputs are not permitted` error instead. On Claude Sonnet 5.5 with `thinking: {"type": "between_tools"}` and on Claude Haiku 5.5 with `thinking: {"type": "disabled"}`, effort can't change mid-conversation: a per-message `output_config.effort` that differs from the level in effect returns a 400 error. To vary effort per turn, use adaptive thinking.
377Without the beta value, a per-message `output_config` returns a 400 error: `messages.N.output_config: Extra inputs are not permitted`, where `N` is the index of the `system` message in `messages`. With the beta value, models without per-message effort, including Claude Fable 5, return a 400 error: `output_config.effort requires a model that supports per-turn effort; this model does not`. On Amazon Bedrock, those models and Claude Opus 5 return the `Extra inputs are not permitted` error instead. On Claude Sonnet 5.5 with `thinking: {"type": "between_tools"}` and on Claude Haiku 5.5 with `thinking: {"type": "disabled"}`, effort can't change mid-conversation: a per-message `output_config.effort` that differs from the level in effect returns a 400 error. To vary effort for each turn, use adaptive thinking.
378378 
379379Add a `role: "system"` message with empty `content` and the new level in `output_config.effort`. Placed directly after a `user` turn with new input, it sets the level for Claude's reply to that turn. Placed anywhere else, such as between an `assistant` turn and the next `user` turn as in the following example, it takes effect from the next `user` turn with new input. A `user` turn that holds only `tool_result` blocks doesn't count as new input, so a change placed after one in a tool-use loop waits for the next `user` turn with new input. The new level then holds until a later message changes it. Everything before that message is unchanged, so the cached prefix still matches.
380380 
from line 627
627627 client = Anthropic::Client.new
628628 
629629 response = client.beta.messages.create(
630 model: "claude-fable-5-1",
630 model: Anthropic::Model::CLAUDE_FABLE_5_1,
631631 max_tokens: 4096,
632632 output_config: {effort: :high},
633633 messages: [
from line 659
6596591. **Set effort explicitly:** The API defaults to `high` (`medium` on Claude Opus 5.5 and Claude Haiku 5.5), but the right starting point depends on your model and workload.
6606602. **Use low for speed-sensitive or simple tasks:** When latency matters or tasks are straightforward, low effort can significantly reduce response times and costs.
6616613. **Test your use case:** The impact of effort levels varies by task type. Evaluate performance on your specific use cases before deploying.
6624. **Consider dynamic effort:** Adjust effort based on task complexity. Simple queries may warrant low effort while agentic coding and complex reasoning benefit from high effort. See the next item before varying it within one conversation.
6624. **Consider dynamic effort:** Adjust effort based on task complexity. Simple queries might warrant low effort, whereas agentic coding and complex reasoning benefit from high effort. See the next item before varying it within one conversation.
6636635. **Hold top-level effort constant within cached conversations:** Changing the top-level effort value between requests invalidates [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching), so vary it across workloads rather than within a conversation that relies on cache hits. On models that support it, use a [per-message effort change](https://platform.claude.com/docs/en/build-with-claude/effort#change-effort-mid-conversation-beta) instead, which preserves the cache. See [Thinking and prompt caching](https://platform.claude.com/docs/en/build-with-claude/thinking#thinking-and-prompt-caching).
664664 
665665## Next steps

build-with-claude/embeddings Changed · +8 / -8 lines

from line 1
11---
22title: Embeddings
33url: https://platform.claude.com/docs/en/build-with-claude/embeddings
4description: Text embeddings are numerical representations of text that enable measuring semantic similarity. This guide introduces embeddings, their applications, and how to use embedding models for tasks like search, recommendations, and anomaly detection.
4description: Text embeddings are numerical representations of text that let you measure semantic similarity. This guide introduces embeddings, their applications, and how to use embedding models for tasks such as search, recommendations, and anomaly detection.
55---
66 
77## Before implementing embeddings
from line 8
88 
99When selecting an embeddings provider, there are several factors you can consider depending on your needs and preferences:
1010 
11* Dataset size & domain specificity: size of the model training dataset and its relevance to the domain you want to embed. Larger or more domain-specific data generally produces better in-domain embeddings
12* Inference performance: embedding lookup speed and end-to-end latency. This is a particularly important consideration for large scale production deployments
11* Dataset size and domain specificity: size of the model training dataset and its relevance to the domain you want to embed. Larger or more domain-specific data generally produces better in-domain embeddings
12* Inference performance: embedding lookup speed and end-to-end latency. This is a particularly important consideration for large-scale production deployments
1313* Customization: options for continued training on private data, or specialization of models for very specific domains. This can improve performance on unique vocabularies
1414 
1515## How to get embeddings with Anthropic
from line 140
140140 }'
141141```
142142 
143The response you would get is a JSON object containing the embeddings and the token usage:
143The response is a JSON object containing the embeddings and the token usage:
144144 
145145```json
146146{
from line 176
176176 
177177The following brief example shows how to use embeddings.
178178 
179Suppose you have a small corpus of six documents to retrieve from
179Suppose you have a small corpus of six documents to retrieve from:
180180 
181181```python
182182documents = [
from line 200
200200doc_embds = vo.embed(documents, model="voyage-4", input_type="document").embeddings
201201```
202202 
203The embeddings allow you to do semantic search / retrieval in the vector space. Given an example query,
203The embeddings allow you to do semantic search / retrieval in the vector space. Consider the following example query:
204204 
205205```python
206206query = "When is Apple's conference call scheduled?"
from line 231
231231Apple's conference call to discuss fourth fiscal quarter results and business updates is scheduled for Thursday, November 2, 2023 at 2:00 p.m. PT / 5:00 p.m. ET.
232232```
233233 
234If you are looking for a detailed set of recipes on how to do RAG with embeddings, including vector databases, check out the [RAG recipe](https://platform.claude.com/cookbook/third-party-pinecone-rag-using-pinecone).
234If you are looking for a detailed set of recipes on how to do RAG with embeddings, including vector databases, see the [RAG recipe](https://platform.claude.com/cookbook/third-party-pinecone-rag-using-pinecone).
235235 
236236## FAQ
237237 
from line 272
272272 
273273 Voyage AI embeddings are normalized to length 1, which means that:
274274 
275 * Cosine similarity is equivalent to dot-product similarity, while the latter can be computed more quickly.
275 * Cosine similarity is equivalent to dot-product similarity, although the latter can be computed more quickly.
276276 * Cosine similarity and Euclidean distance result in identical rankings.
277277 </Accordion>
278278 

build-with-claude/extended-thinking Changed · +9 / -9 lines

from line 24
2424 
2525## Supported models
2626 
27Extended thinking availability per model, including the models where extended thinking is the only mode, is listed in the [per-model configuration table](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models).
27Extended thinking availability for each model, including the models where extended thinking is the only mode, is listed in the [per-model configuration table](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models).
2828 
2929## How to use extended thinking
3030 
from line 264
264264 
265265To turn on manual extended thinking, add a `thinking` object with `type` set to `enabled` and a `budget_tokens` value.
266266 
267The `budget_tokens` parameter sets a target for how many tokens Claude can use for its internal reasoning process. Larger budgets can improve response quality by enabling more thorough analysis for complex problems.
267The `budget_tokens` parameter sets a target for how many tokens Claude can use for its internal reasoning process. Larger budgets can improve response quality by allowing more thorough analysis for complex problems.
268268 
269269## Budget rules and tuning
270270 
from line 271
271271`budget_tokens` must satisfy these constraints:
272272 
273273* **Minimum of 1,024 tokens.** The API rejects smaller values.
274* **Less than `max_tokens`.** Thinking tokens count toward the `max_tokens` limit for the turn, so the budget must leave room for the final response. The one exception is [interleaved thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking), where `budget_tokens` can exceed `max_tokens` because the budget spans all thinking blocks within one assistant turn.
274* **Less than `max_tokens`.** Thinking tokens count toward the `max_tokens` limit for the turn, so the budget must leave room for the final response. The one exception is [interleaved thinking in manual mode](https://platform.claude.com/docs/en/build-with-claude/extended-thinking#interleaved-thinking), where `budget_tokens` can exceed `max_tokens` because the budget spans all thinking blocks within one assistant turn.
275275* **No cache pre-warming.** Because `budget_tokens` must be less than `max_tokens`, extended thinking cannot be combined with `max_tokens: 0` ([cache pre-warming](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pre-warming-the-cache)).
276276 
277The budget is a target rather than a strict cap. Actual token usage varies with the task, and Claude may stop reasoning well before the budget is exhausted; `max_tokens` remains the hard ceiling on total output.
277The budget is a target rather than a strict cap. Actual token usage varies with the task, and Claude might stop reasoning well before the budget is exhausted; `max_tokens` remains the hard ceiling on total output.
278278 
279On Claude Opus 4.5, the only extended-thinking-only model that supports [effort](https://platform.claude.com/docs/en/build-with-claude/effort), effort shapes the overall response while `budget_tokens` sets thinking depth; set both.
279On Claude Opus 4.5, the only extended-thinking-only model that supports [effort](https://platform.claude.com/docs/en/build-with-claude/effort), effort shapes the overall response whereas `budget_tokens` sets thinking depth; set both.
280280 
281281To tune the budget:
282282 
283* Match the starting point to the task. For simple tasks, start near the 1,024-token minimum and increase incrementally to find the optimal range for your use case. For complex tasks, start with a larger budget of 16,000 tokens or more and adjust to your latency and quality needs. Higher budgets enable more comprehensive reasoning, with diminishing returns that depend on the task, and at the cost of increased latency. For critical tasks, test different settings to find the right balance.
283* Match the starting point to the task. For simple tasks, start near the 1,024-token minimum and increase incrementally to find the optimal range for your use case. For complex tasks, start with a larger budget of 16,000 tokens or more and adjust to your latency and quality needs. Higher budgets allow more comprehensive reasoning, with diminishing returns that depend on the task, and at the cost of increased latency. For critical tasks, test different settings to find the right balance.
284284* For thinking budgets above 32k, use [batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing) to avoid networking issues. Pushing the model to think beyond 32k tokens produces long-running requests that can hit system timeouts and open-connection limits.
285285 
286286To track what a budget actually costs you, monitor the `usage.output_tokens_details.thinking_tokens` field in the response, which reports how many of the billed output tokens were internal reasoning. When streaming, this breakdown appears only on the final `message_delta` event.
from line 313
313313 
314314The general turn-structure rules, including the single-turn tool-use loop, mid-turn conflict handling, and toggling thinking between turns, are on [Thinking with tool use](https://platform.claude.com/docs/en/build-with-claude/thinking#thinking-with-tool-use).
315315 
316Manual mode adds one requirement: the final assistant turn of a thinking-enabled request must begin with a thinking block ([adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking) drops that requirement). Changing the thinking configuration between turns also invalidates prompt caching; see the following section.
316Manual mode adds one requirement: the final assistant turn of a thinking-enabled request must start with a thinking block ([adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking) drops that requirement). Changing the thinking configuration between turns also invalidates prompt caching; see the following section.
317317 
318318## Prompt caching in manual mode
319319 
from line 385
385385 
386386`effort: "high"` is the default on Claude Sonnet 4.6, so omitting it here produces identical behavior; it appears only to show where the depth control lives in adaptive mode. Claude Opus 5.5 and Claude Haiku 5.5 default to `"medium"`, and other models that support effort default to `"high"` (see [Effort levels](https://platform.claude.com/docs/en/build-with-claude/effort#effort-levels)).
387387 
388Expect a behavioral difference, not just a syntax change. With a fixed budget, Claude thinks on every request. With adaptive thinking, Claude determines whether and how much to think on each request, and at lower [effort](https://platform.claude.com/docs/en/build-with-claude/effort) settings it may skip thinking entirely on easy inputs. You can also remove the `interleaved-thinking-2025-05-14` beta header after migrating: adaptive thinking interleaves automatically, and the Claude API ignores the header on these models. Thinking block preservation changes too: Claude Opus 4.5 and models numbered 4.6 and higher keep prior turns' thinking blocks in context and bill them as input, where Claude Sonnet 4.5 (deprecated), Claude Haiku 4.5, and earlier models stripped them; see [thinking block preservation by model](https://platform.claude.com/docs/en/build-with-claude/thinking#thinking-block-preservation-by-model).
388Expect a behavioral difference, not just a syntax change. With a fixed budget, Claude thinks on every request. With adaptive thinking, Claude determines whether and how much to think on each request, and at lower [effort](https://platform.claude.com/docs/en/build-with-claude/effort) settings it might skip thinking entirely on easy inputs. You can also remove the `interleaved-thinking-2025-05-14` beta header after migrating: adaptive thinking interleaves automatically, and the Claude API ignores the header on these models. Thinking block preservation changes too: Claude Opus 4.5 and models numbered 4.6 and higher keep prior turns' thinking blocks in context and bill them as input, where Claude Sonnet 4.5 (deprecated), Claude Haiku 4.5, and earlier models strip them; see [thinking block preservation by model](https://platform.claude.com/docs/en/build-with-claude/thinking#thinking-block-preservation-by-model).
389389 
390390Switching modes is a thinking-configuration change, so the first request after the switch invalidates cache breakpoints, as described in [Prompt caching in manual mode](https://platform.claude.com/docs/en/build-with-claude/extended-thinking#extended-thinking-with-prompt-caching).
391391 

build-with-claude/fallback-credit Changed · +18 / -18 lines

from line 4
44description: Avoid paying the prompt-cache cost twice when you retry a refused request on another model.
55---
66 
7Prompt caches are per-model. When a model declines a request and you retry on another model, the conversation prefix already cached for the first model must be written into the new model's cache from scratch. Cache writes cost more than cache reads. Fallback credit removes that extra cost. The refusal carries a credit token, you echo the token on the retry, and the retry is billed as though the conversation had been on the new model all along.
7Prompt caches are per-model. When a model declines a request and you retry on another model, the conversation prefix already cached for the first model must be written into the new model's cache in full. Cache writes cost more than cache reads. Fallback credit removes that extra cost. The refusal carries a credit token, you echo the token on the retry, and the retry is billed as though the conversation had been on the new model from the start.
88 
99You need this page only when you build the retry yourself: over raw HTTP or with custom retry logic. [Server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback) and the [SDK middleware](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#client-side-fallback) apply fallback credit automatically. If you use either, skip this page.
1010 
from line 20
2020 <Step title="Read two fields from the refusal">
2121 On a refusal, `stop_details` includes two fields:
2222 
23 * **`fallback_credit_token`:** an opaque string that represents the credit.
24 * **`fallback_has_prefill_claim`:** a Boolean that tells you which retry body shape to use.
23 * **`fallback_credit_token`:** an opaque string that represents the credit
24 * **`fallback_has_prefill_claim`:** a Boolean that tells you which retry body shape to use
2525 
2626 Both are `null` when no credit is available for the refusal.
2727 </Step>
from line 37
3737 
3838The `fallback_has_prefill_claim` field tells you whether the retry can continue the refused model's partial output instead of starting over:
3939 
40| `fallback_has_prefill_claim` | Retry body |
41| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
42| `true` | The refused request body, unchanged, plus one appended assistant message whose `content` echoes the refused response's `content`. The retry model continues the response from where the refused model stopped, and completed server tool calls are not re-executed. |
43| `false` | The refused request body, unchanged. |
40| `fallback_has_prefill_claim` | Retry body |
41| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
42| `true` | The refused request body, unchanged, plus one appended assistant message whose `content` echoes the refused response's `content`. The retry model continues the response from where the refused model stopped, and completed server tool calls are not run again. |
43| `false` | The refused request body, unchanged. |
4444 
4545## Example
4646 
47The following example makes a request that may be refused and redeems the credit token on a retry against Claude Opus 4.8. When a retry attempt is rejected, the example degrades through the rejection ladder: the sequence of progressively simpler retry shapes covered in [When a retry is rejected](https://platform.claude.com/docs/en/build-with-claude/fallback-credit#when-a-retry-is-rejected).
47The following example makes a request that might be refused and redeems the credit token on a retry against Claude Opus 4.8. When a retry attempt is rejected, the example degrades through the rejection ladder: the sequence of progressively simpler retry shapes covered in [When a retry is rejected](https://platform.claude.com/docs/en/build-with-claude/fallback-credit#when-a-retry-is-rejected).
4848 
4949<CodeGroup exclude="shell:cURL, shell:CLI">
5050 <CodeGroupItem language="cURL">
from line 462
462462 client.beta.messages.create(model:, betas: ["fallback-credit-2026-07-01"], **body)
463463 end
464464 
465 response = send_message.call("claude-fable-5", request)
465 response = send_message.call(Anthropic::Model::CLAUDE_FABLE_5, request)
466466 
467467 if response in {stop_reason: :refusal,
468468 stop_details: {fallback_credit_token: String => credit_token} => details}
from line 482
482482 end
483483 
484484 begin
485 response = send_message.call("claude-opus-4-8", attempt)
485 response = send_message.call(Anthropic::Model::CLAUDE_OPUS_4_8, attempt)
486486 rescue Anthropic::Errors::BadRequestError => error
487487 # Transient: retry with the token within its five-minute window
488488 raise if error.message.include?("redemption temporarily unavailable")
489489 begin
490490 # Fall back to the unchanged body, still with the token
491 response = send_message.call("claude-opus-4-8", exact_body)
491 response = send_message.call(Anthropic::Model::CLAUDE_OPUS_4_8, exact_body)
492492 rescue Anthropic::Errors::BadRequestError => error
493493 # Transient: retry with the token within its five-minute window
494494 raise if error.message.include?("redemption temporarily unavailable")
495495 # The token itself was rejected: forfeit it and retry without.
496 response = send_message.call("claude-opus-4-8", request)
496 response = send_message.call(Anthropic::Model::CLAUDE_OPUS_4_8, request)
497497 end
498498 end
499499 end
from line 531
531531</Steps>
532532 
533533<Note>
534 If the refused request executed server tools, a tokenless retry re-runs and re-bills those tools. In that case, surface the 400 error to your caller instead of falling through to a tokenless retry.
534 If the refused request ran server tools, a tokenless retry re-runs and re-bills those tools. In that case, surface the 400 error to your caller instead of falling through to a tokenless retry.
535535</Note>
536536 
537537<Accordion title="If the error says 'redemption temporarily unavailable'">
538 This rejection is transient, not a verdict on your retry shape. Retry the same request, with the same token, within the token's five-minute window. Do not move to the next step of the ladder.
538 This rejection is transient, not a verdict on your retry shape. Retry the same request, with the same token, within the token's 5-minute window. Do not move to the next step of the ladder.
539539</Accordion>
540540 
541541## Reference
from line 575
575575<Accordion title="Echoing the refused response's content">
576576 When a refusal's token supports the continuation shape, the response `content` carries only the model's own output, and the refusal explanation is delivered in `stop_details.explanation`. You can therefore echo `content` into the appended assistant message as-is.
577577 
578 Two adjustments may still be needed before sending:
578 Two adjustments might still be needed before sending:
579579 
580580 * If the final block you send is a `text` block, strip its trailing whitespace.
581581 * Omit any client-side `tool_use` block that has no matching `tool_result`.
from line 586
586586<Accordion title="Token scope and lifetime">
587587 The token redeems only from the organization and workspace that received the refusal, including on Microsoft Foundry. On Amazon Bedrock and Google Cloud, which do not have workspaces, the token is bound to the platform's caller identity instead.
588588 
589 The token expires five minutes after the refusal. After that, send the retry without it. The token is also stateless: the server stores nothing about it, and there is no endpoint to inspect or revoke it.
589 The token expires 5 minutes after the refusal. After that, send the retry without it. The token is also stateless: the server stores nothing about it, and there is no endpoint to inspect or revoke it.
590590</Accordion>
591591 
592592<Accordion title="When a token cannot be redeemed by either shape">
593 When the refusal arrived after server tools had already executed within the request, the token redeems only by continuing the partial response. That restriction is what prevents the completed tool calls from running, and billing, again.
593 When the refusal arrived after server tools had already run within the request, the token redeems only by continuing the partial response. That restriction is what prevents the completed tool calls from running, and billing, again.
594594 
595595 One combination can therefore leave the token unredeemable by either shape, when both of the following are true:
596596 
597597 * The request used `output_config.format` or a `tool_choice` that forces tool use. Either one rules out the appended-assistant-message shape.
598 * The refusal arrived after server tools had executed. That rules out the unchanged body.
598 * The refusal arrived after server tools had run. That rules out the unchanged body.
599599 
600600 If the unchanged-body retry is rejected with a 400 error saying the token must be redeemed by continuing the partial response, discard the token. A retry without it goes through, but it re-runs and re-bills the completed server tools. Surface the cost or the error to your caller rather than retrying silently.
601601</Accordion>

build-with-claude/fast-mode Changed · +3 / -3 lines

from line 181
181181 client = Anthropic::Client.new
182182 
183183 response = client.messages.create(
184 model: "claude-opus-5-5",
184 model: Anthropic::Model::CLAUDE_OPUS_5_5,
185185 max_tokens: 4096,
186186 speed: "fast",
187187 messages: [{role: "user", content: "Refactor this module to use dependency injection"}]
from line 363
363363 client = Anthropic::Client.new
364364 
365365 response = client.messages.create(
366 model: "claude-opus-5-5",
366 model: Anthropic::Model::CLAUDE_OPUS_5_5,
367367 max_tokens: 1024,
368368 speed: "fast",
369369 messages: [{ role: "user", content: "Hello" }]
from line 400
400400If you'd prefer to fall back to standard speed rather than wait for fast mode capacity, catch the rate limit error and retry without `speed: "fast"`. Set `max_retries` (typescript, java, php: `maxRetries`; csharp: `MaxRetries`; go: `option.WithMaxRetries`) to `0` on the initial fast request to skip automatic retries and fail immediately on rate limit errors.
401401 
402402<Note>
403 Falling back from fast to standard speed will result in a [prompt cache](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) miss. Requests at different speeds do not share cached prefixes.
403 Falling back from fast to standard speed results in a [prompt cache](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) miss. Requests at different speeds do not share cached prefixes.
404404</Note>
405405 
406406Because setting `max_retries` (typescript, java, php: `maxRetries`; csharp: `MaxRetries`; go: `option.WithMaxRetries`) to `0` also disables retries for other transient errors (overloaded, internal server errors), the following examples reissue the original request with default retries for those cases.

build-with-claude/files Changed · +33 / -37 lines

from line 29
2929* **Manage your files** with list, retrieve, and delete operations
3030 
3131<Warning id="workspace-scoped-access">
32 **Uploaded files are accessible to your entire workspace, not scoped to an end user, conversation, or session.** Any API key with access to a workspace can access any files uploaded to that workspace. Every service account, and every user whose organization role allows API access, can use the Default Workspace in addition to any workspace you add them to, so keep files that must stay separate in their own [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces#api-keys-and-resource-scoping) and access them only with keys scoped to that workspace. Never accept `file_id` values from end users or other untrusted sources: a user-supplied file ID would let one user of your application read content that another user uploaded. Treat file IDs as server-side references, and keep the mapping between your users and their files in your application.
32 **Uploaded files are accessible to your entire workspace, not scoped to an end user, conversation, or session.** Any API key with access to a workspace can access any files uploaded to that workspace. Every service account, and every user whose organization role allows API access, can use the Default Workspace in addition to any workspace you add them to, so keep files that must stay separate in their own workspace and access them only with [keys scoped to that workspace](https://platform.claude.com/docs/en/manage-claude/workspaces#api-keys-and-resource-scoping). Never accept `file_id` values from end users or other untrusted sources: a user-supplied file ID would let one user of your application read content that another user uploaded. Treat file IDs as server-side references, and keep the mapping between your users and their files in your application.
3333 
34 If you are building a multi-tenant application on the Files API, create a separate [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces) for each tenant. The workspace is the isolation boundary for files, so a workspace per tenant gives each tenant's data hard isolation from every other tenant. Each organization can have up to 100 workspaces; contact your account team if you need more.
34 If you are building a multitenant application on the Files API, create a separate [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces) for each tenant. The workspace is the isolation boundary for files, so a workspace for each tenant gives that tenant's data hard isolation from every other tenant. Each organization can have up to 100 workspaces; contact your account team if you need more.
3535</Warning>
3636 
3737## How to use the Files API
from line 38
3838 
3939### Uploading a file
4040 
41Upload a file to be referenced in future API calls:
41Upload a file to reference in future API calls:
4242 
4343<CodeGroup>
4444 ```bash cURL
from line 375
375375 
376376The Files API supports different file types that correspond to different content block types:
377377 
378| File type | MIME type | Content block type | Use case |
379| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | ------------------ | ----------------------------------- |
380| PDF | `application/pdf` | `document` | Text analysis, document processing |
381| Plain text | `text/plain` | `document` | Text analysis, processing |
382| Images | `image/jpeg`, `image/png`, `image/gif`, `image/webp` | `image` | Image analysis, visual tasks |
383| [Datasets, others](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#upload-and-analyze-your-own-files) | Varies | `container_upload` | Analyze data, create visualizations |
378| File type | MIME type | Content block type | Use case |
379| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | ------------------ | ---------------------------------- |
380| PDF | `application/pdf` | `document` | Text analysis, document processing |
381| Plain text | `text/plain` | `document` | Text analysis, processing |
382| Images | `image/jpeg`, `image/png`, `image/gif`, `image/webp` | `image` | Image analysis, visual tasks |
383| [Datasets, others](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#upload-and-analyze-your-own-files) | Varies | `container_upload` | Data analysis, visualization |
384384 
385385#### Document blocks
386386 
from line 752
752752 ```
753753 
754754 ```bash CLI
755 ant files retrieve-metadata \
756 --file-id "$FILE_ID"
755 ant files retrieve-metadata --file-id "$FILE_ID"
757756 ```
758757 
759758 ```python Python
from line 798
799798 
800799#### Delete a file
801800 
802Remove a file from your workspace:
801Delete a file from your workspace:
803802 
804803<CodeGroup>
805804 ```bash cURL
from line 808
809808 ```
810809 
811810 ```bash CLI
812 ant files delete \
813 --file-id "$FILE_ID"
811 ant files delete --file-id "$FILE_ID"
814812 ```
815813 
816814 ```python Python
from line 852
854852 curl -X GET "https://api.anthropic.com/v1/files/$FILE_ID/content" \
855853 -H "x-api-key: $ANTHROPIC_API_KEY" \
856854 -H "anthropic-version: 2023-06-01" \
857 --output downloaded_file.txt
855 -o downloaded_file.txt
858856 ```
859857 
860858 ```bash CLI
861 ant files download \
862 --file-id "$FILE_ID" \
863 --output downloaded_file.txt
859 ant files download --file-id "$FILE_ID" --output downloaded_file.txt
864860 ```
865861 
866862 ```python Python
from line 930
934930 
935931### Storage limits
936932 
937* **Maximum file size:** 500 MB per file
938* **Total storage:** 1 TB per organization
933* **Maximum file size:** 500 MB for each file
934* **Total storage:** 1 TB for each organization
939935 
940936### File lifecycle
941937 
942* Files are scoped to the workspace they were uploaded in. Any request in the same workspace can reference them; never accept file IDs from untrusted sources (see the [workspace access warning](https://platform.claude.com/docs/en/build-with-claude/files#workspace-scoped-access))
943* Files cannot be modified or renamed after upload. To change a file's content, upload a new file and delete the old one
944* Files persist until you delete them with the `DELETE /v1/files/{file_id}` endpoint or they reach their `expires_at`
945* Deleted files cannot be recovered
946* Files are inaccessible through the API shortly after deletion, but they may persist in active Messages API calls and associated tool uses
947* Files that users delete will be deleted in accordance with Anthropic's [data retention policy](https://privacy.claude.com/en/articles/7996866-how-long-do-you-store-my-organization-s-data). For ZDR eligibility across all features, see [API and data retention](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention)
938* Files are scoped to the workspace they were uploaded in. Any request in the same workspace can reference them; never accept file IDs from untrusted sources (see the [workspace access warning](https://platform.claude.com/docs/en/build-with-claude/files#workspace-scoped-access)).
939* Files cannot be modified or renamed after upload. To change a file's content, upload a new file and delete the old one.
940* Files persist until you delete them with the `DELETE /v1/files/{file_id}` endpoint or they reach their `expires_at`.
941* Deleted files cannot be recovered.
942* Files are inaccessible through the API shortly after deletion, but they may persist in active Messages API calls and associated tool uses.
943* Files that users delete will be deleted in accordance with Anthropic's [data retention policy](https://privacy.claude.com/en/articles/7996866-how-long-do-you-store-my-organization-s-data). For ZDR eligibility across all features, see [API and data retention](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention).
948944 
949945### File expiration
950946 
from line 948
952948 
953949When a file reaches its `expires_at`:
954950 
955* Downloading its content (`GET /v1/files/{file_id}/content`) returns a 404 error
956* A Messages request that references the file fails before inference
957* Its metadata (`GET /v1/files/{file_id}`) remains readable for up to 30 days, with `expires_at` in the past
958* It continues to appear in list responses during that window; compare `expires_at` to the current time to filter expired files
951* Downloading its content (`GET /v1/files/{file_id}/content`) returns a 404 error.
952* A Messages request that references the file fails before inference.
953* Its metadata (`GET /v1/files/{file_id}`) remains readable for up to 30 days, with `expires_at` in the past.
954* It continues to appear in list responses during that window; compare `expires_at` to the current time to filter expired files.
959955 
960956Deleting an expired file with `DELETE /v1/files/{file_id}` removes its metadata immediately instead of waiting for the 30-day window to elapse.
961957 
962958<Note>
963 Expiration is a lifecycle feature, not a guaranteed-deletion control. After `expires_at`, file content is no longer retrievable through the API and is released from your storage quota; the underlying content may be retained for a limited period thereafter for safety review before permanent deletion, and file metadata remains visible for up to 30 days after expiration. To remove a file before its scheduled expiration, use `DELETE /v1/files/{file_id}`.
959 Expiration is a lifecycle feature, not a guaranteed-deletion control. After `expires_at`, file content is no longer retrievable through the API and is released from your storage quota; the underlying content may be retained for a limited period thereafter for safety review before permanent deletion, and file metadata remains visible for up to 30 days after expiration. To delete a file before its scheduled expiration, use `DELETE /v1/files/{file_id}`.
964960</Note>
965961 
966962### Audit logging
from line 976
980976 
981977To migrate:
982978 
9831. **Remove the beta header.** Drop `anthropic-beta: files-api-2025-04-14` from your requests. In the SDKs, call `client.files` instead of `client.beta.files`; keeping `client.beta.files` works only on the [SDK releases that no longer send the header](https://platform.claude.com/docs/en/build-with-claude/files#sdk-beta-namespace). Earlier releases send it from `client.beta.files` even with no `betas` argument.
9791. **Remove the beta header.** Drop `anthropic-beta: files-api-2025-04-14` from your requests. With the SDK, call `client.files` (csharp, go: `client.Files`; java: `client.files()`; php: `$client->files`) instead of `client.beta.files` (csharp, go: `client.Beta.Files`; java: `client.beta().files()`; php: `$client->beta->files`); keeping `client.beta.files` (csharp, go: `client.Beta.Files`; java: `client.beta().files()`; php: `$client->beta->files`) works only on the [SDK releases that no longer send the header](https://platform.claude.com/docs/en/build-with-claude/files#sdk-beta-namespace). Earlier releases send it from `client.beta.files` (csharp, go: `client.Beta.Files`; java: `client.beta().files()`; php: `$client->beta->files`) even when you pass no beta names.
9849802. **Update pagination.** Replace `after_id`/`before_id` loops with the `page`/`next_page` cursor, or use the SDK auto-pagination helpers shown in [Managing files](https://platform.claude.com/docs/en/build-with-claude/files#managing-files).
9859813. **Read `expires_at`.** The field appears only without the header; `null` means the file has no expiration (see [File expiration](https://platform.claude.com/docs/en/build-with-claude/files#file-expiration)).
986982 
987983### SDK beta namespace
988984 
989Starting with Python SDK 1.2.0, TypeScript SDK 0.122.0, Go SDK 1.68.0, Java SDK 2.59.0, Ruby SDK 1.67.0, and C# SDK 12.44.0, `client.beta.files` no longer sends `files-api-2025-04-14` and returns the same shapes as `client.files`, with `Beta`-prefixed type names. It accepts a `betas` argument for Files features that are still in beta, such as `scope_id` filtering under a [Managed Agents](https://platform.claude.com/docs/en/managed-agents/files) beta header. Earlier SDK releases are typed to the beta shapes; if you depend on those types, stay on an earlier release until you migrate.
985Starting with Python SDK 1.2.0, TypeScript SDK 0.122.0, Go SDK 1.68.0, Java SDK 2.59.0, PHP SDK 0.45.0, Ruby SDK 1.67.0, and C# SDK 12.44.0, `client.beta.files` (csharp, go: `client.Beta.Files`; java: `client.beta().files()`; php: `$client->beta->files`) no longer sends `files-api-2025-04-14` and returns the same shapes as `client.files` (csharp, go: `client.Files`; java: `client.files()`; php: `$client->files`), with `Beta`-prefixed type names (in PHP, classes in the `Anthropic\Beta` namespace). It takes beta names through `betas` (csharp, go: `Betas`; java: `.addBeta()`) for Files features that are in beta, such as `scope_id` filtering under a [Managed Agents](https://platform.claude.com/docs/en/managed-agents/files) beta header. Earlier SDK releases are typed to the beta shapes; if you depend on those types, stay on an earlier release until you migrate.
990986 
991987Requests that carry `anthropic-beta: managed-agents-2026-04-01` without `files-api-2025-04-14` receive the shapes on this page with one compatibility affordance on `GET /v1/files`: `before_id` and `after_id` are still accepted (not combinable with `page` or `ids[]`), and the list response includes `has_more`, `first_id`, and `last_id` alongside `next_page`. Later Managed Agents beta versions receive the plain shape.
992988 
from line 994
998994* **Invalid file type (400):** The file type doesn't match the content block type (for example, using an image file in a document block)
999995* **Not downloadable (400):** Files you upload have `"downloadable": false` and cannot be downloaded. Only files created by skills or the code execution tool can be downloaded
1000996* **Exceeds context window size (400):** The file is larger than the context window size (for example, using a 500 MB plain text file in a `/v1/messages` request)
1001* **Invalid filename (400):** The file name doesn't meet the length requirements (1-255 characters) or contains forbidden characters (`<`, `>`, `:`, `"`, `|`, `?`, `*`, `\`, `/`, or Unicode characters 0-31)
997* **Invalid file name (400):** The file name doesn't meet the length requirements (1–255 characters) or contains forbidden characters (`<`, `>`, `:`, `"`, `|`, `?`, `*`, `\`, `/`, or Unicode characters 0–31)
1002998* **File too large (413):** File exceeds the 500 MB limit
1003* **Storage limit exceeded (400):** Your organization has reached the 1 TB storage limit
999* **Storage limit exceeded (400):** Your organization has reached the 1 TB storage limit
10041000 
10051001```json Output
10061002{
from line 1033
10371033 </Card>
10381034 
10391035 <Card title="Code execution tool" icon="terminal" href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool">
1040 Run Python and bash code in a sandboxed container to analyze data, generate files, and iterate on solutions.
1036 Run Python and Bash code in a sandboxed container to analyze data, generate files, and iterate on solutions.
10411037 </Card>
10421038 
10431039 <Card title="Vision" icon="image" href="https://platform.claude.com/docs/en/build-with-claude/vision">

build-with-claude/handling-stop-reasons Changed · +18 / -18 lines

## Stop reasons versus errors ## Stop reasons vs. errors

from line 12
1212 
1313| Value | When it occurs | What to do |
1414| -------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
15| [`end_turn`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#end-turn) | Claude finished its response naturally. | Use the response. |
15| [`end_turn`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#end-turn) | Claude completed its response naturally. | Use the response. |
1616| [`max_tokens`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#max-tokens) | The response reached your `max_tokens` limit. | Raise `max_tokens` or [continue the response](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#ensuring-complete-responses). |
1717| [`stop_sequence`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#stop-sequence) | Claude emitted one of your `stop_sequences`. | Read `stop_sequence` to see which one fired. |
1818| [`tool_use`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#tool-use) | Claude is calling a tool. | Run the tool and return the result. A server tool call still missing its result block completes in a later response. |
from line 49
4949 
5050### end\_turn
5151 
52The most common stop reason. Indicates Claude finished its response naturally.
52The most common stop reason. Indicates Claude completed its response naturally.
5353 
5454<CodeGroup>
5555 ```bash cURL
from line 206
206206</CodeGroup>
207207 
208208<Accordion title="Empty responses with end_turn">
209 Sometimes Claude returns an empty response (exactly 2–3 tokens with no content) with `stop_reason: "end_turn"`. This typically occurs when Claude interprets that the assistant turn is complete, particularly after tool results.
209 Sometimes Claude returns an empty response (exactly 2–3 tokens with no content) with `stop_reason: "end_turn"`. This typically occurs when Claude determines that the assistant turn is complete, particularly after tool results.
210210 
211211 **Common causes:**
212212 
213 * Adding text blocks immediately after tool results (Claude learns to expect the user to always insert text after tool results, so it ends its turn to follow the pattern)
213 * Adding text blocks immediately after tool results (the history then shows user text after every tool result, so Claude ends its turn to follow that pattern)
214214 * Sending Claude's completed response back without adding anything (Claude already determined it's done, so it will remain done)
215215 
216216 **How to prevent empty responses:**
from line 537
537537 # Check if response is empty
538538 if response.stop_reason == "end_turn" and not response.content:
539539 # INCORRECT: Don't just retry with the empty response
540 # This won't work because Claude already decided it's done
540 # This won't work because Claude already determined it's done
541541 
542542 # CORRECT: Add a continuation prompt in a NEW user message
543543 messages.append({"role": "user", "content": "Please continue"})
from line 563
563563 // Check if response is empty
564564 if (response.stop_reason === "end_turn" && response.content.length === 0) {
565565 // INCORRECT: Don't just retry with the empty response
566 // This won't work because Claude already decided it's done
566 // This won't work because Claude already determined it's done
567567 
568568 // CORRECT: Add a continuation prompt in a NEW user message
569569 messages.push({ role: "user", content: "Please continue" });
from line 719
719719 
720720 **Best practices:**
721721 
722 1. **Never add text blocks immediately after tool results:** This teaches Claude to expect user input after every tool use.
722 1. **Never add text blocks immediately after tool results:** This sets a pattern of user input after every tool use, and Claude follows that pattern by ending its turn.
723723 2. **Don't retry empty responses without modification:** Sending the empty response back won't help.
724724 3. **Use continuation prompts as a last resort:** Only if these fixes don't resolve the issue.
725725</Accordion>
from line 1178
11781178 
11791179### tool\_use
11801180 
1181Claude is calling a tool and expects you to run it.
1181Claude is calling a tool that you need to run.
11821182 
11831183<Note>
11841184 For most tool use implementations, use the [tool runner](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner), which automatically handles tool execution, result formatting, and conversation management.
from line 1470
14701470 ```
14711471</CodeGroup>
14721472 
1473A `tool_use` response can also contain a `server_tool_use` block whose `id` has no matching result block. That server tool call is not finished, and this response does not carry its result. In the common case, Claude calls a [server tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) and one of your client tools in the same group of parallel tool calls: the API returns without running the server tool so that you can run the client tools first. There is no other marker for the state; detect it by checking each `server_tool_use` or `mcp_tool_use` block's `id` for a matching result block.
1473A `tool_use` response can also contain a `server_tool_use` block whose `id` has no matching result block. That server tool call is not complete, and this response does not carry its result. In the common case, Claude calls a [server tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) and one of your client tools in the same group of parallel tool calls: the API returns without running the server tool so that you can run the client tools first. There is no other marker for the state; detect it by checking each `server_tool_use` or `mcp_tool_use` block's `id` for a matching result block.
14741474 
14751475<Note>
1476 With [programmatic tool calling](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling), the same response shape means something different. The client `tool_use` block comes from code that is running in the `code_execution` tool rather than from Claude directly, and its `caller` field names the `code_execution` block that called it. That code has already started: it is paused waiting for your `tool_result` blocks, and sending them resumes the execution instead of starting a deferred tool. The `code_execution` block's own result block arrives once the code finishes, which can take more than one round of tool results. The follow-up user message itself is the same in both cases; with programmatic tool calling, also pass back the `id` from the response's `container` field, as that page shows.
1476 With [programmatic tool calling](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling), the same response shape means something different. The client `tool_use` block comes from code that is running in the `code_execution` tool rather than from Claude directly, and its `caller` field names the `code_execution` block that called it. That code has already started: it is paused waiting for your `tool_result` blocks, and sending them resumes the execution instead of starting a deferred tool. The `code_execution` block's own result block arrives once the code completes, which can take more than one round of tool results. The follow-up user message itself is the same in both cases; with programmatic tool calling, also pass back the `id` from the response's `container` field, as that page shows.
14771477</Note>
14781478 
14791479```json A mixed tool_use response
from line 1521
15211521 
15221522### pause\_turn
15231523 
1524Returned when the server-side sampling loop reaches its iteration limit while executing [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) such as web search. The default limit is 10 iterations per request.
1524Returned when the server-side sampling loop reaches its iteration limit while running [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) such as web search. The default limit is 10 iterations for each request.
15251525 
1526When this happens, the response may contain a `server_tool_use` block without a corresponding result block. To let Claude finish processing, continue the conversation by sending the response back as-is. A response that leaves a client `tool_use` block waiting on you never has a `stop_reason` of `pause_turn`: when Claude stops to call your tools, `stop_reason` is [`tool_use`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#tool-use), and you continue it by sending the client `tool_result` blocks instead of the response itself.
1526When this occurs, the response might contain a `server_tool_use` block without a corresponding result block. To let Claude finish processing, continue the conversation by sending the response back as-is. A response that leaves a client `tool_use` block waiting on you never has a `stop_reason` of `pause_turn`: when Claude stops to call your tools, `stop_reason` is [`tool_use`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#tool-use), and you continue it by sending the client `tool_result` blocks instead of the response itself.
15271527 
15281528<CodeGroup>
15291529 ```bash cURL
from line 1889
18891889 If you encounter `refusal` stop reasons frequently while using Claude Sonnet 4.5 ([deprecated](https://platform.claude.com/docs/en/about-claude/model-deprecations)) or Claude Opus 4.1 (the latter [retired, except on Bedrock and Google Cloud](https://platform.claude.com/docs/en/about-claude/model-deprecations)), you can try updating your API calls to use Haiku 4.5 (`claude-haiku-4-5-20251001`), which has different usage restrictions. Learn more about [understanding Sonnet 4.5's API safety filters](https://support.claude.com/en/articles/12449294-understanding-sonnet-4-5-s-api-safety-filters).
18901890</Tip>
18911891 
1892On a refusal, the `stop_details` object identifies the policy category that triggered it. The categories and the full refusal response shape are covered on [Refusals and fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response). `stop_details` is `null` for all stop reasons other than `refusal`.
1892On a refusal, the `stop_details` object identifies the policy category that triggered it. The categories and the full refusal response shape are covered in [What a refusal looks like](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response). `stop_details` is `null` for all stop reasons other than `refusal`.
18931893 
18941894A refused request on Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, Claude Sonnet 5.5, or Claude Haiku 5.5 can usually be served by retrying on another Claude model. [Refusals and fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback) shows how to set up that retry, server-side or in your client. Claude Haiku 5.5 has no server-side fallback, so set up its retry [in your client](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#client-side-fallback). If you build the retry yourself from Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, or Claude Sonnet 5.5, [fallback credit](https://platform.claude.com/docs/en/build-with-claude/fallback-credit) covers how to avoid paying the prompt-cache cost twice.
18951895 
from line 1898
18981898Claude stopped because it reached the model's context window limit. This lets you request the maximum possible tokens without knowing the exact input size.
18991899 
19001900<Note>
1901 This stop reason is currently typed only in the SDK's `beta` (csharp, go: `Beta`; java: `beta()`) namespace, so the following examples call `client.beta.messages` (csharp, go: `client.Beta.Messages`; java: `client.beta().messages()`; php: `$client->beta->messages`) and use the `Beta`-prefixed types. On Sonnet 4.5 (deprecated) and newer models the API returns this value without a beta header. For earlier models, add the `model-context-window-exceeded-2025-08-26` beta header to enable it.
1901 This stop reason is currently typed only in the SDK's `beta` (csharp, go: `Beta`; java: `beta()`) namespace, so the following examples call `client.beta.messages` (csharp, go: `client.Beta.Messages`; java: `client.beta().messages()`; php: `$client->beta->messages`) and use the `Beta`-prefixed types. On Sonnet 4.5 (deprecated) and newer models, the API returns this value without a beta header. For earlier models, add the `model-context-window-exceeded-2025-08-26` beta header to enable it.
19021902</Note>
19031903 
19041904<CodeGroup>
from line 2318
23182318 
23192319### Implement retry logic for pause\_turn
23202320 
2321When using [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools), the API may return `pause_turn` if the server-side sampling loop reaches its iteration limit (default 10). Handle this by continuing the conversation:
2321When using [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools), the API might return `pause_turn` if the server-side sampling loop reaches its iteration limit (default 10). Handle this by continuing the conversation:
23222322 
23232323<CodeGroup exclude="shell">
23242324 ```python Python
from line 2572
25722572 ```
25732573</CodeGroup>
25742574 
2575## Stop reasons vs. errors
2575## Stop reasons versus errors
25762576 
25772577It's important to distinguish between `stop_reason` values and actual errors:
25782578 
from line 3641
36413641 Retry refused requests on a fallback model, server-side or in your client.
36423642 </Card>
36433643 
3644 <Card title="Tool Runner (SDK)" icon="wrench" href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner">
3644 <Card title="Tool runner (SDK)" icon="wrench" href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner">
36453645 Let the SDK manage the `tool_use` loop, result formatting, and retries for you.
36463646 </Card>
36473647 

build-with-claude/mid-conversation-effort-example Changed · +5 / -5 lines

from line 18
1818 
1919## Set up the loop
2020 
21The example is a single file. The constants control the effort level, the fan-out shape, and how often the mode refresher is re-sent. `MAX_CONCURRENT` caps how many subagents run at the same time (the PHP port is sequential and ignores it); `MAX_TOTAL_SUBTASKS` caps how many the model may queue in a single Workflow call. Splitting the two lets the model plan a large backlog without launching it all at once. The `DOC_TEST_MODE` check caps the loops to a single turn when that environment variable is set, so the automated docs harness can validate that the file compiles and finishes quickly without running the full orchestration; leave it unset when running the example yourself.
21The example is a single file. The constants control the effort level, the fan-out shape, and how often the mode refresher is re-sent. `MAX_CONCURRENT` caps how many subagents run at the same time (the PHP port is sequential and ignores it); `MAX_TOTAL_SUBTASKS` caps how many the model may queue in a single Workflow call. Splitting the two lets the model plan a large backlog without launching it all at once. The `DOC_TEST_MODE` check caps the loops to a single turn when that environment variable is set, so the automated docs harness can validate that the file compiles and completes quickly without running the full orchestration; leave it unset when running the example yourself.
2222 
2323<CodeGroup exclude="shell:cURL, shell:CLI">
2424 ```python Python
from line 1948
19481948 
19491949## Journal results so reruns resume
19501950 
1951A fan-out that spawns dozens of subagents is expensive to restart from scratch. A small content-addressed journal makes it idempotent: before dispatching a subagent, look up the SHA-256 of its prompt in a local JSON file, and return the recorded result if one exists. Interrupt the run, rerun it, and only the subtasks that never finished are recomputed. The journal deduplicates across runs, not within a single fan-out wave; delete the journal file to start fresh.
1951A fan-out that spawns dozens of subagents is expensive to restart from the beginning. A small content-addressed journal makes it idempotent: before dispatching a subagent, look up the SHA-256 of its prompt in a local JSON file, and return the recorded result if one exists. Interrupt the run, rerun it, and only the subtasks that never completed are recomputed. The journal deduplicates across runs, not within a single fan-out wave; delete the journal file to start fresh.
19521952 
19531953<CodeGroup exclude="shell:cURL, shell:CLI">
19541954 ```python Python
from line 2239
22392239 
22402240## Fan out, then verify
22412241 
2242The fan-out accepts up to `MAX_TOTAL_SUBTASKS` prompts, runs them through the journal with at most `MAX_CONCURRENT` in flight (sequential in the PHP port), and isolates failures so one broken subagent degrades to an error string instead of ending the run. Once the first wave finishes, a second wave reuses the same subagent path to try to refute each result: every verifier re-derives the claims from the source, defaulting to refuted when uncertain. Both the original result and its verdict are returned to the orchestrator so it can weigh them together.
2242The fan-out accepts up to `MAX_TOTAL_SUBTASKS` prompts, runs them through the journal with at most `MAX_CONCURRENT` in flight (sequential in the PHP port), and isolates failures so one broken subagent degrades to an error string instead of ending the run. Once the first wave completes, a second wave reuses the same subagent path to attempt to refute each result: every verifier re-derives the claims from the source, defaulting to refuted when uncertain. Both the original result and its verdict are returned to the orchestrator so it can weigh them together.
22432243 
22442244<CodeGroup exclude="shell:cURL, shell:CLI">
22452245 ```python Python
from line 3892
38923892 
38933893* **Sandboxed orchestration scripts:** let the model emit a short orchestration program (branching, loops, and reduce steps) and run it inside an isolated interpreter, rather than accepting only a flat list of subtask strings.
38943894* **Durable journaling:** replace the local JSON file with a store that survives process restarts and is safe under concurrent writers across machines.
3895* **Budget enforcement:** track total subagents launched across the whole session, not just per Workflow call, and refuse to exceed a hard cap so a runaway plan cannot exhaust your quota.
3895* **Budget enforcement:** track total subagents launched across the whole session, not just for each Workflow call, and refuse to exceed a hard cap so a runaway plan cannot exhaust your quota.
38963896 
38973897The patterns in this example (the mode reminders, standing consent in the tool description, journaling, and a verification wave) carry over unchanged; only the execution substrate around them gets more robust.
38983898 
from line 3912
39123912 </Card>
39133913 
39143914 <Card title="Bash tool" icon="terminal" href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/bash-tool">
3915 The Anthropic-defined bash tool this example executes locally.
3915 The Anthropic-defined bash tool this example runs locally.
39163916 </Card>
39173917</CardGroup>
39183918 
Feedback