Sweep 22 Sep 2026 · 17:19Z Build v2.1.280 501 read Stable v2.1.267 Latest v2.1.280 Next v2.1.280 Feeds RSS JSON llms.txt Unofficial
One capture · api

One read of Claude Developer Platform

147 pages moved out of 634 read.

api-20260922T163722Z

Pages moved 147 significant first
Pages read 634 in this capture
Captured 16:37 UTC
Corpus hash 4b35df8b3fd5 corpus-hash

What this read moved

26–50 of 147

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

api/errors Changed · +13 / -3 lines

### Computer use tool version not supported

from line 475
475475 
476476### Thinking cannot be disabled
477477 
478On Claude Fable 5.1, [Claude Mythos 5.1](https://anthropic.com/glasswing), Claude Fable 5, [Claude Mythos 5](https://anthropic.com/glasswing), and [Claude Mythos Preview](https://anthropic.com/glasswing), thinking is always on. Sending `thinking: {"type": "disabled"}` to any of these models returns a 400 `invalid_request_error`. On all of these models except Claude Mythos Preview, the message reads:
478On Claude Fable 5.1, [Claude Mythos 5.1](https://anthropic.com/glasswing), Claude Fable 5, [Claude Mythos 5](https://anthropic.com/glasswing), Claude Opus 5.5, and [Claude Mythos Preview](https://anthropic.com/glasswing), thinking is always on. Sending `thinking: {"type": "disabled"}` to any of these models returns a 400 `invalid_request_error`. On all of these models except Claude Mythos Preview, the message reads:
479479 
480480```text wrap
481481"thinking.type.disabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.
from line 491
491491 
492492### Forced tool use not supported
493493 
494Claude Fable 5.1 and [Claude Mythos 5.1](https://anthropic.com/glasswing) don't support forced tool use. Sending `tool_choice: {"type": "any"}` or `tool_choice: {"type": "tool", "name": "..."}` to either model, including on the [token counting endpoint](https://platform.claude.com/docs/en/build-with-claude/token-counting), returns a 400 `invalid_request_error`:
494Claude Opus 5.5, Claude Fable 5.1, and [Claude Mythos 5.1](https://anthropic.com/glasswing) don't support forced tool use. Sending `tool_choice: {"type": "any"}` or `tool_choice: {"type": "tool", "name": "..."}` to any of these models, including on the [token counting endpoint](https://platform.claude.com/docs/en/build-with-claude/token-counting), returns a 400 `invalid_request_error`:
495495 
496496```text wrap
497497tool_choice: type "tool" and "any" are not supported for this model.
from line 499
499499 
500500`tool_choice: {"type": "auto"}` (the default) and `{"type": "none"}` are accepted. Use `auto` with [strict tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use) to keep tool inputs schema-valid, or [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) when you need the response itself in a fixed JSON shape. See [Forcing tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools#forcing-tool-use).
501501 
502### Computer use tool version not supported
503 
504On the Claude API and Google Cloud, Claude Opus 5.5 supports [computer use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool) only as the `computer_toolset_20260801` toolset. On those platforms, sending it a `tools` entry of the earlier `computer_20251124` type (with that tool's beta header) returns a 400 `invalid_request_error`. The message names the rejected type, then lists the tool types the model does accept after `Did you mean one of`; it begins:
505 
506```text wrap
507'claude-opus-5-5' does not support tool types: computer_20251124.
508```
509 
510The API returns the same message for any Anthropic-defined tool type that the requested model doesn't support. Declare `{"type": "computer_toolset_20260801"}` without the beta header and update your agent loop as described in [Migrate from `computer_20251124`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool#migrate-from-computer-20251124). Earlier models that support the toolset keep accepting `computer_20251124`, as does Claude Opus 5.5 on Amazon Bedrock.
511 
502512### Thinking block no longer matches the conversation
503513 
504On Claude Fable 5.1, the API accepts a replayed thinking block only while the `system` prompt, `tools`, and messages that preceded it are unchanged. For new accounts created on or after August 31, 2026, and for any request that sets `thinking.block_binding.prefix_mismatch_behavior` to `"error"`, a replayed block whose earlier history changed is rejected with a 400 `invalid_request_error` (with `"drop_block"`, the API drops the block and the request succeeds). The message starts with the position of the first failing block:
514On Claude Fable 5.1 and Claude Opus 5.5, the API accepts a replayed thinking block only while the `system` prompt, `tools`, and messages that preceded it are unchanged. For new accounts created on or after August 31, 2026, and for any request that sets `thinking.block_binding.prefix_mismatch_behavior` to `"error"`, a replayed block whose earlier history changed is rejected with a 400 `invalid_request_error` (with `"drop_block"`, the API drops the block and the request succeeds). The message starts with the position of the first failing block:
505515 
506516```text wrap
507517messages.{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".

api/rate-limits Changed · +5 / -2 lines

from line 139
139139 | Model | Maximum requests per minute (RPM) | Maximum input tokens per minute (ITPM) | Maximum output tokens per minute (OTPM) |
140140 | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------------------------------------- | --------------------------------------- |
141141 | Claude Fable 5.x1 | 1,000 | 500,000 | 100,000 |
142 | Claude Opus 5.5 | 1,000 | 2,000,000 | 400,000 |
142143 | Claude Opus 5 | 1,000 | 2,000,000 | 400,000 |
143144 | Claude Opus 4.x2 | 1,000 | 2,000,000 | 400,000 |
144145 | Claude Sonnet 5 | 1,000 | 2,000,000 | 400,000 |
from line 152
151152 | Model | Maximum requests per minute (RPM) | Maximum input tokens per minute (ITPM) | Maximum output tokens per minute (OTPM) |
152153 | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------------------------------------- | --------------------------------------- |
153154 | Claude Fable 5.x1 | 2,000 | 1,500,000 | 300,000 |
155 | Claude Opus 5.5 | 5,000 | 5,000,000 | 1,000,000 |
154156 | Claude Opus 5 | 5,000 | 5,000,000 | 1,000,000 |
155157 | Claude Opus 4.x2 | 5,000 | 5,000,000 | 1,000,000 |
156158 | Claude Sonnet 5 | 5,000 | 5,000,000 | 1,000,000 |
from line 165
163165 | Model | Maximum requests per minute (RPM) | Maximum input tokens per minute (ITPM) | Maximum output tokens per minute (OTPM) |
164166 | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------------------------------------- | --------------------------------------- |
165167 | Claude Fable 5.x1 | 4,000 | 4,000,000 | 800,000 |
168 | Claude Opus 5.5 | 10,000 | 10,000,000 | 2,000,000 |
166169 | Claude Opus 5 | 10,000 | 10,000,000 | 2,000,000 |
167170 | Claude Opus 4.x2 | 10,000 | 10,000,000 | 2,000,000 |
168171 | Claude Sonnet 5 | 10,000 | 10,000,000 | 2,000,000 |
from line 181
178181 
179182*1 Fable rate limit is a total limit that applies to combined traffic across Claude Fable 5.1 and Claude Fable 5. Claude Mythos 5.1 and Claude Mythos 5 share a separate combined limit on the same terms.*
180183 
181*2 Opus rate limit is a total limit that applies to combined traffic across Claude Opus 4.8, Opus 4.7, Opus 4.6, and Opus 4.5. Claude Opus 5 has a separate rate limit and is not part of this combined bucket.*
184*2 Opus rate limit is a total limit that applies to combined traffic across Claude Opus 4.8, Opus 4.7, Opus 4.6, and Opus 4.5. Claude Opus 5.5 and Claude Opus 5 each have a separate rate limit and are not part of this combined bucket.*
182185 
183186*3 Sonnet 4.x rate limit is a total limit that applies to combined traffic across Sonnet 4.6 and Sonnet 4.5. Claude Sonnet 5 has a separate rate limit and is not part of this combined bucket.*
184187 
from line 230
227230 
228231### Fast mode rate limits
229232 
230When using [fast mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode) (research preview) with `speed: "fast"` on Claude Opus 5 or Opus 4.8, dedicated rate limits apply that are separate from standard Opus rate limits. When fast mode rate limits are exceeded, the API returns a `429` error with a `retry-after` header. Fast mode is not available on Claude Opus 4.7 (requests return an error) or Claude Opus 4.6 (requests to `claude-opus-4-6` with `speed: "fast"` run at standard speed). See [Fast mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode#supported-models).
233When using [fast mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode) (research preview) with `speed: "fast"` on Claude Opus 5.5, Claude Opus 5, or Opus 4.8, dedicated rate limits apply that are separate from standard Opus rate limits. When fast mode rate limits are exceeded, the API returns a `429` error with a `retry-after` header. Fast mode is not available on Claude Opus 4.7 (requests return an error) or Claude Opus 4.6 (requests to `claude-opus-4-6` with `speed: "fast"` run at standard speed). See [Fast mode](https://platform.claude.com/docs/en/build-with-claude/fast-mode#supported-models).
231234 
232235The response includes `anthropic-fast-*` headers that indicate your fast mode rate limit status. See [Fast mode rate limits](https://platform.claude.com/docs/en/build-with-claude/fast-mode#rate-limits) for details on these headers.
233236 

build-with-claude/batch-processing Changed · +49 / -48 lines

from line 87
8787| Claude Mythos 5.1 ([limited availability](https://anthropic.com/glasswing)) | $5 / MTok | $25 / MTok |
8888| Claude Fable 5 | $5 / MTok | $25 / MTok |
8989| Claude Mythos 5 ([limited availability](https://anthropic.com/glasswing)) | $5 / MTok | $25 / MTok |
90| Claude Opus 5.5 | $2 / MTok | $10 / MTok |
9091| Claude Opus 5 | $2.50 / MTok | $12.50 / MTok |
9192| Claude Opus 4.8 | $2.50 / MTok | $12.50 / MTok |
9293| Claude Opus 4.7 | $2.50 / MTok | $12.50 / MTok |
from line 125
124125 {
125126 "custom_id": "my-first-request",
126127 "params": {
127 "model": "claude-opus-5",
128 "model": "claude-opus-5-5",
128129 "max_tokens": 1024,
129130 "messages": [
130131 {"role": "user", "content": "Hello, world"}
from line 135
134135 {
135136 "custom_id": "my-second-request",
136137 "params": {
137 "model": "claude-opus-5",
138 "model": "claude-opus-5-5",
138139 "max_tokens": 1024,
139140 "messages": [
140141 {"role": "user", "content": "Hi again, friend"}
from line 151
150151 requests:
151152 - custom_id: my-first-request
152153 params:
153 model: claude-opus-5
154 model: claude-opus-5-5
154155 max_tokens: 1024
155156 messages:
156157 - role: user
from line 158
157158 content: Hello, world
158159 - custom_id: my-second-request
159160 params:
160 model: claude-opus-5
161 model: claude-opus-5-5
161162 max_tokens: 1024
162163 messages:
163164 - role: user
from line 177
176177 Request(
177178 custom_id="my-first-request",
178179 params=MessageCreateParamsNonStreaming(
179 model="claude-opus-5",
180 model="claude-opus-5-5",
180181 max_tokens=1024,
181182 messages=[
182183 {
from line 190
189190 Request(
190191 custom_id="my-second-request",
191192 params=MessageCreateParamsNonStreaming(
192 model="claude-opus-5",
193 model="claude-opus-5-5",
193194 max_tokens=1024,
194195 messages=[
195196 {
from line 214
213214 {
214215 custom_id: "my-first-request",
215216 params: {
216 model: "claude-opus-5",
217 model: "claude-opus-5-5",
217218 max_tokens: 1024,
218219 messages: [{ role: "user", content: "Hello, world" }]
219220 }
from line 222
221222 {
222223 custom_id: "my-second-request",
223224 params: {
224 model: "claude-opus-5",
225 model: "claude-opus-5-5",
225226 max_tokens: 1024,
226227 messages: [{ role: "user", content: "Hi again, friend" }]
227228 }
from line 249
248249 CustomID = "my-first-request",
249250 Params = new()
250251 {
251 Model = Model.ClaudeOpus5,
252 Model = Model.ClaudeOpus5_5,
252253 MaxTokens = 1024,
253254 Messages =
254255 [
from line 262
261262 CustomID = "my-second-request",
262263 Params = new()
263264 {
264 Model = Model.ClaudeOpus5,
265 Model = Model.ClaudeOpus5_5,
265266 MaxTokens = 1024,
266267 Messages =
267268 [
from line 285
284285 {
285286 CustomID: "my-first-request",
286287 Params: anthropic.MessageBatchNewParamsRequestParams{
287 Model: anthropic.ModelClaudeOpus5,
288 Model: anthropic.ModelClaudeOpus5_5,
288289 MaxTokens: 1024,
289290 Messages: []anthropic.MessageParam{
290291 anthropic.NewUserMessage(
from line 297
296297 {
297298 CustomID: "my-second-request",
298299 Params: anthropic.MessageBatchNewParamsRequestParams{
299 Model: anthropic.ModelClaudeOpus5,
300 Model: anthropic.ModelClaudeOpus5_5,
300301 MaxTokens: 1024,
301302 Messages: []anthropic.MessageParam{
302303 anthropic.NewUserMessage(
from line 321
320321 .customId("my-first-request")
321322 .params(
322323 BatchCreateParams.Request.Params.builder()
323 .model(Model.CLAUDE_OPUS_5)
324 .model(Model.CLAUDE_OPUS_5_5)
324325 .maxTokens(1024)
325326 .addUserMessage("Hello, world")
326327 .build()
from line 333
332333 .customId("my-second-request")
333334 .params(
334335 BatchCreateParams.Request.Params.builder()
335 .model(Model.CLAUDE_OPUS_5)
336 .model(Model.CLAUDE_OPUS_5_5)
336337 .maxTokens(1024)
337338 .addUserMessage("Hi again, friend")
338339 .build()
from line 355
354355 [
355356 'custom_id' => 'my-first-request',
356357 'params' => [
357 'model' => 'claude-opus-5',
358 'model' => 'claude-opus-5-5',
358359 'max_tokens' => 1024,
359360 'messages' => [
360361 ['role' => 'user', 'content' => 'Hello, world']
from line 365
364365 [
365366 'custom_id' => 'my-second-request',
366367 'params' => [
367 'model' => 'claude-opus-5',
368 'model' => 'claude-opus-5-5',
368369 'max_tokens' => 1024,
369370 'messages' => [
370371 ['role' => 'user', 'content' => 'Hi again, friend']
from line 386
385386 {
386387 custom_id: "my-first-request",
387388 params: {
388 model: "claude-opus-5",
389 model: "claude-opus-5-5",
389390 max_tokens: 1024,
390391 messages: [
391392 { role: "user", content: "Hello, world" }
from line 396
395396 {
396397 custom_id: "my-second-request",
397398 params: {
398 model: "claude-opus-5",
399 model: "claude-opus-5-5",
399400 max_tokens: 1024,
400401 messages: [
401402 { role: "user", content: "Hi again, friend" }
from line 932
931932The results are in `.jsonl` format, where each line is a valid JSON object representing the result of a single request in the Message Batch. For each streamed result, you can do something different depending on its `custom_id` and result type. Here is an example set of results:
932933 
933934```jsonl .jsonl file
934{"custom_id":"my-second-request","result":{"type":"succeeded","message":{"id":"msg_014VwiXbi91y3JMjcpyGBHX5","type":"message","role":"assistant","model":"claude-opus-5","content":[{"type":"text","text":"Hello again! It's nice to see you. How can I assist you today? Is there anything specific you'd like to chat about or any questions you have?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":11,"output_tokens":36}}}}
935{"custom_id":"my-first-request","result":{"type":"succeeded","message":{"id":"msg_01FqfsLoHwgeFbguDgpz48m7","type":"message","role":"assistant","model":"claude-opus-5","content":[{"type":"text","text":"Hello! How can I assist you today? Feel free to ask me any questions or let me know if there's anything you'd like to chat about."}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":34}}}}
935{"custom_id":"my-second-request","result":{"type":"succeeded","message":{"id":"msg_014VwiXbi91y3JMjcpyGBHX5","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Hello again! It's nice to see you. How can I assist you today? Is there anything specific you'd like to chat about or any questions you have?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":11,"output_tokens":36}}}}
936{"custom_id":"my-first-request","result":{"type":"succeeded","message":{"id":"msg_01FqfsLoHwgeFbguDgpz48m7","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Hello! How can I assist you today? Feel free to ask me any questions or let me know if there's anything you'd like to chat about."}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":34}}}}
936937```
937938 
938939If your result has an error, its `result.error` will be set to the standard [error shape](https://platform.claude.com/docs/en/api/errors#error-shapes).
from line 1076
10751076 {
10761077 "custom_id": "my-first-request",
10771078 "params": {
1078 "model": "claude-opus-5",
1079 "model": "claude-opus-5-5",
10791080 "max_tokens": 1024,
10801081 "system": [
10811082 {
from line 1097
10961097 {
10971098 "custom_id": "my-second-request",
10981099 "params": {
1099 "model": "claude-opus-5",
1100 "model": "claude-opus-5-5",
11001101 "max_tokens": 1024,
11011102 "system": [
11021103 {
from line 1124
11231124 requests:
11241125 - custom_id: my-first-request
11251126 params:
1126 model: claude-opus-5
1127 model: claude-opus-5-5
11271128 max_tokens: 1024
11281129 system:
11291130 - type: text
from line 1141
11401141 content: Analyze the major themes in Pride and Prejudice.
11411142 - custom_id: my-second-request
11421143 params:
1143 model: claude-opus-5
1144 model: claude-opus-5-5
11441145 max_tokens: 1024
11451146 system:
11461147 - type: text
from line 1170
11691170 Request(
11701171 custom_id="my-first-request",
11711172 params=MessageCreateParamsNonStreaming(
1172 model="claude-opus-5",
1173 model="claude-opus-5-5",
11731174 max_tokens=1024,
11741175 system=[
11751176 {
from line 1194
11931194 Request(
11941195 custom_id="my-second-request",
11951196 params=MessageCreateParamsNonStreaming(
1196 model="claude-opus-5",
1197 model="claude-opus-5-5",
11971198 max_tokens=1024,
11981199 system=[
11991200 {
from line 1227
12261227 {
12271228 custom_id: "my-first-request",
12281229 params: {
1229 model: "claude-opus-5",
1230 model: "claude-opus-5-5",
12301231 max_tokens: 1024,
12311232 system: [
12321233 {
from line 1248
12471248 {
12481249 custom_id: "my-second-request",
12491250 params: {
1250 model: "claude-opus-5",
1251 model: "claude-opus-5-5",
12511252 max_tokens: 1024,
12521253 system: [
12531254 {
from line 1287
12861287 CustomID = "my-first-request",
12871288 Params = new()
12881289 {
1289 Model = Model.ClaudeOpus5,
1290 Model = Model.ClaudeOpus5_5,
12901291 MaxTokens = 1024,
12911292 System = new List<TextBlockParam>
12921293 {
from line 1312
13111312 CustomID = "my-second-request",
13121313 Params = new()
13131314 {
1314 Model = Model.ClaudeOpus5,
1315 Model = Model.ClaudeOpus5_5,
13151316 MaxTokens = 1024,
13161317 System = new List<TextBlockParam>
13171318 {
from line 1344
13431344 {
13441345 CustomID: "my-first-request",
13451346 Params: anthropic.MessageBatchNewParamsRequestParams{
1346 Model: anthropic.ModelClaudeOpus5,
1347 Model: anthropic.ModelClaudeOpus5_5,
13471348 MaxTokens: 1024,
13481349 System: []anthropic.TextBlockParam{
13491350 {
from line 1363
13621363 {
13631364 CustomID: "my-second-request",
13641365 Params: anthropic.MessageBatchNewParamsRequestParams{
1365 Model: anthropic.ModelClaudeOpus5,
1366 Model: anthropic.ModelClaudeOpus5_5,
13661367 MaxTokens: 1024,
13671368 System: []anthropic.TextBlockParam{
13681369 {
from line 1400
13991400 .customId("my-first-request")
14001401 .params(
14011402 BatchCreateParams.Request.Params.builder()
1402 .model(Model.CLAUDE_OPUS_5)
1403 .model(Model.CLAUDE_OPUS_5_5)
14031404 .maxTokens(1024)
14041405 .systemOfTextBlockParams(
14051406 List.of(
from line 1425
14241425 .customId("my-second-request")
14251426 .params(
14261427 BatchCreateParams.Request.Params.builder()
1427 .model(Model.CLAUDE_OPUS_5)
1428 .model(Model.CLAUDE_OPUS_5_5)
14281429 .maxTokens(1024)
14291430 .systemOfTextBlockParams(
14301431 List.of(
from line 1458
14571458 [
14581459 'custom_id' => 'my-first-request',
14591460 'params' => [
1460 'model' => 'claude-opus-5',
1461 'model' => 'claude-opus-5-5',
14611462 'max_tokens' => 1024,
14621463 'system' => [
14631464 [
from line 1479
14781479 [
14791480 'custom_id' => 'my-second-request',
14801481 'params' => [
1481 'model' => 'claude-opus-5',
1482 'model' => 'claude-opus-5-5',
14821483 'max_tokens' => 1024,
14831484 'system' => [
14841485 [
from line 1509
15081509 {
15091510 custom_id: "my-first-request",
15101511 params: {
1511 model: "claude-opus-5",
1512 model: "claude-opus-5-5",
15121513 max_tokens: 1024,
15131514 system: [
15141515 {
from line 1530
15291530 {
15301531 custom_id: "my-second-request",
15311532 params: {
1532 model: "claude-opus-5",
1533 model: "claude-opus-5-5",
15331534 max_tokens: 1024,
15341535 system: [
15351536 {
from line 1565
15641565 
15651566### Extended output (beta)
15661567 
1567The `output-300k-2026-03-24` beta header raises the `max_tokens` cap to 300,000 for batch requests using Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, or Claude Sonnet 4.6. Include the header to generate outputs far longer than the standard 128k `max_tokens` limit in a single turn.
1568The `output-300k-2026-03-24` beta header raises the `max_tokens` cap to 300,000 for batch requests using Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, or Claude Sonnet 4.6. Include the header to generate outputs far longer than the standard 128k `max_tokens` limit in a single turn.
15681569 
15691570<Note>
15701571 Extended output is available on the Message Batches API only, not the synchronous Messages API. It is supported on the Claude API and Claude Platform on AWS, and is not currently available on Amazon Bedrock, Google Cloud, or Microsoft Foundry.
from line 1588
15871588 {
15881589 "custom_id": "long-form-request",
15891590 "params": {
1590 "model": "claude-opus-5",
1591 "model": "claude-opus-5-5",
15911592 "max_tokens": 300000,
15921593 "messages": [
15931594 {"role": "user", "content": "Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices."}
from line 1604
16031604 requests:
16041605 - custom_id: long-form-request
16051606 params:
1606 model: claude-opus-5
1607 model: claude-opus-5-5
16071608 max_tokens: 300000
16081609 messages:
16091610 - role: user
from line 1627
16261627 Request(
16271628 custom_id="long-form-request",
16281629 params=MessageCreateParamsNonStreaming(
1629 model="claude-opus-5",
1630 model="claude-opus-5-5",
16301631 max_tokens=300_000,
16311632 messages=[
16321633 {
from line 1652
16511652 {
16521653 custom_id: "long-form-request",
16531654 params: {
1654 model: "claude-opus-5",
1655 model: "claude-opus-5-5",
16551656 max_tokens: 300000,
16561657 messages: [
16571658 {
from line 1687
16861687 CustomID = "long-form-request",
16871688 Params = new()
16881689 {
1689 Model = Model.ClaudeOpus5,
1690 Model = Model.ClaudeOpus5_5,
16901691 MaxTokens = 300_000,
16911692 Messages =
16921693 [
from line 1711
17101711 {
17111712 CustomID: "long-form-request",
17121713 Params: anthropic.BetaMessageBatchNewParamsRequestParams{
1713 Model: anthropic.ModelClaudeOpus5,
1714 Model: anthropic.ModelClaudeOpus5_5,
17141715 MaxTokens: 300_000,
17151716 Messages: []anthropic.BetaMessageParam{
17161717 anthropic.NewBetaUserMessage(
from line 1742
17411742 .customId("long-form-request")
17421743 .params(
17431744 BatchCreateParams.Request.Params.builder()
1744 .model(Model.CLAUDE_OPUS_5)
1745 .model(Model.CLAUDE_OPUS_5_5)
17451746 .maxTokens(300_000L)
17461747 .addUserMessage("Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices.")
17471748 .build()
from line 1766
17651766 [
17661767 'custom_id' => 'long-form-request',
17671768 'params' => [
1768 'model' => 'claude-opus-5',
1769 'model' => 'claude-opus-5-5',
17691770 'max_tokens' => 300_000,
17701771 'messages' => [
17711772 ['role' => 'user', 'content' => 'Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices.']
from line 1788
17871788 {
17881789 custom_id: "long-form-request",
17891790 params: {
1790 model: "claude-opus-5",
1791 model: "claude-opus-5-5",
17911792 max_tokens: 300_000,
17921793 messages: [
17931794 { role: "user", content: "Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices." }

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

from line 41
4141 -H "anthropic-beta: cache-diagnosis-2026-04-07" \
4242 -H "content-type: application/json" \
4343 -d '{
44 "model": "claude-opus-5",
44 "model": "claude-opus-5-5",
4545 "max_tokens": 1024,
4646 "cache_control": {"type": "ephemeral"},
4747 "system": "You are an AI assistant analyzing a large document. <document>...</document>",
from line 59
5959 -H "content-type: application/json" \
6060 -d @- <<EOF | jq '{id, diagnostics}' # diagnostics: null means no divergence was found
6161 {
62 "model": "claude-opus-5",
62 "model": "claude-opus-5-5",
6363 "max_tokens": 1024,
6464 "cache_control": {"type": "ephemeral"},
6565 "system": "You are an AI assistant analyzing a large document. <document>...</document>",
from line 78
7878 turn1=$(ant beta:messages create \
7979 --beta cache-diagnosis-2026-04-07 \
8080 --transform '{id,usage,diagnostics}' <<'YAML'
81 model: claude-opus-5
81 model: claude-opus-5-5
8282 max_tokens: 1024
8383 cache_control:
8484 type: ephemeral
from line 97
9797 ant beta:messages create \
9898 --beta cache-diagnosis-2026-04-07 \
9999 --transform '{id,usage,diagnostics}' <<YAML
100 model: claude-opus-5
100 model: claude-opus-5-5
101101 max_tokens: 1024
102102 cache_control:
103103 type: ephemeral
from line 121
121121 
122122 # Turn 1: opt in with previous_message_id=None
123123 r1 = client.beta.messages.create(
124 model="claude-opus-5",
124 model="claude-opus-5-5",
125125 max_tokens=1024,
126126 cache_control={"type": "ephemeral"},
127127 system=SYSTEM,
from line 132
132132 
133133 # Turn 2: reference the previous response id
134134 r2 = client.beta.messages.create(
135 model="claude-opus-5",
135 model="claude-opus-5-5",
136136 max_tokens=1024,
137137 cache_control={"type": "ephemeral"},
138138 system=SYSTEM,
from line 161
161161 
162162 // Turn 1: opt in with previous_message_id: null
163163 const r1 = await client.beta.messages.create({
164 model: "claude-opus-5",
164 model: "claude-opus-5-5",
165165 max_tokens: 1024,
166166 cache_control: { type: "ephemeral" },
167167 system: SYSTEM,
from line 172
172172 
173173 // Turn 2: reference the previous response id
174174 const r2 = await client.beta.messages.create({
175 model: "claude-opus-5",
175 model: "claude-opus-5-5",
176176 max_tokens: 1024,
177177 cache_control: { type: "ephemeral" },
178178 system: SYSTEM,
from line 202
202202 var r1 = await client.Beta.Messages.Create(
203203 new()
204204 {
205 Model = Messages::Model.ClaudeOpus5,
205 Model = Messages::Model.ClaudeOpus5_5,
206206 MaxTokens = 1024,
207207 CacheControl = new(),
208208 System = system,
from line 218
218218 var r2 = await client.Beta.Messages.Create(
219219 new()
220220 {
221 Model = Messages::Model.ClaudeOpus5,
221 Model = Messages::Model.ClaudeOpus5_5,
222222 MaxTokens = 1024,
223223 CacheControl = new(),
224224 System = system,
from line 254
254254 }
255255 
256256 r1, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
257 Model: anthropic.ModelClaudeOpus5,
257 Model: anthropic.ModelClaudeOpus5_5,
258258 MaxTokens: 1024,
259259 CacheControl: anthropic.BetaCacheControlEphemeralParam{},
260260 System: system,
from line 271
271271 }
272272 
273273 r2, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
274 Model: anthropic.ModelClaudeOpus5,
274 Model: anthropic.ModelClaudeOpus5_5,
275275 MaxTokens: 1024,
276276 CacheControl: anthropic.BetaCacheControlEphemeralParam{},
277277 System: system,
from line 306
306306 
307307 var r1 = client.beta().messages().create(
308308 MessageCreateParams.builder()
309 .model(Model.CLAUDE_OPUS_5)
309 .model(Model.CLAUDE_OPUS_5_5)
310310 .maxTokens(1024)
311311 .cacheControl(BetaCacheControlEphemeral.builder().build())
312312 .system(system)
from line 319
319319 
320320 var r2 = client.beta().messages().create(
321321 MessageCreateParams.builder()
322 .model(Model.CLAUDE_OPUS_5)
322 .model(Model.CLAUDE_OPUS_5_5)
323323 .maxTokens(1024)
324324 .cacheControl(BetaCacheControlEphemeral.builder().build())
325325 .system(system)
from line 350
350350 $system = 'You are an AI assistant analyzing a large document. <document>...</document>';
351351 
352352 $r1 = $client->beta->messages->create(
353 model: Model::CLAUDE_OPUS_5,
353 model: Model::CLAUDE_OPUS_5_5,
354354 maxTokens: 1024,
355355 cacheControl: new BetaCacheControlEphemeral,
356356 system: $system,
from line 362
362362 );
363363 
364364 $r2 = $client->beta->messages->create(
365 model: Model::CLAUDE_OPUS_5,
365 model: Model::CLAUDE_OPUS_5_5,
366366 maxTokens: 1024,
367367 cacheControl: new BetaCacheControlEphemeral,
368368 system: $system,
from line 388
388388 SYSTEM = "You are an AI assistant analyzing a large document. <document>...</document>"
389389 
390390 r1 = client.beta.messages.create(
391 model: :"claude-opus-5",
391 model: :"claude-opus-5-5",
392392 max_tokens: 1024,
393393 cache_control: {type: "ephemeral"},
394394 system_: SYSTEM,
from line 400
400400 )
401401 
402402 r2 = client.beta.messages.create(
403 model: :"claude-opus-5",
403 model: :"claude-opus-5-5",
404404 max_tokens: 1024,
405405 cache_control: {type: "ephemeral"},
406406 system_: SYSTEM,
from line 439
439439 -H "content-type: application/json" \
440440 -d @- <<EOF | jq -R 'select(startswith("data: ")) | ltrimstr("data: ") | fromjson | select(.type == "message_start") | .message.diagnostics'
441441 {
442 "model": "claude-opus-5",
442 "model": "claude-opus-5-5",
443443 "max_tokens": 1024,
444444 "stream": true,
445445 "cache_control": {"type": "ephemeral"},
from line 460
460460 ant beta:messages create \
461461 --beta cache-diagnosis-2026-04-07 \
462462 --stream --format jsonl <<YAML |
463 model: claude-opus-5
463 model: claude-opus-5-5
464464 max_tokens: 1024
465465 cache_control:
466466 type: ephemeral
from line 481
481481 ```python Python
482482 # Turn 2: stream, referencing the previous response id
483483 with client.beta.messages.stream(
484 model="claude-opus-5",
484 model="claude-opus-5-5",
485485 max_tokens=1024,
486486 cache_control={"type": "ephemeral"},
487487 system=SYSTEM,
from line 509
509509 
510510 ```typescript TypeScript
511511 const stream = client.beta.messages.stream({
512 model: "claude-opus-5",
512 model: "claude-opus-5-5",
513513 max_tokens: 1024,
514514 cache_control: { type: "ephemeral" },
515515 system: SYSTEM,
from line 548
548548 var stream = client.Beta.Messages.CreateStreaming(
549549 new()
550550 {
551 Model = Messages::Model.ClaudeOpus5,
551 Model = Messages::Model.ClaudeOpus5_5,
552552 MaxTokens = 1024,
553553 CacheControl = new(),
554554 System = system,
from line 592
592592 ```go Go
593593 // Turn 2: stream, referencing the previous response id
594594 stream := client.Beta.Messages.NewStreaming(ctx, anthropic.BetaMessageNewParams{
595 Model: anthropic.ModelClaudeOpus5,
595 Model: anthropic.ModelClaudeOpus5_5,
596596 MaxTokens: 1024,
597597 CacheControl: anthropic.BetaCacheControlEphemeralParam{},
598598 System: system,
from line 632
632632 ```java Java
633633 // Turn 2: stream, referencing the previous response id
634634 var params = MessageCreateParams.builder()
635 .model(Model.CLAUDE_OPUS_5)
635 .model(Model.CLAUDE_OPUS_5_5)
636636 .maxTokens(1024)
637637 .cacheControl(BetaCacheControlEphemeral.builder().build())
638638 .system(system)
from line 671
671671 ```php PHP
672672 // Turn 2: stream, referencing the previous response id
673673 $stream = $client->beta->messages->createStream(
674 model: Model::CLAUDE_OPUS_5,
674 model: Model::CLAUDE_OPUS_5_5,
675675 maxTokens: 1024,
676676 cacheControl: new BetaCacheControlEphemeral,
677677 system: $system,
from line 710
710710 ```ruby Ruby
711711 # Turn 2: stream, referencing the previous response id
712712 stream = client.beta.messages.stream(
713 model: :"claude-opus-5",
713 model: :"claude-opus-5-5",
714714 max_tokens: 1024,
715715 cache_control: {type: "ephemeral"},
716716 system_: SYSTEM,
from line 776
776776 messages.append({"role": "user", "content": user_message})
777777 
778778 r = client.beta.messages.create(
779 model="claude-opus-5",
779 model="claude-opus-5-5",
780780 max_tokens=1024,
781781 cache_control={"type": "ephemeral"},
782782 system=SYSTEM,
from line 808
808808 messages.push({ role: "user", content: prompt });
809809 
810810 const r: BetaMessage = await client.beta.messages.create({
811 model: "claude-opus-5",
811 model: "claude-opus-5-5",
812812 max_tokens: 1024,
813813 cache_control: { type: "ephemeral" },
814814 system: SYSTEM,
from line 844
844844 var r = await client.Beta.Messages.Create(
845845 new()
846846 {
847 Model = Messages::Model.ClaudeOpus5,
847 Model = Messages::Model.ClaudeOpus5_5,
848848 MaxTokens = 1024,
849849 CacheControl = new(),
850850 System = system,
from line 889
889889 messages = append(messages, anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock(prompt)))
890890 
891891 r, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
892 Model: anthropic.ModelClaudeOpus5,
892 Model: anthropic.ModelClaudeOpus5_5,
893893 MaxTokens: 1024,
894894 CacheControl: anthropic.BetaCacheControlEphemeralParam{},
895895 System: system,
from line 933
933933 
934934 var r = client.beta().messages().create(
935935 MessageCreateParams.builder()
936 .model(Model.CLAUDE_OPUS_5)
936 .model(Model.CLAUDE_OPUS_5_5)
937937 .maxTokens(1024)
938938 .cacheControl(BetaCacheControlEphemeral.builder().build())
939939 .system(system)
from line 971
971971 $messages[] = ['role' => 'user', 'content' => $userMsg];
972972 
973973 $r = $client->beta->messages->create(
974 model: Model::CLAUDE_OPUS_5,
974 model: Model::CLAUDE_OPUS_5_5,
975975 maxTokens: 1024,
976976 cacheControl: new BetaCacheControlEphemeral,
977977 system: $system,
from line 1003
10031003 messages << {role: "user", content: user_msg}
10041004 
10051005 r = client.beta.messages.create(
1006 model: :"claude-opus-5",
1006 model: :"claude-opus-5-5",
10071007 max_tokens: 1024,
10081008 cache_control: {type: "ephemeral"},
10091009 system_: SYSTEM,

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

from line 32
3232 -H "x-api-key: $ANTHROPIC_API_KEY" \
3333 -H "anthropic-version: 2023-06-01" \
3434 -d '{
35 "model": "claude-opus-5",
35 "model": "claude-opus-5-5",
3636 "max_tokens": 1024,
3737 "messages": [
3838 {
from line 61
6161 
6262 ```bash CLI
6363 ant messages create <<'YAML'
64 model: claude-opus-5
64 model: claude-opus-5-5
6565 max_tokens: 1024
6666 messages:
6767 - role: user
from line 84
8484 client = anthropic.Anthropic()
8585 
8686 response = client.messages.create(
87 model="claude-opus-5",
87 model="claude-opus-5-5",
8888 max_tokens=1024,
8989 messages=[
9090 {
from line 113
113113 const client = new Anthropic();
114114 
115115 const response = await client.messages.create({
116 model: "claude-opus-5",
116 model: "claude-opus-5-5",
117117 max_tokens: 1024,
118118 messages: [
119119 {
from line 147
147147 var response = await client.Messages.Create(
148148 new()
149149 {
150 Model = Model.ClaudeOpus5,
150 Model = Model.ClaudeOpus5_5,
151151 MaxTokens = 1024,
152152 Messages =
153153 [
from line 181
181181 client := anthropic.NewClient()
182182 
183183 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
184 Model: anthropic.ModelClaudeOpus5,
184 Model: anthropic.ModelClaudeOpus5_5,
185185 MaxTokens: 1024,
186186 Messages: []anthropic.MessageParam{
187187 anthropic.NewUserMessage(
from line 226
226226 .build();
227227 
228228 MessageCreateParams params = MessageCreateParams.builder()
229 .model(Model.CLAUDE_OPUS_5)
229 .model(Model.CLAUDE_OPUS_5_5)
230230 .maxTokens(1024)
231231 .addUserMessageOfBlockParams(
232232 List.of(
from line 267
267267 ],
268268 ],
269269 ],
270 model: 'claude-opus-5',
270 model: 'claude-opus-5-5',
271271 );
272272 
273273 echo json_encode($response, JSON_PRETTY_PRINT);
from line 277
277277 client = Anthropic::Client.new
278278 
279279 response = client.messages.create(
280 model: "claude-opus-5",
280 model: "claude-opus-5-5",
281281 max_tokens: 1024,
282282 messages: [
283283 {
from line 403
403403 -H "x-api-key: $ANTHROPIC_API_KEY" \
404404 -H "anthropic-version: 2023-06-01" \
405405 -d '{
406 "model": "claude-opus-5",
406 "model": "claude-opus-5-5",
407407 "max_tokens": 1024,
408408 "messages": [
409409 {
from line 430
430430 ```
431431 
432432 ```bash CLI
433 ant messages create --model claude-opus-5 --max-tokens 1024 <<'YAML'
433 ant messages create --model claude-opus-5-5 --max-tokens 1024 <<'YAML'
434434 messages:
435435 - role: user
436436 content:
from line 457
457457 ) # Minimum cacheable length
458458 
459459 response = client.messages.create(
460 model="claude-opus-5",
460 model="claude-opus-5-5",
461461 max_tokens=1024,
462462 messages=[
463463 {
from line 494
494494 "This is a very long document with thousands of words..." + " ... ".repeat(1000); // Minimum cacheable length
495495 
496496 const response = await client.messages.create({
497 model: "claude-opus-5",
497 model: "claude-opus-5-5",
498498 max_tokens: 1024,
499499 messages: [
500500 {
from line 532
532532 var response = await client.Messages.Create(
533533 new()
534534 {
535 Model = Model.ClaudeOpus5,
535 Model = Model.ClaudeOpus5_5,
536536 MaxTokens = 1024,
537537 Messages =
538538 [
from line 566
566566 strings.Repeat(" ... ", 1000) // Minimum cacheable length
567567 
568568 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
569 Model: anthropic.ModelClaudeOpus5,
569 Model: anthropic.ModelClaudeOpus5_5,
570570 MaxTokens: 1024,
571571 Messages: []anthropic.MessageParam{
572572 anthropic.NewUserMessage(
from line 608
608608 .build();
609609 
610610 MessageCreateParams params = MessageCreateParams.builder()
611 .model(Model.CLAUDE_OPUS_5)
611 .model(Model.CLAUDE_OPUS_5_5)
612612 .maxTokens(1024)
613613 .addUserMessageOfBlockParams(
614614 List.of(
from line 653
653653 ],
654654 ],
655655 ],
656 model: 'claude-opus-5',
656 model: 'claude-opus-5-5',
657657 );
658658 
659659 echo json_encode($response, JSON_PRETTY_PRINT);
from line 668
668668 " ... " * 1000 # Minimum cacheable length
669669 
670670 response = client.messages.create(
671 model: "claude-opus-5",
671 model: "claude-opus-5-5",
672672 max_tokens: 1024,
673673 messages: [
674674 {
from line 754
754754 -H "content-type: application/json" \
755755 -d @- <<EOF
756756 {
757 "model": "claude-opus-5",
757 "model": "claude-opus-5-5",
758758 "max_tokens": 1024,
759759 "messages": [
760760 {
from line 780
780780 
781781 ```bash CLI
782782 ant messages create <<YAML
783 model: claude-opus-5
783 model: claude-opus-5-5
784784 max_tokens: 1024
785785 messages:
786786 - role: user
from line 800
800800 
801801 ```python Python
802802 cited_response = client.messages.create(
803 model="claude-opus-5",
803 model="claude-opus-5-5",
804804 max_tokens=1024,
805805 messages=[
806806 {
from line 823
823823 
824824 ```typescript TypeScript
825825 const citedResponse = await client.messages.create({
826 model: "claude-opus-5",
826 model: "claude-opus-5-5",
827827 max_tokens: 1024,
828828 messages: [
829829 {
from line 851
851851 var citedResponse = await client.Messages.Create(
852852 new MessageCreateParams
853853 {
854 Model = Model.ClaudeOpus5,
854 Model = Model.ClaudeOpus5_5,
855855 MaxTokens = 1024,
856856 Messages =
857857 [
from line 879
879879 ```go Go
880880 citedMsg, err := client.Messages.New(context.Background(),
881881 anthropic.MessageNewParams{
882 Model: anthropic.ModelClaudeOpus5,
882 Model: anthropic.ModelClaudeOpus5_5,
883883 MaxTokens: 1024,
884884 Messages: []anthropic.MessageParam{
885885 anthropic.NewUserMessage(
from line 905
905905 
906906 ```java Java
907907 MessageCreateParams citedParams = MessageCreateParams.builder()
908 .model(Model.CLAUDE_OPUS_5)
908 .model(Model.CLAUDE_OPUS_5_5)
909909 .maxTokens(1024)
910910 .addUserMessageOfBlockParams(List.of(
911911 ContentBlockParam.ofDocument(DocumentBlockParam.builder()
from line 942
942942 ],
943943 ],
944944 ],
945 model: 'claude-opus-5',
945 model: 'claude-opus-5-5',
946946 );
947947 
948948 echo $citedResponse;
from line 950
950950 
951951 ```ruby Ruby
952952 cited_response = client.messages.create(
953 model: "claude-opus-5",
953 model: "claude-opus-5-5",
954954 max_tokens: 1024,
955955 messages: [
956956 {
from line 1006
10061006 -H "x-api-key: $ANTHROPIC_API_KEY" \
10071007 -H "anthropic-version: 2023-06-01" \
10081008 -d '{
1009 "model": "claude-opus-5",
1009 "model": "claude-opus-5-5",
10101010 "max_tokens": 1024,
10111011 "messages": [
10121012 {
from line 1035
10351035 
10361036 ```bash CLI
10371037 ant messages create <<'YAML'
1038 model: claude-opus-5
1038 model: claude-opus-5-5
10391039 max_tokens: 1024
10401040 messages:
10411041 - role: user
from line 1062
10621062 ).decode()
10631063 
10641064 response = client.messages.create(
1065 model="claude-opus-5",
1065 model="claude-opus-5-5",
10661066 max_tokens=1024,
10671067 messages=[
10681068 {
from line 1093
10931093 const pdfBase64 = Buffer.from(await readFile("/path/to/document.pdf")).toString("base64");
10941094 
10951095 const response = await client.messages.create({
1096 model: "claude-opus-5",
1096 model: "claude-opus-5-5",
10971097 max_tokens: 1024,
10981098 messages: [
10991099 {
from line 1129
11291129 var response = await client.Messages.Create(
11301130 new()
11311131 {
1132 Model = Model.ClaudeOpus5,
1132 Model = Model.ClaudeOpus5_5,
11331133 MaxTokens = 1024,
11341134 Messages =
11351135 [
from line 1166
11661166 pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)
11671167 
11681168 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1169 Model: anthropic.ModelClaudeOpus5,
1169 Model: anthropic.ModelClaudeOpus5_5,
11701170 MaxTokens: 1024,
11711171 Messages: []anthropic.MessageParam{
11721172 anthropic.NewUserMessage(
from line 1206
12061206 .build();
12071207 
12081208 MessageCreateParams params = MessageCreateParams.builder()
1209 .model(Model.CLAUDE_OPUS_5)
1209 .model(Model.CLAUDE_OPUS_5_5)
12101210 .maxTokens(1024)
12111211 .addUserMessageOfBlockParams(
12121212 List.of(
from line 1249
12491249 ],
12501250 ],
12511251 ],
1252 model: 'claude-opus-5',
1252 model: 'claude-opus-5-5',
12531253 );
12541254 
12551255 echo json_encode($response, JSON_PRETTY_PRINT);
from line 1261
12611261 pdf_base64 = Base64.strict_encode64(File.binread("/path/to/document.pdf"))
12621262 
12631263 response = client.messages.create(
1264 model: "claude-opus-5",
1264 model: "claude-opus-5-5",
12651265 max_tokens: 1024,
12661266 messages: [
12671267 {
from line 1300
13001300 -H "x-api-key: $ANTHROPIC_API_KEY" \
13011301 -H "anthropic-version: 2023-06-01" \
13021302 -d '{
1303 "model": "claude-opus-5",
1303 "model": "claude-opus-5-5",
13041304 "max_tokens": 1024,
13051305 "messages": [
13061306 {
from line 1328
13281328 
13291329 ```bash CLI
13301330 ant messages create <<'YAML'
1331 model: claude-opus-5
1331 model: claude-opus-5-5
13321332 max_tokens: 1024
13331333 messages:
13341334 - role: user
from line 1350
13501350 client = anthropic.Anthropic()
13511351 
13521352 response = client.messages.create(
1353 model="claude-opus-5",
1353 model="claude-opus-5-5",
13541354 max_tokens=1024,
13551355 messages=[
13561356 {
from line 1378
13781378 const client = new Anthropic();
13791379 
13801380 const response = await client.messages.create({
1381 model: "claude-opus-5",
1381 model: "claude-opus-5-5",
13821382 max_tokens: 1024,
13831383 messages: [
13841384 {
from line 1411
14111411 var response = await client.Messages.Create(
14121412 new()
14131413 {
1414 Model = Model.ClaudeOpus5,
1414 Model = Model.ClaudeOpus5_5,
14151415 MaxTokens = 1024,
14161416 Messages =
14171417 [
from line 1445
14451445 client := anthropic.NewClient()
14461446 
14471447 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1448 Model: anthropic.ModelClaudeOpus5,
1448 Model: anthropic.ModelClaudeOpus5_5,
14491449 MaxTokens: 1024,
14501450 Messages: []anthropic.MessageParam{
14511451 anthropic.NewUserMessage(
from line 1484
14841484 .build();
14851485 
14861486 MessageCreateParams params = MessageCreateParams.builder()
1487 .model(Model.CLAUDE_OPUS_5)
1487 .model(Model.CLAUDE_OPUS_5_5)
14881488 .maxTokens(1024)
14891489 .addUserMessageOfBlockParams(
14901490 List.of(
from line 1524
15241524 ],
15251525 ],
15261526 ],
1527 model: 'claude-opus-5',
1527 model: 'claude-opus-5-5',
15281528 );
15291529 
15301530 echo json_encode($response, JSON_PRETTY_PRINT);
from line 1534
15341534 client = Anthropic::Client.new
15351535 
15361536 response = client.messages.create(
1537 model: "claude-opus-5",
1537 model: "claude-opus-5-5",
15381538 max_tokens: 1024,
15391539 messages: [
15401540 {
from line 1575
15751575 -H "content-type: application/json" \
15761576 -d @- <<EOF
15771577 {
1578 "model": "claude-opus-5",
1578 "model": "claude-opus-5-5",
15791579 "max_tokens": 1024,
15801580 "messages": [
15811581 {
from line 1601
16011601 
16021602 ```bash CLI
16031603 ant messages create <<YAML
1604 model: claude-opus-5
1604 model: claude-opus-5-5
16051605 max_tokens: 1024
16061606 messages:
16071607 - role: user
from line 1621
16211621 
16221622 ```python Python
16231623 cited_response = client.messages.create(
1624 model="claude-opus-5",
1624 model="claude-opus-5-5",
16251625 max_tokens=1024,
16261626 messages=[
16271627 {
from line 1644
16441644 
16451645 ```typescript TypeScript
16461646 const citedResponse = await client.messages.create({
1647 model: "claude-opus-5",
1647 model: "claude-opus-5-5",
16481648 max_tokens: 1024,
16491649 messages: [
16501650 {
from line 1672
16721672 var citedResponse = await client.Messages.Create(
16731673 new MessageCreateParams
16741674 {
1675 Model = Model.ClaudeOpus5,
1675 Model = Model.ClaudeOpus5_5,
16761676 MaxTokens = 1024,
16771677 Messages =
16781678 [
from line 1700
17001700 ```go Go
17011701 citedMsg, err := client.Messages.New(context.Background(),
17021702 anthropic.MessageNewParams{
1703 Model: anthropic.ModelClaudeOpus5,
1703 Model: anthropic.ModelClaudeOpus5_5,
17041704 MaxTokens: 1024,
17051705 Messages: []anthropic.MessageParam{
17061706 anthropic.NewUserMessage(
from line 1726
17261726 
17271727 ```java Java
17281728 MessageCreateParams citedParams = MessageCreateParams.builder()
1729 .model(Model.CLAUDE_OPUS_5)
1729 .model(Model.CLAUDE_OPUS_5_5)
17301730 .maxTokens(1024)
17311731 .addUserMessageOfBlockParams(List.of(
17321732 ContentBlockParam.ofDocument(DocumentBlockParam.builder()
from line 1763
17631763 ],
17641764 ],
17651765 ],
1766 model: 'claude-opus-5',
1766 model: 'claude-opus-5-5',
17671767 );
17681768 
17691769 echo $citedResponse;
from line 1771
17711771 
17721772 ```ruby Ruby
17731773 cited_response = client.messages.create(
1774 model: "claude-opus-5",
1774 model: "claude-opus-5-5",
17751775 max_tokens: 1024,
17761776 messages: [
17771777 {
from line 1823
18231823 -H "x-api-key: $ANTHROPIC_API_KEY" \
18241824 -H "anthropic-version: 2023-06-01" \
18251825 -d '{
1826 "model": "claude-opus-5",
1826 "model": "claude-opus-5-5",
18271827 "max_tokens": 1024,
18281828 "messages": [
18291829 {
from line 1854
18541854 
18551855 ```bash CLI
18561856 ant messages create <<'YAML'
1857 model: claude-opus-5
1857 model: claude-opus-5-5
18581858 max_tokens: 1024
18591859 messages:
18601860 - role: user
from line 1880
18801880 client = anthropic.Anthropic()
18811881 
18821882 response = client.messages.create(
1883 model="claude-opus-5",
1883 model="claude-opus-5-5",
18841884 max_tokens=1024,
18851885 messages=[
18861886 {
from line 1911
19111911 const client = new Anthropic();
19121912 
19131913 const response = await client.messages.create({
1914 model: "claude-opus-5",
1914 model: "claude-opus-5-5",
19151915 max_tokens: 1024,
19161916 messages: [
19171917 {
from line 1947
19471947 var response = await client.Messages.Create(
19481948 new()
19491949 {
1950 Model = Model.ClaudeOpus5,
1950 Model = Model.ClaudeOpus5_5,
19511951 MaxTokens = 1024,
19521952 Messages =
19531953 [
from line 1985
19851985 client := anthropic.NewClient()
19861986 
19871987 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1988 Model: anthropic.ModelClaudeOpus5,
1988 Model: anthropic.ModelClaudeOpus5_5,
19891989 MaxTokens: 1024,
19901990 Messages: []anthropic.MessageParam{
19911991 anthropic.NewUserMessage(
from line 2034
20342034 .build();
20352035 
20362036 MessageCreateParams params = MessageCreateParams.builder()
2037 .model(Model.CLAUDE_OPUS_5)
2037 .model(Model.CLAUDE_OPUS_5_5)
20382038 .maxTokens(1024)
20392039 .addUserMessageOfBlockParams(
20402040 List.of(
from line 2077
20772077 ],
20782078 ],
20792079 ],
2080 model: 'claude-opus-5',
2080 model: 'claude-opus-5-5',
20812081 );
20822082 
20832083 echo json_encode($response, JSON_PRETTY_PRINT);
from line 2087
20872087 client = Anthropic::Client.new
20882088 
20892089 response = client.messages.create(
2090 model: "claude-opus-5",
2090 model: "claude-opus-5-5",
20912091 max_tokens: 1024,
20922092 messages: [
20932093 {

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

from line 102
102102 <Tabs>
103103 <Tab title="Gradle">
104104 ```kotlin
105 implementation("com.anthropic:anthropic-java:2.63.0")
106 implementation("com.anthropic:anthropic-java-bedrock:2.63.0")
105 implementation("com.anthropic:anthropic-java:2.65.0")
106 implementation("com.anthropic:anthropic-java-bedrock:2.65.0")
107107 ```
108108 </Tab>
109109 
from line 112
112112 <dependency>
113113 <groupId>com.anthropic</groupId>
114114 <artifactId>anthropic-java</artifactId>
115 <version>2.63.0</version>
115 <version>2.65.0</version>
116116 </dependency>
117117 <dependency>
118118 <groupId>com.anthropic</groupId>
119119 <artifactId>anthropic-java-bedrock</artifactId>
120 <version>2.63.0</version>
120 <version>2.65.0</version>
121121 </dependency>
122122 ```
123123 </Tab>
from line 155
155155 -H "content-type: application/json" \
156156 -H "anthropic-version: 2023-06-01" \
157157 -d '{
158 "model": "anthropic.claude-opus-5",
158 "model": "anthropic.claude-opus-5-5",
159159 "max_tokens": 1024,
160160 "messages": [
161161 {"role": "user", "content": "Hello, Claude"}
from line 175
175175 client = AnthropicBedrockMantle(aws_region="us-east-1")
176176 
177177 message = client.messages.create(
178 model="anthropic.claude-opus-5",
178 model="anthropic.claude-opus-5-5",
179179 max_tokens=1024,
180180 messages=[{"role": "user", "content": "Hello, Claude"}],
181181 )
from line 193
193193 });
194194 
195195 const message = await client.messages.create({
196 model: "anthropic.claude-opus-5",
196 model: "anthropic.claude-opus-5-5",
197197 max_tokens: 1024,
198198 messages: [{ role: "user", content: "Hello, Claude" }]
199199 });
from line 214
214214 
215215 var message = await client.Messages.Create(new()
216216 {
217 Model = "anthropic.claude-opus-5",
217 Model = "anthropic.claude-opus-5-5",
218218 MaxTokens = 1024,
219219 Messages = [new() { Role = Role.User, Content = "Hello, Claude" }],
220220 });
from line 240
240240 }
241241 
242242 message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
243 Model: "anthropic.claude-opus-5",
243 Model: "anthropic.claude-opus-5-5",
244244 MaxTokens: 1024,
245245 Messages: []anthropic.MessageParam{
246246 anthropic.NewUserMessage(anthropic.NewTextBlock("Hello, Claude")),
from line 275
275275 
276276 Message message = client.messages().create(
277277 MessageCreateParams.builder()
278 .model("anthropic.claude-opus-5")
278 .model("anthropic.claude-opus-5-5")
279279 .maxTokens(1024)
280280 .addUserMessage("Hello, Claude")
281281 .build()
from line 296
296296 $client = new MantleClient(awsRegion: 'us-east-1');
297297 
298298 $message = $client->messages->create(
299 model: 'anthropic.claude-opus-5',
299 model: 'anthropic.claude-opus-5-5',
300300 maxTokens: 1024,
301301 messages: [
302302 ['role' => 'user', 'content' => 'Hello, Claude'],
from line 314
314314 client = Anthropic::BedrockMantleClient.new(aws_region: "us-east-1")
315315 
316316 message = client.messages.create(
317 model: "anthropic.claude-opus-5",
317 model: "anthropic.claude-opus-5-5",
318318 max_tokens: 1024,
319319 messages: [{role: "user", content: "Hello, Claude"}]
320320 )
from line 336
336336| --------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------- |
337337| Claude Fable 5.1 | anthropic.claude-fable-5-1 | Open |
338338| Claude Fable 5 | anthropic.claude-fable-5 | Open |
339| Claude Opus 5.5 | anthropic.claude-opus-5-5 | See [Access](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#access) |
339340| Claude Opus 5 | anthropic.claude-opus-5 | See [Access](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#access) |
340341| Claude Opus 4.8 | anthropic.claude-opus-4-8 | Open |
341342| Claude Opus 4.7 | anthropic.claude-opus-4-7 | Open |
from line 344
343344| Claude Haiku 4.5 | anthropic.claude-haiku-4-5 | Open |
344345| Claude Mythos Preview | anthropic.claude-mythos-preview | Invitation only ([Project Glasswing](https://anthropic.com/glasswing)) |
345346 
346Use Claude Code 2.1.255 or later with Claude Fable 5.1 on Amazon Bedrock; run `claude update` to upgrade.
347Use Claude Code 2.1.255 or later with Claude Fable 5.1 on Amazon Bedrock, and 2.1.280 or later with Claude Opus 5.5; run `claude update` to upgrade.
347348 
348349<Tip>
349350 Upgrading to a newer Claude model? In Claude Code, run `/claude-api migrate` to apply model ID swaps and breaking parameter changes across your codebase. The skill detects which cloud platform your code targets and adjusts model ID formats and feature changes for that platform. See [Migrating to a newer Claude model](https://platform.claude.com/docs/en/agents-and-tools/agent-skills/claude-api-skill#migrating-to-a-newer-claude-model).
from line 380
379380* **Global:** dynamic routing across all available regions for maximum availability. No pricing premium.
380381* **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.
381382 
382The global endpoint is available for Claude Fable 5.1, Claude Fable 5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Sonnet 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`.
383The 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, 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`.
383384 
384385| AWS region | Location | Endpoint types |
385386| ---------------- | ------------------------- | -------------------------- |

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

from line 4
44description: Access Claude models through Microsoft Foundry with Azure-native endpoints and authentication.
55---
66 
7This guide shows you how to set up and make API calls to Claude in Microsoft Foundry using one of Anthropic's client SDKs or direct HTTP requests. When you access Claude in Microsoft Foundry, you are billed for Claude usage in the Azure Marketplace. You can use Claude models including Claude Fable 5.1, Claude Opus 5, Claude Opus 4.8, and Claude Sonnet 5, and features such as the [1M-token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows), while managing costs through your Azure subscription.
7This guide shows you how to set up and make API calls to Claude in Microsoft Foundry using one of Anthropic's client SDKs or direct HTTP requests. When you access Claude in Microsoft Foundry, you are billed for Claude usage in the Azure Marketplace. You can use Claude models including Claude Fable 5.1, Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, and Claude Sonnet 5, and features such as the [1M-token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows), while managing costs through your Azure subscription.
88 
99Claude is available in Global Standard and US Data Zone Standard deployment types in Foundry resources, billed in Claude Consumption Units through the Azure Marketplace. Visit [Claude in Microsoft Foundry pricing](https://platform.claude.com/docs/en/about-claude/pricing#claude-in-microsoft-foundry-pricing) for details.
1010 
from line 77
7777 <Tabs>
7878 <Tab title="Gradle">
7979 ```kotlin
80 implementation("com.anthropic:anthropic-java:2.63.0")
81 implementation("com.anthropic:anthropic-java-foundry:2.63.0")
80 implementation("com.anthropic:anthropic-java:2.65.0")
81 implementation("com.anthropic:anthropic-java-foundry:2.65.0")
8282 
8383 // For Entra ID authentication, also add the Azure Identity library
8484 implementation("com.azure:azure-identity:1.18.3")
from line 90
9090 <dependency>
9191 <groupId>com.anthropic</groupId>
9292 <artifactId>anthropic-java</artifactId>
93 <version>2.63.0</version>
93 <version>2.65.0</version>
9494 </dependency>
9595 <dependency>
9696 <groupId>com.anthropic</groupId>
9797 <artifactId>anthropic-java-foundry</artifactId>
98 <version>2.63.0</version>
98 <version>2.65.0</version>
9999 </dependency>
100100 <!-- For Entra ID authentication, also add the Azure Identity library -->
101101 <dependency>
from line 200
200200 -H "api-key: YOUR_AZURE_API_KEY" \
201201 -H "anthropic-version: 2023-06-01" \
202202 -d '{
203 "model": "claude-opus-5",
203 "model": "claude-opus-5-5",
204204 "max_tokens": 1024,
205205 "messages": [
206206 {"role": "user", "content": "Hello!"}
from line 214
214214 
215215 ant messages create \
216216 --base-url https://example-resource.services.ai.azure.com/anthropic \
217 --model claude-opus-5 \
217 --model claude-opus-5-5 \
218218 --max-tokens 1024 \
219219 --message '{role: user, content: "Hello!"}' \
220220 --transform content
from line 230
230230 )
231231 
232232 message = client.messages.create(
233 model="claude-opus-5",
233 model="claude-opus-5-5",
234234 max_tokens=1024,
235235 messages=[{"role": "user", "content": "Hello!"}],
236236 )
from line 246
246246 });
247247 
248248 const message = await client.messages.create({
249 model: "claude-opus-5",
249 model: "claude-opus-5-5",
250250 max_tokens: 1024,
251251 messages: [{ role: "user", content: "Hello!" }]
252252 });
from line 266
266266 
267267 var response = await client.Messages.Create(new MessageCreateParams
268268 {
269 Model = "claude-opus-5",
269 Model = "claude-opus-5-5",
270270 MaxTokens = 1024,
271271 Messages = [new() { Role = Role.User, Content = "Hello!" }],
272272 });
from line 305
305305 )
306306 
307307 message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
308 Model: "claude-opus-5",
308 Model: "claude-opus-5-5",
309309 MaxTokens: 1024,
310310 Messages: []anthropic.MessageParam{
311311 anthropic.NewUserMessage(anthropic.NewTextBlock("Hello!")),
from line 331
331331 .build();
332332 
333333 MessageCreateParams params = MessageCreateParams.builder()
334 .model("claude-opus-5")
334 .model("claude-opus-5-5")
335335 .maxTokens(1024)
336336 .addUserMessage("Hello!")
337337 .build();
from line 355
355355 messages: [
356356 ['role' => 'user', 'content' => 'Hello!']
357357 ],
358 model: 'claude-opus-5',
358 model: 'claude-opus-5-5',
359359 );
360360 echo array_find($message->content, fn ($block) => $block->type === 'text')->text;
361361 ```
from line 376
376376 )
377377 
378378 message = client.messages.create(
379 model: "claude-opus-5",
379 model: "claude-opus-5-5",
380380 max_tokens: 1024,
381381 messages: [{role: "user", content: "Hello!"}]
382382 )
from line 410
410410 -H "Authorization: Bearer $ACCESS_TOKEN" \
411411 -H "anthropic-version: 2023-06-01" \
412412 -d '{
413 "model": "claude-opus-5",
413 "model": "claude-opus-5-5",
414414 "max_tokens": 1024,
415415 "messages": [
416416 {"role": "user", "content": "Hello!"}
from line 443
443443 
444444 # Make request
445445 message = client.messages.create(
446 model="claude-opus-5",
446 model="claude-opus-5-5",
447447 max_tokens=1024,
448448 messages=[{"role": "user", "content": "Hello!"}],
449449 )
from line 466
466466 
467467 // Make request
468468 const message = await client.messages.create({
469 model: "claude-opus-5",
469 model: "claude-opus-5-5",
470470 max_tokens: 1024,
471471 messages: [{ role: "user", content: "Hello!" }]
472472 });
from line 487
487487 
488488 var response = await client.Messages.Create(new MessageCreateParams
489489 {
490 Model = "claude-opus-5",
490 Model = "claude-opus-5-5",
491491 MaxTokens = 1024,
492492 Messages = [new() { Role = Role.User, Content = "Hello!" }],
493493 });
from line 530
530530 )
531531 
532532 message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
533 Model: "claude-opus-5",
533 Model: "claude-opus-5-5",
534534 MaxTokens: 1024,
535535 Messages: []anthropic.MessageParam{
536536 anthropic.NewUserMessage(anthropic.NewTextBlock("Hello!")),
from line 566
566566 .build();
567567 
568568 MessageCreateParams params = MessageCreateParams.builder()
569 .model("claude-opus-5")
569 .model("claude-opus-5-5")
570570 .maxTokens(1024)
571571 .addUserMessage("Hello!")
572572 .build();
from line 595
595595 messages: [
596596 ['role' => 'user', 'content' => 'Hello!']
597597 ],
598 model: 'claude-opus-5',
598 model: 'claude-opus-5-5',
599599 );
600600 echo array_find($message->content, fn ($block) => $block->type === 'text')->text;
601601 ```
from line 619
619619 )
620620 
621621 message = client.messages.create(
622 model: "claude-opus-5",
622 model: "claude-opus-5-5",
623623 max_tokens: 1024,
624624 messages: [{role: "user", content: "Hello!"}]
625625 )
from line 638
638638 
639639### Context window
640640 
641Claude Fable 5.1, Claude Fable 5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, and Claude Sonnet 4.6 have a [1M-token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows) on Microsoft Foundry. Other Claude models, including Claude Sonnet 4.5, have a 200k-token context window.
641Claude 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, and Claude Sonnet 4.6 have a [1M-token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows) on Microsoft Foundry. Other Claude models, including Claude Sonnet 4.5, have a 200k-token context window.
642642 
643643### Claude features not supported for Claude in Microsoft Foundry
644644 
from line 679
679679| :---------------- | :---------------------- | :-------------: | :-----------------: |
680680| Claude Fable 5.1 | `claude-fable-5-1` | | ✓ |
681681| Claude Fable 5 | `claude-fable-5` | | ✓ |
682| Claude Opus 5.5 | `claude-opus-5-5` | ✓ | ✓ |
682683| Claude Opus 5 | `claude-opus-5` | ✓ | ✓ |
683684| Claude Opus 4.8 | `claude-opus-4-8` | ✓ | ✓ |
684685| Claude Opus 4.7 | `claude-opus-4-7` | | ✓ |

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

from line 54
5454 <Tab title="Java">
5555 <CodeGroup>
5656 ```groovy Gradle
57 implementation("com.anthropic:anthropic-java:2.63.0")
58 implementation("com.anthropic:anthropic-java-bedrock:2.63.0")
57 implementation("com.anthropic:anthropic-java:2.65.0")
58 implementation("com.anthropic:anthropic-java-bedrock:2.65.0")
5959 ```
6060 
6161 ```xml Maven
from line 62
6262 <dependency>
6363 <groupId>com.anthropic</groupId>
6464 <artifactId>anthropic-java</artifactId>
65 <version>2.63.0</version>
65 <version>2.65.0</version>
6666 </dependency>
6767 <dependency>
6868 <groupId>com.anthropic</groupId>
6969 <artifactId>anthropic-java-bedrock</artifactId>
70 <version>2.63.0</version>
70 <version>2.65.0</version>
7171 </dependency>
7272 ```
7373 
from line 131
131131#### API model IDs
132132 
133133<Note>
134 Claude Fable 5.1, Claude Fable 5, Claude Opus 5, Claude Sonnet 5, Claude Opus 4.8, and Claude Opus 4.7 are reachable through `InvokeModel` on `bedrock-runtime`. These requests are served by the same infrastructure as the [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock) endpoint. For the native Messages API request shape and full feature parity, use that page. These models are omitted from the model table on this page because they do not have ARN-versioned model IDs.
134 Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, Claude Sonnet 5, Claude Opus 4.8, and Claude Opus 4.7 are reachable through `InvokeModel` on `bedrock-runtime`. These requests are served by the same infrastructure as the [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock) endpoint. For the native Messages API request shape and full feature parity, use that page. These models are omitted from the model table on this page because they do not have ARN-versioned model IDs.
135135</Note>
136136 
137137Lifecycle terms (Deprecated, Retired) are defined in [Model deprecations](https://platform.claude.com/docs/en/about-claude/model-deprecations). Lifecycle dates on partner-operated platforms are set by the partner and can differ from the Claude API schedule. For the current retirement date of any model on Amazon Bedrock, see [Amazon Bedrock's model lifecycle page](https://docs.aws.amazon.com/bedrock/latest/userguide/model-lifecycle.html).
from line 758
758758 
759759### Mid-conversation system messages on Bedrock
760760 
761[Mid-conversation system messages](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages) are available through the InvokeModel API for Claude Fable 5.1, Claude Fable 5, Claude Opus 5, and Claude Opus 4.8. As described in the note under [API model IDs](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy#api-model-ids), these requests are served by the same infrastructure as the [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock) endpoint. No beta header is required. This feature is not available on Claude Sonnet 5. Use the top-level `system` field instead. It is not available for the ARN-versioned models in the model table on this page.
761[Mid-conversation system messages](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages) are available through the InvokeModel API for Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, and Claude Opus 4.8. As described in the note under [API model IDs](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy#api-model-ids), these requests are served by the same infrastructure as the [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock) endpoint. No beta header is required. This feature is not available on Claude Sonnet 5. Use the top-level `system` field instead. It is not available for the ARN-versioned models in the model table on this page.
762762 
763763**For Converse API users:** the Converse API accepts system instructions through its top-level [`system` parameter](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html). To add system instructions mid-conversation, use the InvokeModel API.
764764 
765765### Context window
766766 
767Claude Fable 5.1, Claude Fable 5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, and Claude Sonnet 4.6 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 and Sonnet 4 (deprecated), have a 200k-token context window.
767Claude 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, and Claude Sonnet 4.6 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 and Sonnet 4 (deprecated), have a 200k-token context window.
768768 
769769Bedrock limits request payloads to 20 MB. When sending large documents or many images, you may reach this limit before the token limit.
770770 

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

from line 45
4545 <Tab title="Java">
4646 <CodeGroup exclude="shell, python, typescript, csharp, go, php, ruby">
4747 ```groovy Gradle
48 implementation("com.anthropic:anthropic-java:2.63.0")
49 implementation("com.anthropic:anthropic-java-vertex:2.63.0")
48 implementation("com.anthropic:anthropic-java:2.65.0")
49 implementation("com.anthropic:anthropic-java-vertex:2.65.0")
5050 ```
5151 
5252 ```xml Maven
from line 53
5353 <dependency>
5454 <groupId>com.anthropic</groupId>
5555 <artifactId>anthropic-java</artifactId>
56 <version>2.63.0</version>
56 <version>2.65.0</version>
5757 </dependency>
5858 <dependency>
5959 <groupId>com.anthropic</groupId>
6060 <artifactId>anthropic-java-vertex</artifactId>
61 <version>2.63.0</version>
61 <version>2.65.0</version>
6262 </dependency>
6363 ```
6464 
from line 76
7676 .build();
7777 
7878 MessageCreateParams params = MessageCreateParams.builder()
79 .model(Model.CLAUDE_OPUS_5)
79 .model(Model.CLAUDE_OPUS_5_5)
8080 .maxTokens(1024L)
8181 .addUserMessage("What is the capital of France?")
8282 .build();
from line 119
119119| :--------------------------------------------------------------------------------------------------- | :--------------------------- |
120120| Claude Fable 5.1 | `claude-fable-5-1` |
121121| Claude Fable 5 | `claude-fable-5` |
122| Claude Opus 5.5 | `claude-opus-5-5` |
122123| Claude Opus 5 | `claude-opus-5` |
123124| Claude Opus 4.8 | `claude-opus-4-8` |
124125| Claude Opus 4.7 | `claude-opus-4-7` |
from line 146
145146 
146147<CodeGroup>
147148 ```bash cURL
148 MODEL_ID=claude-opus-5
149 MODEL_ID=claude-opus-5-5
149150 PROJECT_ID=MY_PROJECT_ID
150151 
151152 curl https://aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/global/publishers/anthropic/models/${MODEL_ID}:rawPredict \
from line 172
171172 client = AnthropicVertex(project_id=project_id, region=region)
172173 
173174 message = client.messages.create(
174 model="claude-opus-5",
175 model="claude-opus-5-5",
175176 max_tokens=100,
176177 messages=[
177178 {
from line 197
196197 });
197198 
198199 const result = await client.messages.create({
199 model: "claude-opus-5",
200 model: "claude-opus-5-5",
200201 max_tokens: 100,
201202 messages: [
202203 {
from line 220
219220 
220221 var parameters = new MessageCreateParams
221222 {
222 Model = Model.ClaudeOpus5,
223 Model = Model.ClaudeOpus5_5,
223224 MaxTokens = 100,
224225 Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
225226 };
from line 244
243244 )
244245 
245246 message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
246 Model: anthropic.ModelClaudeOpus5,
247 Model: anthropic.ModelClaudeOpus5_5,
247248 MaxTokens: 100,
248249 Messages: []anthropic.MessageParam{
249250 anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
from line 274
273274 .messages()
274275 .create(
275276 MessageCreateParams.builder()
276 .model(Model.CLAUDE_OPUS_5)
277 .model(Model.CLAUDE_OPUS_5_5)
277278 .maxTokens(100)
278279 .addUserMessage("Hey Claude!")
279280 .build()
from line 299
298299 messages: [
299300 ['role' => 'user', 'content' => 'Hey Claude!']
300301 ],
301 model: 'claude-opus-5',
302 model: 'claude-opus-5-5',
302303 );
303304 $textBlock = array_find($message->content, static fn ($block): bool => $block->type === 'text');
304305 echo $textBlock->text;
from line 314
313314 )
314315 
315316 message = client.messages.create(
316 model: "claude-opus-5",
317 model: "claude-opus-5-5",
317318 max_tokens: 100,
318319 messages: [{role: "user", content: "Hey Claude!"}]
319320 )
from line 366
365366 
366367### Context window
367368 
368Claude Fable 5.1, Claude Fable 5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, and Claude Sonnet 4.6 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 and Sonnet 4 (deprecated), have a 200k-token context window.
369Claude 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, and Claude Sonnet 4.6 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 and Sonnet 4 (deprecated), have a 200k-token context window.
369370 
370371Agent Platform limits request payloads to 30 MB. When sending large documents or many images, you might reach this limit before the token limit.
371372 
from line 416
415416 
416417<CodeGroup>
417418 ```bash cURL
418 MODEL_ID=claude-opus-5
419 MODEL_ID=claude-opus-5-5
419420 PROJECT_ID=MY_PROJECT_ID
420421 
421422 curl https://aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/global/publishers/anthropic/models/${MODEL_ID}:rawPredict \
from line 442
441442 client = AnthropicVertex(project_id=project_id, region=region)
442443 
443444 message = client.messages.create(
444 model="claude-opus-5",
445 model="claude-opus-5-5",
445446 max_tokens=100,
446447 messages=[
447448 {
from line 466
465466 });
466467 
467468 const result = await client.messages.create({
468 model: "claude-opus-5",
469 model: "claude-opus-5-5",
469470 max_tokens: 100,
470471 messages: [
471472 {
from line 489
488489 
489490 var parameters = new MessageCreateParams
490491 {
491 Model = Model.ClaudeOpus5,
492 Model = Model.ClaudeOpus5_5,
492493 MaxTokens = 100,
493494 Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
494495 };
from line 513
512513 )
513514 
514515 message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
515 Model: anthropic.ModelClaudeOpus5,
516 Model: anthropic.ModelClaudeOpus5_5,
516517 MaxTokens: 100,
517518 Messages: []anthropic.MessageParam{
518519 anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
from line 549
548549 .messages()
549550 .create(
550551 MessageCreateParams.builder()
551 .model(Model.CLAUDE_OPUS_5)
552 .model(Model.CLAUDE_OPUS_5_5)
552553 .maxTokens(100)
553554 .addUserMessage("Hey Claude!")
554555 .build()
from line 574
573574 messages: [
574575 ['role' => 'user', 'content' => 'Hey Claude!']
575576 ],
576 model: 'claude-opus-5',
577 model: 'claude-opus-5-5',
577578 );
578579 
579580 $textBlock = array_find($message->content, static fn ($block): bool => $block->type === 'text');
from line 590
589590 )
590591 
591592 message = client.messages.create(
592 model: "claude-opus-5",
593 model: "claude-opus-5-5",
593594 max_tokens: 100,
594595 messages: [{role: "user", content: "Hey Claude!"}]
595596 )
from line 605
604605 
605606<CodeGroup>
606607 ```bash cURL
607 MODEL_ID=claude-opus-5
608 MODEL_ID=claude-opus-5-5
608609 LOCATION=us # Multi-region identifier: "us" or "eu"
609610 PROJECT_ID=MY_PROJECT_ID
610611 
from line 632
631632 client = AnthropicVertex(project_id=project_id, region=region)
632633 
633634 message = client.messages.create(
634 model="claude-opus-5",
635 model="claude-opus-5-5",
635636 max_tokens=100,
636637 messages=[
637638 {
from line 656
655656 });
656657 
657658 const result = await client.messages.create({
658 model: "claude-opus-5",
659 model: "claude-opus-5-5",
659660 max_tokens: 100,
660661 messages: [
661662 {
from line 679
678679 
679680 var parameters = new MessageCreateParams
680681 {
681 Model = Model.ClaudeOpus5,
682 Model = Model.ClaudeOpus5_5,
682683 MaxTokens = 100,
683684 Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
684685 };
from line 703
702703 )
703704 
704705 message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
705 Model: anthropic.ModelClaudeOpus5,
706 Model: anthropic.ModelClaudeOpus5_5,
706707 MaxTokens: 100,
707708 Messages: []anthropic.MessageParam{
708709 anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
from line 739
738739 .messages()
739740 .create(
740741 MessageCreateParams.builder()
741 .model(Model.CLAUDE_OPUS_5)
742 .model(Model.CLAUDE_OPUS_5_5)
742743 .maxTokens(100)
743744 .addUserMessage("Hey Claude!")
744745 .build()
from line 764
763764 messages: [
764765 ['role' => 'user', 'content' => 'Hey Claude!']
765766 ],
766 model: 'claude-opus-5',
767 model: 'claude-opus-5-5',
767768 );
768769 $textBlock = array_find($message->content, static fn ($block): bool => $block->type === 'text');
769770 echo $textBlock->text;
from line 779
778779 )
779780 
780781 message = client.messages.create(
781 model: "claude-opus-5",
782 model: "claude-opus-5-5",
782783 max_tokens: 100,
783784 messages: [{role: "user", content: "Hey Claude!"}]
784785 )

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

from line 305
305305 
306306 <Tab title="Java">
307307 ```kotlin Gradle
308 implementation("com.anthropic:anthropic-java:2.63.0")
309 implementation("com.anthropic:anthropic-java-aws:2.63.0")
308 implementation("com.anthropic:anthropic-java:2.65.0")
309 implementation("com.anthropic:anthropic-java-aws:2.65.0")
310310 ```
311311 
312312 ```xml Maven
from line 313
313313 <dependency>
314314 <groupId>com.anthropic</groupId>
315315 <artifactId>anthropic-java</artifactId>
316 <version>2.63.0</version>
316 <version>2.65.0</version>
317317 </dependency>
318318 <dependency>
319319 <groupId>com.anthropic</groupId>
320320 <artifactId>anthropic-java-aws</artifactId>
321 <version>2.63.0</version>
321 <version>2.65.0</version>
322322 </dependency>
323323 ```
324324 </Tab>
from line 348
348348| :---------------- | :------------------ |
349349| Claude Fable 5.1 | `claude-fable-5-1` |
350350| Claude Fable 5 | `claude-fable-5` |
351| Claude Opus 5.5 | `claude-opus-5-5` |
351352| Claude Opus 5 | `claude-opus-5` |
352353| Claude Opus 4.8 | `claude-opus-4-8` |
353354| Claude Opus 4.7 | `claude-opus-4-7` |
from line 802
801802 
802803The **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.
803804 
804| Page | Available | Through AWS gateway | Notes |
805| --------------------- | ------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
806| **Usage** | Yes | No | View token usage by model, workspace, and dimension. Data can take a few minutes to appear after a request. |
807| **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. |
808| **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). |
809| **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). |
810| **Encryption keys** | Yes | Yes | Under **Settings → Encryption keys**, register AWS KMS keys for [CMEK](https://platform.claude.com/docs/en/manage-claude/cmek-aws-kms#claude-platform-on-aws) (Admin role). Attach a registered key to a workspace from that workspace's **Security** settings. |
811| **Files** | Yes | Yes | View and manage uploaded files. |
812| **Skills** | Yes | Yes | View and manage Agent Skills. |
813| **Batches** | Yes | Yes | View and manage batch processing jobs. |
814| **Agents** | Yes | Yes | View and manage agent definitions. |
815| **Sessions** | Yes | Yes | View agent sessions and event history. |
816| **Environments** | Yes | Yes | View and manage cloud sandbox configurations for sessions. |
817| **Credential vaults** | Yes | Yes | View and manage credential vaults for session authentication. |
818| **Memory stores** | Yes | Yes | View and manage persistent agent memory. |
819| **Webhooks** | Yes | Yes | View and manage webhook endpoints under **Settings → Webhooks**. |
820| **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). |
821| **Members** | No | N/A | Not applicable. AWS IAM manages access. |
822| **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. |
823| **Claude Code** | No | N/A | View Claude Code usage on the Usage page. |
805| Page | Available | Through AWS gateway | Notes |
806| --------------------- | ------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
807| **Usage** | Yes | No | View token usage by model, workspace, and dimension. Data can take a few minutes to appear after a request. |
808| **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. |
809| **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). |
810| **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). |
811| **Encryption keys** | Yes | Yes | Under **Settings → Encryption keys**, register AWS KMS keys for [CMEK](https://platform.claude.com/docs/en/manage-claude/cmek-aws-kms#claude-platform-on-aws) (Admin role). To attach a registered key to a workspace, go to [Manage → Security](https://platform.claude.com/settings/workspaces/default/security-compliance) and select the workspace in the workspace picker at the top of the sidebar. |
812| **Files** | Yes | Yes | View and manage uploaded files. |
813| **Skills** | Yes | Yes | View and manage Agent Skills. |
814| **Batches** | Yes | Yes | View and manage batch processing jobs. |
815| **Agents** | Yes | Yes | View and manage agent definitions. |
816| **Sessions** | Yes | Yes | View agent sessions and event history. |
817| **Environments** | Yes | Yes | View and manage cloud sandbox configurations for sessions. |
818| **Credential vaults** | Yes | Yes | View and manage credential vaults for session authentication. |
819| **Memory stores** | Yes | Yes | View and manage persistent agent memory. |
820| **Webhooks** | Yes | Yes | View and manage webhook endpoints under **Settings → Webhooks**. |
821| **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). |
822| **Members** | No | N/A | Not applicable. AWS IAM manages access. |
823| **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. |
824| **Claude Code** | No | N/A | View Claude Code usage on the Usage page. |
824825 
825826### Switching organizations
826827 

build-with-claude/compaction-background Changed · +13 / -12 lines

from line 11
1111 - claude-fable-5
1212 - claude-mythos-5
1313 - claude-mythos-preview
14 - claude-opus-5-5
1415 - claude-opus-5
1516 - claude-opus-4-8
1617 - claude-opus-4-7
from line 93
9293 
9394 history.append({"role": "user", "content": question})
9495 response = client.beta.messages.create(
95 model="claude-opus-5",
96 model="claude-opus-5-5",
9697 max_tokens=8192,
9798 system=SYSTEM,
9899 betas=["compact-2026-09-04"],
from line 111
110111 sent = len(history)
111112 pending = executor.submit(
112113 client.beta.messages.create,
113 model="claude-opus-5",
114 model="claude-opus-5-5",
114115 max_tokens=4096,
115116 system=SYSTEM,
116117 betas=["compact-2026-09-04"],
from line 171
170171 
171172 history.push({ role: "user", content: question });
172173 const response = await client.beta.messages.create({
173 model: "claude-opus-5",
174 model: "claude-opus-5-5",
174175 max_tokens: 8192,
175176 system: systemPrompt,
176177 betas: ["compact-2026-09-04"],
from line 184
183184 if (conversationTokens > compactAtTokens && turn < questions.length && !pending) {
184185 sent = history.length;
185186 pending = client.beta.messages.create({
186 model: "claude-opus-5",
187 model: "claude-opus-5-5",
187188 max_tokens: 4096,
188189 system: systemPrompt,
189190 betas: ["compact-2026-09-04"],
from line 262
261262 history.Add(new() { Role = Role.User, Content = question });
262263 var response = await client.Beta.Messages.Create(new MessageCreateParams
263264 {
264 Model = Model.ClaudeOpus5,
265 Model = Model.ClaudeOpus5_5,
265266 MaxTokens = 8192,
266267 System = SystemPrompt,
267268 Betas = [AnthropicBeta.Compact2026_09_04],
from line 281
280281 sent = history.Count;
281282 pending = client.Beta.Messages.Create(new MessageCreateParams
282283 {
283 Model = Model.ClaudeOpus5,
284 Model = Model.ClaudeOpus5_5,
284285 MaxTokens = 4096,
285286 System = SystemPrompt,
286287 Betas = [AnthropicBeta.Compact2026_09_04],
from line 341
340341 
341342 history = append(history, anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock(question)))
342343 response, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
343 Model: anthropic.ModelClaudeOpus5,
344 Model: anthropic.ModelClaudeOpus5_5,
344345 MaxTokens: 8192,
345346 System: system,
346347 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaCompact2026_09_04},
from line 359
358359 pending = make(chan *anthropic.BetaMessage, 1)
359360 go func(messages []anthropic.BetaMessageParam, result chan<- *anthropic.BetaMessage) {
360361 summary, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
361 Model: anthropic.ModelClaudeOpus5,
362 Model: anthropic.ModelClaudeOpus5_5,
362363 MaxTokens: 4096,
363364 System: system,
364365 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaCompact2026_09_04},
from line 432
431432 .content(questions.get(turn - 1))
432433 .build());
433434 var params = MessageCreateParams.builder()
434 .model(Model.CLAUDE_OPUS_5)
435 .model(Model.CLAUDE_OPUS_5_5)
435436 .maxTokens(8192)
436437 .system(SYSTEM)
437438 .addBeta(AnthropicBeta.COMPACT_2026_09_04)
from line 446
445446 if (conversationTokens > COMPACT_AT_TOKENS && turn < questions.size() && pending == null) {
446447 sent = history.size();
447448 var summaryParams = MessageCreateParams.builder()
448 .model(Model.CLAUDE_OPUS_5)
449 .model(Model.CLAUDE_OPUS_5_5)
449450 .maxTokens(4096)
450451 .system(SYSTEM)
451452 .addBeta(AnthropicBeta.COMPACT_2026_09_04)
from line 502
501502 
502503 history << { role: "user", content: question }
503504 response = client.beta.messages.create(
504 model: Anthropic::Model::CLAUDE_OPUS_5,
505 model: Anthropic::Model::CLAUDE_OPUS_5_5,
505506 max_tokens: 8192,
506507 system_: SYSTEM,
507508 betas: [Anthropic::AnthropicBeta::COMPACT_2026_09_04],
from line 516
515516 sent = history.length
516517 pending = Thread.new(history.dup) do |snapshot|
517518 client.beta.messages.create(
518 model: Anthropic::Model::CLAUDE_OPUS_5,
519 model: Anthropic::Model::CLAUDE_OPUS_5_5,
519520 max_tokens: 4096,
520521 system_: SYSTEM,
521522 betas: [Anthropic::AnthropicBeta::COMPACT_2026_09_04],

build-with-claude/compaction-keep-recent-turns Changed · +16 / -15 lines

from line 11
1111 - claude-fable-5
1212 - claude-mythos-5
1313 - claude-mythos-preview
14 - claude-opus-5-5
1415 - claude-opus-5
1516 - claude-opus-4-8
1617 - claude-opus-4-7
from line 46
4546 
4647```json
4748{
48 "model": "claude-opus-5",
49 "model": "claude-opus-5-5",
4950 "max_tokens": 4096,
5051 "messages": [
5152 {
from line 92
9192 for turn, question in enumerate(QUESTIONS, start=1):
9293 history.append({"role": "user", "content": question})
9394 response = client.beta.messages.create(
94 model="claude-opus-5",
95 model="claude-opus-5-5",
9596 max_tokens=8192,
9697 system=SYSTEM,
9798 betas=["compact-2026-09-04"],
from line 108
107108 split = -2 * KEEP_TURNS
108109 older, recent = history[:split], history[split:]
109110 summary = client.beta.messages.create(
110 model="claude-opus-5",
111 model="claude-opus-5-5",
111112 max_tokens=4096,
112113 system=SYSTEM,
113114 betas=["compact-2026-09-04"],
from line 144
143144 const turn = index + 1;
144145 history.push({ role: "user", content: question });
145146 const response = await client.beta.messages.create({
146 model: "claude-opus-5",
147 model: "claude-opus-5-5",
147148 max_tokens: 8192,
148149 system: systemPrompt,
149150 betas: ["compact-2026-09-04"],
from line 159
158159 const older = history.slice(0, -2 * keepTurns);
159160 const recent = history.slice(-2 * keepTurns);
160161 const summary = await client.beta.messages.create({
161 model: "claude-opus-5",
162 model: "claude-opus-5-5",
162163 max_tokens: 4096,
163164 system: systemPrompt,
164165 betas: ["compact-2026-09-04"],
from line 205
204205 history.Add(new() { Role = Role.User, Content = question });
205206 var response = await client.Beta.Messages.Create(new MessageCreateParams
206207 {
207 Model = Model.ClaudeOpus5,
208 Model = Model.ClaudeOpus5_5,
208209 MaxTokens = 8192,
209210 System = SystemPrompt,
210211 Betas = [AnthropicBeta.Compact2026_09_04],
from line 226
225226 var recent = history[^(2 * KeepTurns)..];
226227 var summary = await client.Beta.Messages.Create(new MessageCreateParams
227228 {
228 Model = Model.ClaudeOpus5,
229 Model = Model.ClaudeOpus5_5,
229230 MaxTokens = 4096,
230231 System = SystemPrompt,
231232 Betas = [AnthropicBeta.Compact2026_09_04],
from line 275
274275 turn := i + 1
275276 history = append(history, anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock(question)))
276277 response, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
277 Model: anthropic.ModelClaudeOpus5,
278 Model: anthropic.ModelClaudeOpus5_5,
278279 MaxTokens: 8192,
279280 System: system,
280281 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaCompact2026_09_04},
from line 293
292293 split := len(history) - 2*keepTurns
293294 older, recent := history[:split], history[split:]
294295 summary, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
295 Model: anthropic.ModelClaudeOpus5,
296 Model: anthropic.ModelClaudeOpus5_5,
296297 MaxTokens: 4096,
297298 System: system,
298299 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaCompact2026_09_04},
from line 346
345346 .content(questions.get(turn - 1))
346347 .build());
347348 var params = MessageCreateParams.builder()
348 .model(Model.CLAUDE_OPUS_5)
349 .model(Model.CLAUDE_OPUS_5_5)
349350 .maxTokens(8192)
350351 .system(SYSTEM)
351352 .addBeta(AnthropicBeta.COMPACT_2026_09_04)
from line 361
360361 // A turn is one user message and one assistant reply, so the kept turns start with a user message.
361362 var older = history.subList(0, history.size() - 2 * KEEP_TURNS);
362363 var summaryParams = MessageCreateParams.builder()
363 .model(Model.CLAUDE_OPUS_5)
364 .model(Model.CLAUDE_OPUS_5_5)
364365 .maxTokens(4096)
365366 .system(SYSTEM)
366367 .addBeta(AnthropicBeta.COMPACT_2026_09_04)
from line 409
408409 $turn = $index + 1;
409410 $history[] = BetaMessageParam::with(role: Role::USER, content: $question);
410411 $response = $client->beta->messages->create(
411 model: Model::CLAUDE_OPUS_5,
412 model: Model::CLAUDE_OPUS_5_5,
412413 maxTokens: 8192,
413414 system: SYSTEM,
414415 betas: [AnthropicBeta::COMPACT_2026_09_04],
from line 424
423424 $older = array_slice($history, 0, -2 * KEEP_TURNS);
424425 $recent = array_slice($history, -2 * KEEP_TURNS);
425426 $summary = $client->beta->messages->create(
426 model: Model::CLAUDE_OPUS_5,
427 model: Model::CLAUDE_OPUS_5_5,
427428 maxTokens: 4096,
428429 system: SYSTEM,
429430 betas: [AnthropicBeta::COMPACT_2026_09_04],
from line 462
461462 questions.each.with_index(1) do |question, turn|
462463 history << { role: "user", content: question }
463464 response = client.beta.messages.create(
464 model: Anthropic::Model::CLAUDE_OPUS_5,
465 model: Anthropic::Model::CLAUDE_OPUS_5_5,
465466 max_tokens: 8192,
466467 system_: SYSTEM,
467468 betas: [Anthropic::AnthropicBeta::COMPACT_2026_09_04],
from line 476
475476 # A turn is one user message and one assistant reply, so the kept turns start with a user message.
476477 older, recent = history[...-2 * KEEP_TURNS], history.last(2 * KEEP_TURNS)
477478 summary = client.beta.messages.create(
478 model: Anthropic::Model::CLAUDE_OPUS_5,
479 model: Anthropic::Model::CLAUDE_OPUS_5_5,
479480 max_tokens: 4096,
480481 system_: SYSTEM,
481482 betas: [Anthropic::AnthropicBeta::COMPACT_2026_09_04],

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

from line 11
1111 - claude-fable-5
1212 - claude-mythos-5
1313 - claude-mythos-preview
14 - claude-opus-5-5
1415 - claude-opus-5
1516 - claude-opus-4-8
1617 - claude-opus-4-7
from line 51
5051 -H "anthropic-beta: compact-2026-09-04" \
5152 -H "content-type: application/json" \
5253 -d '{
53 "model": "claude-opus-5",
54 "model": "claude-opus-5-5",
5455 "max_tokens": 4096,
5556 "messages": [
5657 {"role": "user", "content": "I am building a recipe app. Help me name the main entities in the data model."},
from line 69
6869 
6970 <File filename="request.yaml">
7071 ```yaml
71 model: claude-opus-5
72 model: claude-opus-5-5
7273 # max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
7374 max_tokens: 4096
7475 messages:
from line 103
102103 ]
103104 
104105 response = client.beta.messages.create(
105 model="claude-opus-5",
106 model="claude-opus-5-5",
106107 # max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
107108 max_tokens=4096,
108109 betas=["compact-2026-09-04"],
from line 130
129130 ];
130131 
131132 const response = await client.beta.messages.create({
132 model: "claude-opus-5",
133 model: "claude-opus-5-5",
133134 // max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
134135 max_tokens: 4096,
135136 betas: ["compact-2026-09-04"],
from line 164
163164 
164165 var response = await client.Beta.Messages.Create(new MessageCreateParams
165166 {
166 Model = Model.ClaudeOpus5,
167 Model = Model.ClaudeOpus5_5,
167168 // max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
168169 MaxTokens = 4096,
169170 Betas = [AnthropicBeta.Compact2026_09_04],
from line 188
187188 }
188189 
189190 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
190 Model: anthropic.ModelClaudeOpus5,
191 Model: anthropic.ModelClaudeOpus5_5,
191192 // max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
192193 MaxTokens: 4096,
193194 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaCompact2026_09_04},
from line 212
211212 var client = AnthropicOkHttpClient.fromEnv();
212213 
213214 var params = MessageCreateParams.builder()
214 .model(Model.CLAUDE_OPUS_5)
215 .model(Model.CLAUDE_OPUS_5_5)
215216 // max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
216217 .maxTokens(4096)
217218 .addBeta(AnthropicBeta.COMPACT_2026_09_04)
from line 248
247248 ];
248249 
249250 $response = $client->beta->messages->create(
250 model: Model::CLAUDE_OPUS_5,
251 model: Model::CLAUDE_OPUS_5_5,
251252 // max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
252253 maxTokens: 4096,
253254 betas: [AnthropicBeta::COMPACT_2026_09_04],
from line 275
274275 ]
275276 
276277 response = client.beta.messages.create(
277 model: Anthropic::Model::CLAUDE_OPUS_5,
278 model: Anthropic::Model::CLAUDE_OPUS_5_5,
278279 # max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
279280 max_tokens: 4096,
280281 betas: [Anthropic::AnthropicBeta::COMPACT_2026_09_04],
from line 291
290291 "id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
291292 "type": "message",
292293 "role": "assistant",
293 "model": "claude-opus-5",
294 "model": "claude-opus-5-5",
294295 "content": [
295296 {
296297 "type": "compaction",
from line 320
319320 
320321```json
321322{
322 "model": "claude-opus-5",
323 "model": "claude-opus-5-5",
323324 "max_tokens": 2048,
324325 "messages": [
325326 {
from line 393
392393 for turn, question in enumerate(QUESTIONS, start=1):
393394 history.append({"role": "user", "content": question})
394395 response = client.beta.messages.create(
395 model="claude-opus-5",
396 model="claude-opus-5-5",
396397 max_tokens=8192,
397398 system=SYSTEM,
398399 betas=["compact-2026-09-04"],
from line 405
404405 conversation_tokens = response.usage.input_tokens + response.usage.output_tokens
405406 if conversation_tokens > COMPACT_AT_TOKENS and turn < len(QUESTIONS):
406407 summary = client.beta.messages.create(
407 model="claude-opus-5",
408 model="claude-opus-5-5",
408409 max_tokens=4096,
409410 system=SYSTEM,
410411 betas=["compact-2026-09-04"],
from line 440
439440 const turn = index + 1;
440441 history.push({ role: "user", content: question });
441442 const response = await client.beta.messages.create({
442 model: "claude-opus-5",
443 model: "claude-opus-5-5",
443444 max_tokens: 8192,
444445 system: systemPrompt,
445446 betas: ["compact-2026-09-04"],
from line 452
451452 const conversationTokens = response.usage.input_tokens + response.usage.output_tokens;
452453 if (conversationTokens > compactAtTokens && turn < questions.length) {
453454 const summary = await client.beta.messages.create({
454 model: "claude-opus-5",
455 model: "claude-opus-5-5",
455456 max_tokens: 4096,
456457 system: systemPrompt,
457458 betas: ["compact-2026-09-04"],
from line 497
496497 history.Add(new() { Role = Role.User, Content = question });
497498 var response = await client.Beta.Messages.Create(new MessageCreateParams
498499 {
499 Model = Model.ClaudeOpus5,
500 Model = Model.ClaudeOpus5_5,
500501 MaxTokens = 8192,
501502 System = SystemPrompt,
502503 Betas = [AnthropicBeta.Compact2026_09_04],
from line 515
514515 {
515516 var summary = await client.Beta.Messages.Create(new MessageCreateParams
516517 {
517 Model = Model.ClaudeOpus5,
518 Model = Model.ClaudeOpus5_5,
518519 MaxTokens = 4096,
519520 System = SystemPrompt,
520521 Betas = [AnthropicBeta.Compact2026_09_04],
from line 562
561562 turn := i + 1
562563 history = append(history, anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock(question)))
563564 response, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
564 Model: anthropic.ModelClaudeOpus5,
565 Model: anthropic.ModelClaudeOpus5_5,
565566 MaxTokens: 8192,
566567 System: system,
567568 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaCompact2026_09_04},
from line 577
576577 conversationTokens := response.Usage.InputTokens + response.Usage.OutputTokens
577578 if conversationTokens > compactAtTokens && turn < len(questions) {
578579 summary, err := client.Beta.Messages.New(ctx, anthropic.BetaMessageNewParams{
579 Model: anthropic.ModelClaudeOpus5,
580 Model: anthropic.ModelClaudeOpus5_5,
580581 MaxTokens: 4096,
581582 System: system,
582583 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaCompact2026_09_04},
from line 629
628629 .content(questions.get(turn - 1))
629630 .build());
630631 var params = MessageCreateParams.builder()
631 .model(Model.CLAUDE_OPUS_5)
632 .model(Model.CLAUDE_OPUS_5_5)
632633 .maxTokens(8192)
633634 .system(SYSTEM)
634635 .addBeta(AnthropicBeta.COMPACT_2026_09_04)
from line 642
641642 long conversationTokens = response.usage().inputTokens() + response.usage().outputTokens();
642643 if (conversationTokens > COMPACT_AT_TOKENS && turn < questions.size()) {
643644 var summaryParams = MessageCreateParams.builder()
644 .model(Model.CLAUDE_OPUS_5)
645 .model(Model.CLAUDE_OPUS_5_5)
645646 .maxTokens(4096)
646647 .system(SYSTEM)
647648 .addBeta(AnthropicBeta.COMPACT_2026_09_04)
from line 689
688689 $turn = $index + 1;
689690 $history[] = BetaMessageParam::with(role: Role::USER, content: $question);
690691 $response = $client->beta->messages->create(
691 model: Model::CLAUDE_OPUS_5,
692 model: Model::CLAUDE_OPUS_5_5,
692693 maxTokens: 8192,
693694 system: SYSTEM,
694695 betas: [AnthropicBeta::COMPACT_2026_09_04],
from line 701
700701 $conversationTokens = $response->usage->inputTokens + $response->usage->outputTokens;
701702 if ($conversationTokens > COMPACT_AT_TOKENS && $turn < count($questions)) {
702703 $summary = $client->beta->messages->create(
703 model: Model::CLAUDE_OPUS_5,
704 model: Model::CLAUDE_OPUS_5_5,
704705 maxTokens: 4096,
705706 system: SYSTEM,
706707 betas: [AnthropicBeta::COMPACT_2026_09_04],
from line 738
737738 questions.each.with_index(1) do |question, turn|
738739 history << { role: "user", content: question }
739740 response = client.beta.messages.create(
740 model: Anthropic::Model::CLAUDE_OPUS_5,
741 model: Anthropic::Model::CLAUDE_OPUS_5_5,
741742 max_tokens: 8192,
742743 system_: SYSTEM,
743744 betas: [Anthropic::AnthropicBeta::COMPACT_2026_09_04],
from line 750
749750 conversation_tokens = response.usage.input_tokens + response.usage.output_tokens
750751 if conversation_tokens > COMPACT_AT_TOKENS && turn < questions.length
751752 summary = client.beta.messages.create(
752 model: Anthropic::Model::CLAUDE_OPUS_5,
753 model: Anthropic::Model::CLAUDE_OPUS_5_5,
753754 max_tokens: 4096,
754755 system_: SYSTEM,
755756 betas: [Anthropic::AnthropicBeta::COMPACT_2026_09_04],

build-with-claude/compaction-threshold Changed · +122 / -121 lines

from line 14
1414 - claude-fable-5
1515 - claude-mythos-5
1616 - claude-mythos-preview
17 - claude-opus-5-5
1718 - claude-opus-5
1819 - claude-opus-4-8
1920 - claude-opus-4-7
from line 67
6667 -H "anthropic-beta: compact-2026-01-12" \
6768 -H "content-type: application/json" \
6869 -d '{
69 "model": "claude-opus-5",
70 "model": "claude-opus-5-5",
7071 "max_tokens": 4096,
7172 "messages": [
7273 {
from line 87
8687 
8788 ```bash CLI
8889 ant beta:messages create --beta compact-2026-01-12 <<'YAML'
89 model: claude-opus-5
90 model: claude-opus-5-5
9091 max_tokens: 4096
9192 messages:
9293 - role: user
from line 105
104105 
105106 response = client.beta.messages.create(
106107 betas=["compact-2026-01-12"],
107 model="claude-opus-5",
108 model="claude-opus-5-5",
108109 max_tokens=4096,
109110 messages=messages,
110111 context_management={"edits": [{"type": "compact_20260112"}]},
from line 124
123124 
124125 const response = await client.beta.messages.create({
125126 betas: ["compact-2026-01-12"],
126 model: "claude-opus-5",
127 model: "claude-opus-5-5",
127128 max_tokens: 4096,
128129 messages,
129130 context_management: {
from line 154
153154 var parameters = new MessageCreateParams
154155 {
155156 Betas = ["compact-2026-01-12"],
156 Model = "claude-opus-5",
157 Model = "claude-opus-5-5",
157158 MaxTokens = 4096,
158159 Messages = messages,
159160 ContextManagement = new BetaContextManagementConfig
from line 183
182183 }
183184 
184185 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
185 Model: anthropic.ModelClaudeOpus5,
186 Model: anthropic.ModelClaudeOpus5_5,
186187 MaxTokens: 4096,
187188 Messages: messages,
188189 ContextManagement: anthropic.BetaContextManagementConfigParam{
from line 211
210211 
211212 MessageCreateParams params = MessageCreateParams.builder()
212213 .addBeta("compact-2026-01-12")
213 .model("claude-opus-5")
214 .model("claude-opus-5-5")
214215 .maxTokens(4096L)
215216 .addUserMessage("Help me build a website")
216217 .contextManagement(BetaContextManagementConfig.builder()
from line 236
235236 $response = $client->beta->messages->create(
236237 maxTokens: 4096,
237238 messages: $messages,
238 model: 'claude-opus-5',
239 model: 'claude-opus-5-5',
239240 betas: ['compact-2026-01-12'],
240241 contextManagement: [
241242 'edits' => [
from line 260
259260 
260261 response = client.beta.messages.create(
261262 betas: ["compact-2026-01-12"],
262 model: "claude-opus-5",
263 model: "claude-opus-5-5",
263264 max_tokens: 4096,
264265 messages: messages,
265266 context_management: {
from line 296
295296 -H "anthropic-beta: compact-2026-01-12" \
296297 -H "content-type: application/json" \
297298 -d '{
298 "model": "claude-opus-5",
299 "model": "claude-opus-5-5",
299300 "max_tokens": 4096,
300301 "messages": [
301302 {
from line 320
319320 
320321 ```bash CLI
321322 ant beta:messages create --beta compact-2026-01-12 <<'YAML'
322 model: claude-opus-5
323 model: claude-opus-5-5
323324 max_tokens: 4096
324325 messages:
325326 - role: user
from line 339
338339 messages = [{"role": "user", "content": "Hello, Claude"}]
339340 response = client.beta.messages.create(
340341 betas=["compact-2026-01-12"],
341 model="claude-opus-5",
342 model="claude-opus-5-5",
342343 max_tokens=4096,
343344 messages=messages,
344345 context_management={
from line 361
360361 
361362 const response = await client.beta.messages.create({
362363 betas: ["compact-2026-01-12"],
363 model: "claude-opus-5",
364 model: "claude-opus-5-5",
364365 max_tokens: 4096,
365366 messages,
366367 context_management: {
from line 384
383384 
384385 var parameters = new MessageCreateParams
385386 {
386 Model = "claude-opus-5",
387 Model = "claude-opus-5-5",
387388 MaxTokens = 4096,
388389 Betas = ["compact-2026-01-12"],
389390 Messages = messages,
from line 406
405406 messages := []anthropic.BetaMessageParam{anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello, Claude"))}
406407 
407408 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
408 Model: anthropic.ModelClaudeOpus5,
409 Model: anthropic.ModelClaudeOpus5_5,
409410 MaxTokens: 4096,
410411 Messages: messages,
411412 ContextManagement: anthropic.BetaContextManagementConfigParam{
from line 432
431432 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
432433 
433434 MessageCreateParams params = MessageCreateParams.builder()
434 .model("claude-opus-5")
435 .model("claude-opus-5-5")
435436 .maxTokens(4096L)
436437 .addBeta("compact-2026-01-12")
437438 .addUserMessage("Hello, Claude")
from line 456
455456 $message = $client->beta->messages->create(
456457 maxTokens: 4096,
457458 messages: $messages,
458 model: 'claude-opus-5',
459 model: 'claude-opus-5-5',
459460 betas: ['compact-2026-01-12'],
460461 contextManagement: [
461462 'edits' => [
from line 480
479480 
480481 response = client.beta.messages.create(
481482 betas: ["compact-2026-01-12"],
482 model: "claude-opus-5",
483 model: "claude-opus-5-5",
483484 max_tokens: 4096,
484485 messages: messages,
485486 context_management: {
from line 517
516517 -H "anthropic-beta: compact-2026-01-12" \
517518 -H "content-type: application/json" \
518519 -d '{
519 "model": "claude-opus-5",
520 "model": "claude-opus-5-5",
520521 "max_tokens": 4096,
521522 "messages": [
522523 {
from line 538
537538 
538539 ```bash CLI
539540 ant beta:messages create --beta compact-2026-01-12 <<'YAML'
540 model: claude-opus-5
541 model: claude-opus-5-5
541542 max_tokens: 4096
542543 messages:
543544 - role: user
from line 557
556557 messages = [{"role": "user", "content": "Hello, Claude"}]
557558 response = client.beta.messages.create(
558559 betas=["compact-2026-01-12"],
559 model="claude-opus-5",
560 model="claude-opus-5-5",
560561 max_tokens=4096,
561562 messages=messages,
562563 context_management={
from line 579
578579 
579580 const response = await client.beta.messages.create({
580581 betas: ["compact-2026-01-12"],
581 model: "claude-opus-5",
582 model: "claude-opus-5-5",
582583 max_tokens: 4096,
583584 messages,
584585 context_management: {
from line 600
599600 var parameters = new MessageCreateParams
600601 {
601602 Betas = ["compact-2026-01-12"],
602 Model = "claude-opus-5",
603 Model = "claude-opus-5-5",
603604 MaxTokens = 4096,
604605 Messages =
605606 [
from line 625
624625 client := anthropic.NewClient()
625626 
626627 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
627 Model: anthropic.ModelClaudeOpus5,
628 Model: anthropic.ModelClaudeOpus5_5,
628629 MaxTokens: 4096,
629630 Messages: []anthropic.BetaMessageParam{
630631 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Help me build a Python web scraper")),
from line 655
654655 
655656 MessageCreateParams params = MessageCreateParams.builder()
656657 .addBeta("compact-2026-01-12")
657 .model("claude-opus-5")
658 .model("claude-opus-5-5")
658659 .maxTokens(4096L)
659660 .addUserMessage("Help me build a Python web scraper")
660661 .addAssistantMessage("I'll help you build a web scraper...")
from line 681
680681 ['role' => 'assistant', 'content' => "I'll help you build a web scraper..."],
681682 ['role' => 'user', 'content' => 'Add support for JavaScript-rendered pages']
682683 ],
683 model: 'claude-opus-5',
684 model: 'claude-opus-5-5',
684685 betas: ['compact-2026-01-12'],
685686 contextManagement: [
686687 'edits' => [
from line 701
700701 
701702 response = client.beta.messages.create(
702703 betas: ["compact-2026-01-12"],
703 model: "claude-opus-5",
704 model: "claude-opus-5-5",
704705 max_tokens: 4096,
705706 messages: [
706707 { role: "user", content: "Help me build a Python web scraper" },
from line 743
742743 -H "anthropic-beta: compact-2026-01-12" \
743744 -H "content-type: application/json" \
744745 -d '{
745 "model": "claude-opus-5",
746 "model": "claude-opus-5-5",
746747 "max_tokens": 4096,
747748 "messages": [
748749 {
from line 768
767768 # step doesn't translate well to a one-off CLI command; see the SDK tabs
768769 # for the full pause-and-continue flow. Single paused request:
769770 ant beta:messages create --beta compact-2026-01-12 --format jsonl <<'YAML'
770 model: claude-opus-5
771 model: claude-opus-5-5
771772 max_tokens: 4096
772773 messages:
773774 - role: user
from line 785
784785 messages = [{"role": "user", "content": "Hello, Claude"}]
785786 response = client.beta.messages.create(
786787 betas=["compact-2026-01-12"],
787 model="claude-opus-5",
788 model="claude-opus-5-5",
788789 max_tokens=4096,
789790 messages=messages,
790791 context_management={
from line 801
800801 # Continue the request
801802 response = client.beta.messages.create(
802803 betas=["compact-2026-01-12"],
803 model="claude-opus-5",
804 model="claude-opus-5-5",
804805 max_tokens=4096,
805806 messages=messages,
806807 context_management={"edits": [{"type": "compact_20260112"}]},
from line 816
815816 
816817 let response = await client.beta.messages.create({
817818 betas: ["compact-2026-01-12"],
818 model: "claude-opus-5",
819 model: "claude-opus-5-5",
819820 max_tokens: 4096,
820821 messages,
821822 context_management: {
from line 840
839840 // Continue the request
840841 response = await client.beta.messages.create({
841842 betas: ["compact-2026-01-12"],
842 model: "claude-opus-5",
843 model: "claude-opus-5-5",
843844 max_tokens: 4096,
844845 messages,
845846 context_management: {
from line 859
858859 
859860 var parameters = new MessageCreateParams
860861 {
861 Model = "claude-opus-5",
862 Model = "claude-opus-5-5",
862863 MaxTokens = 4096,
863864 Betas = ["compact-2026-01-12"],
864865 Messages = messages,
from line 884
883884 
884885 parameters = new()
885886 {
886 Model = "claude-opus-5",
887 Model = "claude-opus-5-5",
887888 MaxTokens = 4096,
888889 Betas = ["compact-2026-01-12"],
889890 Messages = messages,
from line 913
912913 }
913914 
914915 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
915 Model: anthropic.ModelClaudeOpus5,
916 Model: anthropic.ModelClaudeOpus5_5,
916917 MaxTokens: 4096,
917918 Messages: messages,
918919 ContextManagement: compactEdit,
from line 927
926927 messages = append(messages, response.ToParam())
927928 
928929 response, err = client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
929 Model: anthropic.ModelClaudeOpus5,
930 Model: anthropic.ModelClaudeOpus5_5,
930931 MaxTokens: 4096,
931932 Messages: messages,
932933 ContextManagement: anthropic.BetaContextManagementConfigParam{
from line 953
952953 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
953954 
954955 MessageCreateParams params = MessageCreateParams.builder()
955 .model("claude-opus-5")
956 .model("claude-opus-5-5")
956957 .maxTokens(4096L)
957958 .addBeta("compact-2026-01-12")
958959 .addUserMessage("Help me build a website")
from line 972
971972 // Append the compaction block and continue the request
972973 // by building a new request with the compacted context
973974 MessageCreateParams continueParams = MessageCreateParams.builder()
974 .model("claude-opus-5")
975 .model("claude-opus-5-5")
975976 .maxTokens(4096L)
976977 .addBeta("compact-2026-01-12")
977978 .addUserMessage("Help me build a website")
from line 995
994995 $response = $client->beta->messages->create(
995996 maxTokens: 4096,
996997 messages: $messages,
997 model: 'claude-opus-5',
998 model: 'claude-opus-5-5',
998999 betas: ['compact-2026-01-12'],
9991000 contextManagement: [
10001001 'edits' => [
from line 1016
10151016 $response = $client->beta->messages->create(
10161017 maxTokens: 4096,
10171018 messages: $messages,
1018 model: 'claude-opus-5',
1019 model: 'claude-opus-5-5',
10191020 betas: ['compact-2026-01-12'],
10201021 contextManagement: [
10211022 'edits' => [
from line 1035
10341035 
10351036 response = client.beta.messages.create(
10361037 betas: ["compact-2026-01-12"],
1037 model: "claude-opus-5",
1038 model: "claude-opus-5-5",
10381039 max_tokens: 4096,
10391040 messages: messages,
10401041 context_management: {
from line 1053
10521053 
10531054 response = client.beta.messages.create(
10541055 betas: ["compact-2026-01-12"],
1055 model: "claude-opus-5",
1056 model: "claude-opus-5-5",
10561057 max_tokens: 4096,
10571058 messages: messages,
10581059 context_management: {
from line 1082
10811082 
10821083 response = client.beta.messages.create(
10831084 betas=["compact-2026-01-12"],
1084 model="claude-opus-5",
1085 model="claude-opus-5-5",
10851086 max_tokens=4096,
10861087 messages=messages,
10871088 context_management={
from line 1121
11201121 
11211122 const response = await client.beta.messages.create({
11221123 betas: ["compact-2026-01-12"],
1123 model: "claude-opus-5",
1124 model: "claude-opus-5-5",
11241125 max_tokens: 4096,
11251126 messages,
11261127 context_management: {
from line 1160
11591160 var response = await client.Beta.Messages.Create(new()
11601161 {
11611162 Betas = ["compact-2026-01-12"],
1162 Model = "claude-opus-5",
1163 Model = "claude-opus-5-5",
11631164 MaxTokens = 4096,
11641165 Messages = messages,
11651166 ContextManagement = new BetaContextManagementConfig
from line 1205
12041205 compactionCount := 0
12051206 
12061207 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
1207 Model: anthropic.ModelClaudeOpus5,
1208 Model: anthropic.ModelClaudeOpus5_5,
12081209 MaxTokens: 4096,
12091210 Messages: messages,
12101211 ContextManagement: anthropic.BetaContextManagementConfigParam{
from line 1255
12541255 
12551256 MessageCreateParams params = MessageCreateParams.builder()
12561257 .addBeta("compact-2026-01-12")
1257 .model("claude-opus-5")
1258 .model("claude-opus-5-5")
12581259 .maxTokens(4096L)
12591260 .messages(messages)
12601261 .contextManagement(BetaContextManagementConfig.builder()
from line 1299
12981299 $response = $client->beta->messages->create(
12991300 maxTokens: 4096,
13001301 messages: $messages,
1301 model: 'claude-opus-5',
1302 model: 'claude-opus-5-5',
13021303 betas: ['compact-2026-01-12'],
13031304 contextManagement: [
13041305 'edits' => [
from line 1335
13341335 
13351336 response = client.beta.messages.create(
13361337 betas: ["compact-2026-01-12"],
1337 model: "claude-opus-5",
1338 model: "claude-opus-5-5",
13381339 max_tokens: 4096,
13391340 messages: messages,
13401341 context_management: {
from line 1401
14001401 -H "anthropic-beta: compact-2026-01-12" \
14011402 -H "content-type: application/json" \
14021403 -d '{
1403 "model": "claude-opus-5",
1404 "model": "claude-opus-5-5",
14041405 "max_tokens": 4096,
14051406 "messages": [
14061407 {
from line 1424
14231424 --beta compact-2026-01-12 \
14241425 --transform content \
14251426 --format jsonl <<'YAML' > content.json
1426 model: claude-opus-5
1427 model: claude-opus-5-5
14271428 max_tokens: 4096
14281429 messages:
14291430 - role: user
from line 1437
14361437 # After receiving a response with a compaction block, append it as the
14371438 # assistant turn and continue the conversation
14381439 ant beta:messages create --beta compact-2026-01-12 <<YAML
1439 model: claude-opus-5
1440 model: claude-opus-5-5
14401441 max_tokens: 4096
14411442 messages:
14421443 - role: user
from line 1457
14561457 messages = [{"role": "user", "content": "Hello, Claude"}]
14571458 response = client.beta.messages.create(
14581459 betas=["compact-2026-01-12"],
1459 model="claude-opus-5",
1460 model="claude-opus-5-5",
14601461 max_tokens=4096,
14611462 messages=messages,
14621463 context_management={"edits": [{"type": "compact_20260112"}]},
from line 1470
14691470 
14701471 response = client.beta.messages.create(
14711472 betas=["compact-2026-01-12"],
1472 model="claude-opus-5",
1473 model="claude-opus-5-5",
14731474 max_tokens=4096,
14741475 messages=messages,
14751476 context_management={"edits": [{"type": "compact_20260112"}]},
from line 1485
14841485 
14851486 const response = await client.beta.messages.create({
14861487 betas: ["compact-2026-01-12"],
1487 model: "claude-opus-5",
1488 model: "claude-opus-5-5",
14881489 max_tokens: 4096,
14891490 messages,
14901491 context_management: {
from line 1504
15031504 
15041505 const nextResponse = await client.beta.messages.create({
15051506 betas: ["compact-2026-01-12"],
1506 model: "claude-opus-5",
1507 model: "claude-opus-5-5",
15071508 max_tokens: 4096,
15081509 messages,
15091510 context_management: {
from line 1524
15231524 var response = await client.Beta.Messages.Create(new()
15241525 {
15251526 Betas = ["compact-2026-01-12"],
1526 Model = "claude-opus-5",
1527 Model = "claude-opus-5-5",
15271528 MaxTokens = 4096,
15281529 Messages = messages,
15291530 ContextManagement = new BetaContextManagementConfig
from line 1544
15431544 var nextResponse = await client.Beta.Messages.Create(new()
15441545 {
15451546 Betas = ["compact-2026-01-12"],
1546 Model = "claude-opus-5",
1547 Model = "claude-opus-5-5",
15471548 MaxTokens = 4096,
15481549 Messages = messages,
15491550 ContextManagement = new BetaContextManagementConfig
from line 1570
15691570 }
15701571 
15711572 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
1572 Model: anthropic.ModelClaudeOpus5,
1573 Model: anthropic.ModelClaudeOpus5_5,
15731574 MaxTokens: 4096,
15741575 Messages: messages,
15751576 ContextManagement: compactEdit,
from line 1585
15841585 messages = append(messages, anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Now add error handling")))
15851586 
15861587 nextResponse, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
1587 Model: anthropic.ModelClaudeOpus5,
1588 Model: anthropic.ModelClaudeOpus5_5,
15881589 MaxTokens: 4096,
15891590 Messages: messages,
15901591 ContextManagement: compactEdit,
from line 1608
16071608 BetaMessage response = client.beta().messages().create(
16081609 MessageCreateParams.builder()
16091610 .addBeta("compact-2026-01-12")
1610 .model("claude-opus-5")
1611 .model("claude-opus-5-5")
16111612 .maxTokens(4096L)
16121613 .addUserMessage("Help me build a web scraper")
16131614 .contextManagement(BetaContextManagementConfig.builder()
from line 1621
16201621 BetaMessage nextResponse = client.beta().messages().create(
16211622 MessageCreateParams.builder()
16221623 .addBeta("compact-2026-01-12")
1623 .model("claude-opus-5")
1624 .model("claude-opus-5-5")
16241625 .maxTokens(4096L)
16251626 .addUserMessage("Help me build a web scraper")
16261627 .addMessage(response)
from line 1644
16431644 $response = $client->beta->messages->create(
16441645 maxTokens: 4096,
16451646 messages: $messages,
1646 model: 'claude-opus-5',
1647 model: 'claude-opus-5-5',
16471648 betas: ['compact-2026-01-12'],
16481649 contextManagement: [
16491650 'edits' => [['type' => 'compact_20260112']]
from line 1658
16571658 $nextResponse = $client->beta->messages->create(
16581659 maxTokens: 4096,
16591660 messages: $messages,
1660 model: 'claude-opus-5',
1661 model: 'claude-opus-5-5',
16611662 betas: ['compact-2026-01-12'],
16621663 contextManagement: [
16631664 'edits' => [['type' => 'compact_20260112']]
from line 1677
16761677 
16771678 response = client.beta.messages.create(
16781679 betas: ["compact-2026-01-12"],
1679 model: "claude-opus-5",
1680 model: "claude-opus-5-5",
16801681 max_tokens: 4096,
16811682 messages: messages,
16821683 context_management: {
from line 1691
16901691 
16911692 next_response = client.beta.messages.create(
16921693 betas: ["compact-2026-01-12"],
1693 model: "claude-opus-5",
1694 model: "claude-opus-5-5",
16941695 max_tokens: 4096,
16951696 messages: messages,
16961697 context_management: {
from line 1710
17091710* Keep the original messages in your list and let the API handle removing the compacted content
17101711* Manually drop the compacted messages and only include the compaction block onwards
17111712 
1712On Claude Fable 5.1 and Claude Mythos 5.1, 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).
1713On Claude Fable 5.1, Claude Mythos 5.1, and Claude Opus 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).
17131714 
17141715### Streaming
17151716 
from line 1724
17231724 -H "anthropic-beta: compact-2026-01-12" \
17241725 -H "content-type: application/json" \
17251726 -d '{
1726 "model": "claude-opus-5",
1727 "model": "claude-opus-5-5",
17271728 "max_tokens": 4096,
17281729 "stream": true,
17291730 "messages": [
from line 1748
17471748 --stream \
17481749 --beta compact-2026-01-12 \
17491750 --format jsonl <<'YAML'
1750 model: claude-opus-5
1751 model: claude-opus-5-5
17511752 max_tokens: 4096
17521753 messages:
17531754 - role: user
from line 1765
17641765 
17651766 with client.beta.messages.stream(
17661767 betas=["compact-2026-01-12"],
1767 model="claude-opus-5",
1768 model="claude-opus-5-5",
17681769 max_tokens=4096,
17691770 messages=messages,
17701771 context_management={"edits": [{"type": "compact_20260112"}]},
from line 1801
18001801 
18011802 const stream = await client.beta.messages.stream({
18021803 betas: ["compact-2026-01-12"],
1803 model: "claude-opus-5",
1804 model: "claude-opus-5-5",
18041805 max_tokens: 4096,
18051806 messages,
18061807 context_management: {
from line 1849
18481849 var parameters = new MessageCreateParams
18491850 {
18501851 Betas = ["compact-2026-01-12"],
1851 Model = "claude-opus-5",
1852 Model = "claude-opus-5-5",
18521853 MaxTokens = 4096,
18531854 Messages = messages,
18541855 ContextManagement = new BetaContextManagementConfig
from line 1890
18891890 messages := []anthropic.BetaMessageParam{anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello, Claude"))}
18901891 
18911892 stream := client.Beta.Messages.NewStreaming(context.TODO(), anthropic.BetaMessageNewParams{
1892 Model: anthropic.ModelClaudeOpus5,
1893 Model: anthropic.ModelClaudeOpus5_5,
18931894 MaxTokens: 4096,
18941895 Messages: messages,
18951896 ContextManagement: anthropic.BetaContextManagementConfigParam{
from line 1932
19311932 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
19321933 
19331934 MessageCreateParams params = MessageCreateParams.builder()
1934 .model("claude-opus-5")
1935 .model("claude-opus-5-5")
19351936 .maxTokens(4096L)
19361937 .addBeta("compact-2026-01-12")
19371938 .addUserMessage("Hello, Claude")
from line 1978
19771978 $stream = $client->beta->messages->createStream(
19781979 maxTokens: 4096,
19791980 messages: $messages,
1980 model: 'claude-opus-5',
1981 model: 'claude-opus-5-5',
19811982 betas: ['compact-2026-01-12'],
19821983 contextManagement: [
19831984 'edits' => [
from line 2019
20182019 
20192020 stream = client.beta.messages.stream(
20202021 betas: ["compact-2026-01-12"],
2021 model: "claude-opus-5",
2022 model: "claude-opus-5-5",
20222023 max_tokens: 4096,
20232024 messages: messages,
20242025 context_management: {
from line 2087
20862087 -H "anthropic-beta: compact-2026-01-12" \
20872088 -H "content-type: application/json" \
20882089 -d '{
2089 "model": "claude-opus-5",
2090 "model": "claude-opus-5-5",
20902091 "max_tokens": 4096,
20912092 "system": [
20922093 {
from line 2116
21152116 
21162117 ```bash CLI
21172118 ant beta:messages create --beta compact-2026-01-12 <<'YAML'
2118 model: claude-opus-5
2119 model: claude-opus-5-5
21192120 max_tokens: 4096
21202121 system:
21212122 - type: text
from line 2137
21362137 messages = [{"role": "user", "content": "Hello, Claude"}]
21372138 response = client.beta.messages.create(
21382139 betas=["compact-2026-01-12"],
2139 model="claude-opus-5",
2140 model="claude-opus-5-5",
21402141 max_tokens=4096,
21412142 system=[
21422143 {
from line 2161
21602161 
21612162 const response = await client.beta.messages.create({
21622163 betas: ["compact-2026-01-12"],
2163 model: "claude-opus-5",
2164 model: "claude-opus-5-5",
21642165 max_tokens: 4096,
21652166 system: [
21662167 {
from line 2183
21822183 var parameters = new MessageCreateParams
21832184 {
21842185 Betas = ["compact-2026-01-12"],
2185 Model = "claude-opus-5",
2186 Model = "claude-opus-5-5",
21862187 MaxTokens = 4096,
21872188 System = new List<BetaTextBlockParam>
21882189 {
from line 2208
22072208 client := anthropic.NewClient()
22082209 
22092210 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
2210 Model: anthropic.ModelClaudeOpus5,
2211 Model: anthropic.ModelClaudeOpus5_5,
22112212 MaxTokens: 4096,
22122213 System: []anthropic.BetaTextBlockParam{
22132214 {
from line 2238
22372238 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
22382239 
22392240 MessageCreateParams params = MessageCreateParams.builder()
2240 .model("claude-opus-5")
2241 .model("claude-opus-5-5")
22412242 .maxTokens(4096L)
22422243 .addBeta("compact-2026-01-12")
22432244 .systemOfBetaTextBlockParams(List.of(
from line 2263
22622263 $response = $client->beta->messages->create(
22632264 maxTokens: 4096,
22642265 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
2265 model: 'claude-opus-5',
2266 model: 'claude-opus-5-5',
22662267 betas: ['compact-2026-01-12'],
22672268 system: [
22682269 [
from line 2289
22882289 
22892290 response = client.beta.messages.create(
22902291 betas: ["compact-2026-01-12"],
2291 model: "claude-opus-5",
2292 model: "claude-opus-5-5",
22922293 max_tokens: 4096,
22932294 system: [
22942295 {
from line 2362
23612362 -H "anthropic-beta: compact-2026-01-12" \
23622363 -H "content-type: application/json" \
23632364 -d '{
2364 "model": "claude-opus-5",
2365 "model": "claude-opus-5-5",
23652366 "messages": [
23662367 {
23672368 "role": "user",
from line 2381
23802381 
23812382 ```bash CLI
23822383 cat > request.yaml <<'YAML'
2383 model: claude-opus-5
2384 model: claude-opus-5-5
23842385 messages:
23852386 - role: user
23862387 content: Hello, Claude
from line 2409
24082409 messages = [{"role": "user", "content": "Hello, Claude"}]
24092410 count_response = client.beta.messages.count_tokens(
24102411 betas=["compact-2026-01-12"],
2411 model="claude-opus-5",
2412 model="claude-opus-5-5",
24122413 messages=messages,
24132414 context_management={"edits": [{"type": "compact_20260112"}]},
24142415 )
from line 2426
24252426 
24262427 const countResponse = await client.beta.messages.countTokens({
24272428 betas: ["compact-2026-01-12"],
2428 model: "claude-opus-5",
2429 model: "claude-opus-5-5",
24292430 messages,
24302431 context_management: {
24312432 edits: [{ type: "compact_20260112" }]
from line 2443
24422443 
24432444 var countParams = new MessageCountTokensParams
24442445 {
2445 Model = "claude-opus-5",
2446 Model = "claude-opus-5-5",
24462447 Messages = messages,
24472448 ContextManagement = new BetaContextManagementConfig
24482449 {
from line 2462
24612462 messages := []anthropic.BetaMessageParam{anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello, Claude"))}
24622463 
24632464 countResponse, err := client.Beta.Messages.CountTokens(context.TODO(), anthropic.BetaMessageCountTokensParams{
2464 Model: anthropic.ModelClaudeOpus5,
2465 Model: anthropic.ModelClaudeOpus5_5,
24652466 Messages: messages,
24662467 ContextManagement: anthropic.BetaContextManagementConfigParam{
24672468 Edits: []anthropic.BetaContextManagementConfigEditUnionParam{
from line 2488
24872488 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
24882489 
24892490 MessageCountTokensParams params = MessageCountTokensParams.builder()
2490 .model("claude-opus-5")
2491 .model("claude-opus-5-5")
24912492 .addUserMessage("Hello, Claude")
24922493 .contextManagement(BetaContextManagementConfig.builder()
24932494 .addEdit(BetaCompact20260112Edit.builder().build())
from line 2507
25062507 
25072508 $countResponse = $client->beta->messages->countTokens(
25082509 messages: $messages,
2509 model: 'claude-opus-5',
2510 model: 'claude-opus-5-5',
25102511 betas: ['compact-2026-01-12'],
25112512 contextManagement: [
25122513 'edits' => [
from line 2526
25252526 
25262527 count_response = client.beta.messages.count_tokens(
25272528 betas: ["compact-2026-01-12"],
2528 model: "claude-opus-5",
2529 model: "claude-opus-5-5",
25292530 messages: messages,
25302531 context_management: {
25312532 edits: [{ type: "compact_20260112" }]
from line 2553
25522553 -H "anthropic-beta: compact-2026-01-12" \
25532554 -H "content-type: application/json" \
25542555 -d '{
2555 "model": "claude-opus-5",
2556 "model": "claude-opus-5-5",
25562557 "max_tokens": 4096,
25572558 "messages": [
25582559 {
from line 2583
25822583 --beta compact-2026-01-12 \
25832584 --transform 'content.#(type=="text").text' \
25842585 --raw-output <<'YAML'
2585 model: claude-opus-5
2586 model: claude-opus-5-5
25862587 max_tokens: 4096
25872588 messages:
25882589 - role: user
from line 2608
26072608 
26082609 response = client.beta.messages.create(
26092610 betas=["compact-2026-01-12"],
2610 model="claude-opus-5",
2611 model="claude-opus-5-5",
26112612 max_tokens=4096,
26122613 messages=messages,
26132614 context_management={
from line 2645
26442645 
26452646 const response = await client.beta.messages.create({
26462647 betas: ["compact-2026-01-12"],
2647 model: "claude-opus-5",
2648 model: "claude-opus-5-5",
26482649 max_tokens: 4096,
26492650 messages,
26502651 context_management: {
from line 2688
26872688 var parameters = new MessageCreateParams
26882689 {
26892690 Betas = ["compact-2026-01-12"],
2690 Model = "claude-opus-5",
2691 Model = "claude-opus-5-5",
26912692 MaxTokens = 4096,
26922693 Messages = messages,
26932694 ContextManagement = new BetaContextManagementConfig
from line 2736
27352736 messages = append(messages, anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock(userMessage)))
27362737 
27372738 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
2738 Model: anthropic.ModelClaudeOpus5,
2739 Model: anthropic.ModelClaudeOpus5_5,
27392740 MaxTokens: 4096,
27402741 Messages: messages,
27412742 ContextManagement: anthropic.BetaContextManagementConfigParam{
from line 2791
27902791 
27912792 MessageCreateParams params = MessageCreateParams.builder()
27922793 .addBeta("compact-2026-01-12")
2793 .model("claude-opus-5")
2794 .model("claude-opus-5-5")
27942795 .maxTokens(4096L)
27952796 .messages(messages)
27962797 .contextManagement(BetaContextManagementConfig.builder()
from line 2826
28252826 $response = $client->beta->messages->create(
28262827 maxTokens: 4096,
28272828 messages: $messages,
2828 model: 'claude-opus-5',
2829 model: 'claude-opus-5-5',
28292830 betas: ['compact-2026-01-12'],
28302831 contextManagement: [
28312832 'edits' => [
from line 2862
28612862 
28622863 response = client.beta.messages.create(
28632864 betas: ["compact-2026-01-12"],
2864 model: "claude-opus-5",
2865 model: "claude-opus-5-5",
28652866 max_tokens: 4096,
28662867 messages: messages,
28672868 context_management: {
from line 2886
28852886 ```
28862887</CodeGroup>
28872888 
2888On Claude Fable 5.1, remove the `thinking` and `redacted_thinking` blocks from any assistant turn you re-insert after the compaction block, or send `thinking.block_binding.prefix_mismatch_behavior: "drop_block"` with the `thinking-binding-controls-2026-08-01` [beta header](https://platform.claude.com/docs/en/api/beta-headers). Those blocks were produced when the full history was present, so they no longer pass the [conversation check](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation). Where the check is enforced, the continuation request is rejected with a 400 error. The preserved text and tool blocks can stay as they are. Letting the API summarize everything, without re-inserting earlier turns, avoids this.
2889On Claude Fable 5.1 and Claude Opus 5.5, remove the `thinking` and `redacted_thinking` blocks from any assistant turn you re-insert after the compaction block, or send `thinking.block_binding.prefix_mismatch_behavior: "drop_block"` with the `thinking-binding-controls-2026-08-01` [beta header](https://platform.claude.com/docs/en/api/beta-headers). Those blocks were produced when the full history was present, so they no longer pass the [conversation check](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation). Where the check is enforced, the continuation request is rejected with a 400 error. The preserved text and tool blocks can stay as they are. Letting the API summarize everything, without re-inserting earlier turns, avoids this.
28892890 
28902891Here's an example that uses `pause_after_compaction` to preserve the prior exchange and the current user message (three messages total) verbatim instead of summarizing them:
28912892 
from line 2901
29002901 -H "anthropic-beta: compact-2026-01-12" \
29012902 -H "content-type: application/json" \
29022903 -d '{
2903 "model": "claude-opus-5",
2904 "model": "claude-opus-5-5",
29042905 "max_tokens": 4096,
29052906 "messages": [
29062907 {
from line 2932
29312932 --beta compact-2026-01-12 \
29322933 --transform 'content.#(type=="text").text' \
29332934 --raw-output <<'YAML'
2934 model: claude-opus-5
2935 model: claude-opus-5-5
29352936 max_tokens: 4096
29362937 messages:
29372938 - role: user
from line 2960
29592960 
29602961 response = client.beta.messages.create(
29612962 betas=["compact-2026-01-12"],
2962 model="claude-opus-5",
2963 model="claude-opus-5-5",
29632964 max_tokens=4096,
29642965 messages=messages,
29652966 context_management={
from line 2992
29912992 # Continue the request with the compacted context + preserved messages
29922993 response = client.beta.messages.create(
29932994 betas=["compact-2026-01-12"],
2994 model="claude-opus-5",
2995 model="claude-opus-5-5",
29952996 max_tokens=4096,
29962997 messages=messages_after_compaction,
29972998 context_management={"edits": [{"type": "compact_20260112"}]},
from line 3026
30253026 
30263027 let response = await client.beta.messages.create({
30273028 betas: ["compact-2026-01-12"],
3028 model: "claude-opus-5",
3029 model: "claude-opus-5-5",
30293030 max_tokens: 4096,
30303031 messages,
30313032 context_management: {
from line 3058
30573058 // Continue the request with the compacted context + preserved messages
30583059 response = await client.beta.messages.create({
30593060 betas: ["compact-2026-01-12"],
3060 model: "claude-opus-5",
3061 model: "claude-opus-5-5",
30613062 max_tokens: 4096,
30623063 messages: messagesAfterCompaction,
30633064 context_management: {
from line 3100
30993100 var response = await client.Beta.Messages.Create(new()
31003101 {
31013102 Betas = ["compact-2026-01-12"],
3102 Model = "claude-opus-5",
3103 Model = "claude-opus-5-5",
31033104 MaxTokens = 4096,
31043105 Messages = messages,
31053106 ContextManagement = new BetaContextManagementConfig
from line 3135
31343135 response = await client.Beta.Messages.Create(new()
31353136 {
31363137 Betas = ["compact-2026-01-12"],
3137 Model = "claude-opus-5",
3138 Model = "claude-opus-5-5",
31383139 MaxTokens = 4096,
31393140 Messages = messagesAfterCompaction,
31403141 ContextManagement = new BetaContextManagementConfig
from line 3190
31893190 }
31903191 
31913192 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
3192 Model: anthropic.ModelClaudeOpus5,
3193 Model: anthropic.ModelClaudeOpus5_5,
31933194 MaxTokens: 4096,
31943195 Messages: messages,
31953196 ContextManagement: compactEdit,
from line 3216
32153216 messagesAfterCompaction = append(messagesAfterCompaction, preserved...)
32163217 
32173218 response, err = client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
3218 Model: anthropic.ModelClaudeOpus5,
3219 Model: anthropic.ModelClaudeOpus5_5,
32193220 MaxTokens: 4096,
32203221 Messages: messagesAfterCompaction,
32213222 ContextManagement: anthropic.BetaContextManagementConfigParam{
from line 3267
32663267 
32673268 MessageCreateParams params = MessageCreateParams.builder()
32683269 .addBeta("compact-2026-01-12")
3269 .model("claude-opus-5")
3270 .model("claude-opus-5-5")
32703271 .maxTokens(4096L)
32713272 .messages(messages)
32723273 .contextManagement(BetaContextManagementConfig.builder()
from line 3298
32973298 // Continue the request with the compacted context + preserved messages
32983299 MessageCreateParams continueParams = MessageCreateParams.builder()
32993300 .addBeta("compact-2026-01-12")
3300 .model("claude-opus-5")
3301 .model("claude-opus-5-5")
33013302 .maxTokens(4096L)
33023303 .messages(messagesAfterCompaction)
33033304 .contextManagement(BetaContextManagementConfig.builder()
from line 3340
33393340 $response = $client->beta->messages->create(
33403341 maxTokens: 4096,
33413342 messages: $messages,
3342 model: 'claude-opus-5',
3343 model: 'claude-opus-5-5',
33433344 betas: ['compact-2026-01-12'],
33443345 contextManagement: [
33453346 'edits' => [
from line 3368
33673368 $response = $client->beta->messages->create(
33683369 maxTokens: 4096,
33693370 messages: $messagesAfterCompaction,
3370 model: 'claude-opus-5',
3371 model: 'claude-opus-5-5',
33713372 betas: ['compact-2026-01-12'],
33723373 contextManagement: [
33733374 'edits' => [['type' => 'compact_20260112']]
from line 3402
34013402 
34023403 response = client.beta.messages.create(
34033404 betas: ["compact-2026-01-12"],
3404 model: "claude-opus-5",
3405 model: "claude-opus-5-5",
34053406 max_tokens: 4096,
34063407 messages: messages,
34073408 context_management: {
from line 3427
34263427 
34273428 response = client.beta.messages.create(
34283429 betas: ["compact-2026-01-12"],
3429 model: "claude-opus-5",
3430 model: "claude-opus-5-5",
34303431 max_tokens: 4096,
34313432 messages: messages_after_compaction,
34323433 context_management: {

build-with-claude/context-editing Changed · +82 / -82 lines

from line 62
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 
65On Claude Fable 5.1, server-side context management never invalidates thinking blocks. Client-side edits to earlier turns can invalidate the thinking blocks in every later assistant turn. For new accounts created on or after August 31, 2026, a request that replays an invalidated block is rejected unless you opt into dropping it. See [Keeping the prefix unchanged](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#prefix-check).
65On Claude Fable 5.1 and Claude Opus 5.5, server-side context management never invalidates thinking blocks. Client-side edits to earlier turns can invalidate the thinking blocks in every later assistant turn. For new accounts created on or after August 31, 2026, a request that replays an invalidated block is rejected unless you opt into dropping it. See [Keeping the prefix unchanged](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#prefix-check).
6666 
6767### Context editing and prompt caching
6868 
from line 88
8888 --header "content-type: application/json" \
8989 --header "anthropic-beta: context-management-2025-06-27" \
9090 --data '{
91 "model": "claude-opus-5",
91 "model": "claude-opus-5-5",
9292 "max_tokens": 4096,
9393 "messages": [
9494 {
from line 112
112112 
113113 ```bash CLI
114114 ant beta:messages create --beta context-management-2025-06-27 <<'YAML'
115 model: claude-opus-5
115 model: claude-opus-5-5
116116 max_tokens: 4096
117117 messages:
118118 - role: user
from line 128
128128 
129129 ```python Python
130130 response = client.beta.messages.create(
131 model="claude-opus-5",
131 model="claude-opus-5-5",
132132 max_tokens=4096,
133133 messages=[{"role": "user", "content": "Search for recent developments in AI"}],
134134 tools=[{"type": "web_search_20250305", "name": "web_search"}],
from line 143
143143 });
144144 
145145 const response = await anthropic.beta.messages.create({
146 model: "claude-opus-5",
146 model: "claude-opus-5-5",
147147 max_tokens: 4096,
148148 messages: [
149149 {
from line 174
174174 
175175 var parameters = new MessageCreateParams
176176 {
177 Model = Messages::Model.ClaudeOpus5,
177 Model = Messages::Model.ClaudeOpus5_5,
178178 MaxTokens = 4096,
179179 Messages = [
180180 new() { Role = Role.User, Content = "Search for recent developments in AI" }
from line 197
197197 client := anthropic.NewClient()
198198 
199199 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
200 Model: anthropic.ModelClaudeOpus5,
200 Model: anthropic.ModelClaudeOpus5_5,
201201 MaxTokens: 4096,
202202 Messages: []anthropic.BetaMessageParam{
203203 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Search for recent developments in AI")),
from line 230
230230 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
231231 
232232 MessageCreateParams params = MessageCreateParams.builder()
233 .model(Model.CLAUDE_OPUS_5)
233 .model(Model.CLAUDE_OPUS_5_5)
234234 .maxTokens(4096L)
235235 .addUserMessage("Search for recent developments in AI")
236236 .addTool(BetaWebSearchTool20250305.builder().build())
from line 253
253253 messages: [
254254 ['role' => 'user', 'content' => 'Search for recent developments in AI']
255255 ],
256 model: 'claude-opus-5',
256 model: 'claude-opus-5-5',
257257 betas: ['context-management-2025-06-27'],
258258 tools: [
259259 ['type' => 'web_search_20250305', 'name' => 'web_search']
from line 272
272272 client = Anthropic::Client.new
273273 
274274 response = client.beta.messages.create(
275 model: "claude-opus-5",
275 model: "claude-opus-5-5",
276276 max_tokens: 4096,
277277 messages: [
278278 { role: "user", content: "Search for recent developments in AI" }
from line 303
303303 --header "content-type: application/json" \
304304 --header "anthropic-beta: context-management-2025-06-27" \
305305 --data '{
306 "model": "claude-opus-5",
306 "model": "claude-opus-5-5",
307307 "max_tokens": 4096,
308308 "messages": [
309309 {
from line 348
348348 
349349 ```bash CLI
350350 ant beta:messages create --beta context-management-2025-06-27 <<'YAML'
351 model: claude-opus-5
351 model: claude-opus-5-5
352352 max_tokens: 4096
353353 messages:
354354 - role: user
from line 379
379379 
380380 ```python Python
381381 response = client.beta.messages.create(
382 model="claude-opus-5",
382 model="claude-opus-5-5",
383383 max_tokens=4096,
384384 messages=[
385385 {
from line 420
420420 });
421421 
422422 const response = await anthropic.beta.messages.create({
423 model: "claude-opus-5",
423 model: "claude-opus-5-5",
424424 max_tokens: 4096,
425425 messages: [
426426 {
from line 478
478478 
479479 var parameters = new MessageCreateParams
480480 {
481 Model = Messages::Model.ClaudeOpus5,
481 Model = Messages::Model.ClaudeOpus5_5,
482482 MaxTokens = 4096,
483483 Messages = [
484484 new() { Role = Role.User, Content = "Create a simple command line calculator app using Python" }
from line 510
510510 client := anthropic.NewClient()
511511 
512512 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
513 Model: anthropic.ModelClaudeOpus5,
513 Model: anthropic.ModelClaudeOpus5_5,
514514 MaxTokens: 4096,
515515 Messages: []anthropic.BetaMessageParam{
516516 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Create a simple command line calculator app using Python")),
from line 563
563563 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
564564 
565565 MessageCreateParams params = MessageCreateParams.builder()
566 .model(Model.CLAUDE_OPUS_5)
566 .model(Model.CLAUDE_OPUS_5_5)
567567 .maxTokens(4096L)
568568 .addUserMessage("Create a simple command line calculator app using Python")
569569 .addTool(BetaToolTextEditor20250728.builder()
from line 605
605605 'content' => 'Create a simple command line calculator app using Python'
606606 ]
607607 ],
608 model: 'claude-opus-5',
608 model: 'claude-opus-5-5',
609609 betas: ['context-management-2025-06-27'],
610610 tools: [
611611 [
from line 648
648648 client = Anthropic::Client.new
649649 
650650 response = client.beta.messages.create(
651 model: "claude-opus-5",
651 model: "claude-opus-5-5",
652652 max_tokens: 4096,
653653 messages: [
654654 {
from line 706
706706 --header "content-type: application/json" \
707707 --header "anthropic-beta: context-management-2025-06-27" \
708708 --data '{
709 "model": "claude-opus-5",
709 "model": "claude-opus-5-5",
710710 "max_tokens": 16000,
711711 "messages": [{"role": "user", "content": "Hello"}],
712712 "context_management": {
from line 725
725725 
726726 ```bash CLI
727727 ant beta:messages create --beta context-management-2025-06-27 <<'YAML'
728 model: claude-opus-5
728 model: claude-opus-5-5
729729 max_tokens: 16000
730730 messages:
731731 - role: user
from line 741
741741 
742742 ```python Python
743743 response = client.beta.messages.create(
744 model="claude-opus-5",
744 model="claude-opus-5-5",
745745 max_tokens=16000,
746746 messages=[{"role": "user", "content": "Hello"}],
747747 betas=["context-management-2025-06-27"],
from line 762
762762 });
763763 
764764 const response = await anthropic.beta.messages.create({
765 model: "claude-opus-5",
765 model: "claude-opus-5-5",
766766 max_tokens: 16000,
767767 messages: [{ role: "user", content: "Hello" }],
768768 betas: ["context-management-2025-06-27"],
from line 790
790790 
791791 var parameters = new MessageCreateParams
792792 {
793 Model = Messages::Model.ClaudeOpus5,
793 Model = Messages::Model.ClaudeOpus5_5,
794794 MaxTokens = 16000,
795795 Messages = [
796796 new() { Role = Role.User, Content = "Hello" }
from line 815
815815 client := anthropic.NewClient()
816816 
817817 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
818 Model: anthropic.ModelClaudeOpus5,
818 Model: anthropic.ModelClaudeOpus5_5,
819819 MaxTokens: 16000,
820820 Messages: []anthropic.BetaMessageParam{
821821 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello")),
from line 849
849849 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
850850 
851851 MessageCreateParams params = MessageCreateParams.builder()
852 .model(Model.CLAUDE_OPUS_5)
852 .model(Model.CLAUDE_OPUS_5_5)
853853 .maxTokens(16000L)
854854 .addUserMessage("Hello")
855855 .addBeta(AnthropicBeta.CONTEXT_MANAGEMENT_2025_06_27)
from line 875
875875 messages: [
876876 ['role' => 'user', 'content' => 'Hello']
877877 ],
878 model: 'claude-opus-5',
878 model: 'claude-opus-5-5',
879879 betas: ['context-management-2025-06-27'],
880880 contextManagement: [
881881 'edits' => [
from line 897
897897 client = Anthropic::Client.new
898898 
899899 response = client.beta.messages.create(
900 model: "claude-opus-5",
900 model: "claude-opus-5-5",
901901 max_tokens: 16000,
902902 messages: [{ role: "user", content: "Hello" }],
903903 betas: ["context-management-2025-06-27"],
from line 937
937937 --header "content-type: application/json" \
938938 --header "anthropic-beta: context-management-2025-06-27" \
939939 --data '{
940 "model": "claude-opus-5",
940 "model": "claude-opus-5-5",
941941 "max_tokens": 16000,
942942 "messages": [{"role": "user", "content": "Hello"}],
943943 "context_management": {
from line 956
956956 
957957 ```bash CLI
958958 ant beta:messages create --beta context-management-2025-06-27 <<'YAML'
959 model: claude-opus-5
959 model: claude-opus-5-5
960960 max_tokens: 16000
961961 messages:
962962 - role: user
from line 972
972972 
973973 ```python Python
974974 response = client.beta.messages.create(
975 model="claude-opus-5",
975 model="claude-opus-5-5",
976976 max_tokens=16000,
977977 messages=[{"role": "user", "content": "Hello"}],
978978 betas=["context-management-2025-06-27"],
from line 993
993993 });
994994 
995995 const response = await anthropic.beta.messages.create({
996 model: "claude-opus-5",
996 model: "claude-opus-5-5",
997997 max_tokens: 16000,
998998 messages: [{ role: "user", content: "Hello" }],
999999 betas: ["context-management-2025-06-27"],
from line 1021
10211021 
10221022 var parameters = new MessageCreateParams
10231023 {
1024 Model = Messages::Model.ClaudeOpus5,
1024 Model = Messages::Model.ClaudeOpus5_5,
10251025 MaxTokens = 16000,
10261026 Messages = [
10271027 new() { Role = Role.User, Content = "Hello" }
from line 1046
10461046 client := anthropic.NewClient()
10471047 
10481048 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
1049 Model: anthropic.ModelClaudeOpus5,
1049 Model: anthropic.ModelClaudeOpus5_5,
10501050 MaxTokens: 16000,
10511051 Messages: []anthropic.BetaMessageParam{
10521052 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello")),
from line 1074
10741074 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
10751075 
10761076 MessageCreateParams params = MessageCreateParams.builder()
1077 .model(Model.CLAUDE_OPUS_5)
1077 .model(Model.CLAUDE_OPUS_5_5)
10781078 .maxTokens(16000L)
10791079 .addUserMessage("Hello")
10801080 .addBeta(AnthropicBeta.CONTEXT_MANAGEMENT_2025_06_27)
from line 1099
10991099 messages: [
11001100 ['role' => 'user', 'content' => 'Hello']
11011101 ],
1102 model: 'claude-opus-5',
1102 model: 'claude-opus-5-5',
11031103 betas: ['context-management-2025-06-27'],
11041104 contextManagement: [
11051105 'edits' => [
from line 1121
11211121 client = Anthropic::Client.new
11221122 
11231123 response = client.beta.messages.create(
1124 model: "claude-opus-5",
1124 model: "claude-opus-5-5",
11251125 max_tokens: 16000,
11261126 messages: [{ role: "user", content: "Hello" }],
11271127 betas: ["context-management-2025-06-27"],
from line 1151
11511151 --header "content-type: application/json" \
11521152 --header "anthropic-beta: context-management-2025-06-27" \
11531153 --data '{
1154 "model": "claude-opus-5",
1154 "model": "claude-opus-5-5",
11551155 "max_tokens": 16000,
11561156 "messages": [{"role": "user", "content": "Hello"}],
11571157 "context_management": {
from line 1167
11671167 
11681168 ```bash CLI
11691169 ant beta:messages create --beta context-management-2025-06-27 <<'YAML'
1170 model: claude-opus-5
1170 model: claude-opus-5-5
11711171 max_tokens: 16000
11721172 messages:
11731173 - role: user
from line 1181
11811181 
11821182 ```python Python
11831183 response = client.beta.messages.create(
1184 model="claude-opus-5",
1184 model="claude-opus-5-5",
11851185 max_tokens=16000,
11861186 messages=[{"role": "user", "content": "Hello"}],
11871187 betas=["context-management-2025-06-27"],
from line 1202
12021202 });
12031203 
12041204 const response = await anthropic.beta.messages.create({
1205 model: "claude-opus-5",
1205 model: "claude-opus-5-5",
12061206 max_tokens: 16000,
12071207 messages: [{ role: "user", content: "Hello" }],
12081208 betas: ["context-management-2025-06-27"],
from line 1227
12271227 
12281228 var parameters = new MessageCreateParams
12291229 {
1230 Model = Messages::Model.ClaudeOpus5,
1230 Model = Messages::Model.ClaudeOpus5_5,
12311231 MaxTokens = 16000,
12321232 Messages = [
12331233 new() { Role = Role.User, Content = "Hello" }
from line 1252
12521252 client := anthropic.NewClient()
12531253 
12541254 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
1255 Model: anthropic.ModelClaudeOpus5,
1255 Model: anthropic.ModelClaudeOpus5_5,
12561256 MaxTokens: 16000,
12571257 Messages: []anthropic.BetaMessageParam{
12581258 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello")),
from line 1278
12781278 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
12791279 
12801280 MessageCreateParams params = MessageCreateParams.builder()
1281 .model(Model.CLAUDE_OPUS_5)
1281 .model(Model.CLAUDE_OPUS_5_5)
12821282 .maxTokens(16000L)
12831283 .addUserMessage("Hello")
12841284 .addBeta(AnthropicBeta.CONTEXT_MANAGEMENT_2025_06_27)
from line 1301
13011301 messages: [
13021302 ['role' => 'user', 'content' => 'Hello']
13031303 ],
1304 model: 'claude-opus-5',
1304 model: 'claude-opus-5-5',
13051305 betas: ['context-management-2025-06-27'],
13061306 contextManagement: [
13071307 'edits' => [
from line 1320
13201320 client = Anthropic::Client.new
13211321 
13221322 response = client.beta.messages.create(
1323 model: "claude-opus-5",
1323 model: "claude-opus-5-5",
13241324 max_tokens: 16000,
13251325 messages: [{ role: "user", content: "Hello" }],
13261326 betas: ["context-management-2025-06-27"],
from line 1353
13531353 --header "content-type: application/json" \
13541354 --header "anthropic-beta: context-management-2025-06-27" \
13551355 --data '{
1356 "model": "claude-opus-5",
1356 "model": "claude-opus-5-5",
13571357 "max_tokens": 16000,
13581358 "messages": [
13591359 {
from line 1395
13951395 
13961396 ```bash CLI
13971397 ant beta:messages create --beta context-management-2025-06-27 <<'YAML'
1398 model: claude-opus-5
1398 model: claude-opus-5-5
13991399 max_tokens: 16000
14001400 messages:
14011401 - role: user
from line 1422
14221422 
14231423 ```python Python
14241424 response = client.beta.messages.create(
1425 model="claude-opus-5",
1425 model="claude-opus-5-5",
14261426 max_tokens=16000,
14271427 messages=[
14281428 {
from line 1462
14621462 });
14631463 
14641464 const response = await anthropic.beta.messages.create({
1465 model: "claude-opus-5",
1465 model: "claude-opus-5-5",
14661466 max_tokens: 16000,
14671467 messages: [
14681468 {
from line 1516
15161516 
15171517 var parameters = new MessageCreateParams
15181518 {
1519 Model = Messages::Model.ClaudeOpus5,
1519 Model = Messages::Model.ClaudeOpus5_5,
15201520 MaxTokens = 16000,
15211521 Messages = [
15221522 new() { Role = Role.User, Content = "Search for the latest developments in quantum error correction and summarize the key breakthroughs." }
from line 1549
15491549 client := anthropic.NewClient()
15501550 
15511551 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
1552 Model: anthropic.ModelClaudeOpus5,
1552 Model: anthropic.ModelClaudeOpus5_5,
15531553 MaxTokens: 16000,
15541554 Messages: []anthropic.BetaMessageParam{
15551555 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Search for the latest developments in quantum error correction and summarize the key breakthroughs.")),
from line 1604
16041604 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
16051605 
16061606 MessageCreateParams params = MessageCreateParams.builder()
1607 .model(Model.CLAUDE_OPUS_5)
1607 .model(Model.CLAUDE_OPUS_5_5)
16081608 .maxTokens(16000L)
16091609 .addUserMessage("Search for the latest developments in quantum error correction and summarize the key breakthroughs.")
16101610 .addTool(BetaWebSearchTool20250305.builder()
from line 1644
16441644 'content' => 'Search for the latest developments in quantum error correction and summarize the key breakthroughs.'
16451645 ]
16461646 ],
1647 model: 'claude-opus-5',
1647 model: 'claude-opus-5-5',
16481648 betas: ['context-management-2025-06-27'],
16491649 tools: [
16501650 [
from line 1684
16841684 client = Anthropic::Client.new
16851685 
16861686 response = client.beta.messages.create(
1687 model: "claude-opus-5",
1687 model: "claude-opus-5-5",
16881688 max_tokens: 16000,
16891689 messages: [
16901690 {
from line 1803
18031803 --header "content-type: application/json" \
18041804 --header "anthropic-beta: context-management-2025-06-27" \
18051805 --data '{
1806 "model": "claude-opus-5",
1806 "model": "claude-opus-5-5",
18071807 "messages": [
18081808 {
18091809 "role": "user",
from line 1830
18301830 
18311831 ```bash CLI
18321832 cat > request.yaml <<'YAML'
1833 model: claude-opus-5
1833 model: claude-opus-5-5
18341834 messages:
18351835 - role: user
18361836 content: Continue our conversation...
from line 1861
18611861 
18621862 ```python Python
18631863 response = client.beta.messages.count_tokens(
1864 model="claude-opus-5",
1864 model="claude-opus-5-5",
18651865 messages=[{"role": "user", "content": "Continue our conversation..."}],
18661866 betas=["context-management-2025-06-27"],
18671867 context_management={
from line 1888
18881888 });
18891889 
18901890 const response = await anthropic.beta.messages.countTokens({
1891 model: "claude-opus-5",
1891 model: "claude-opus-5-5",
18921892 messages: [
18931893 {
18941894 role: "user",
from line 1932
19321932 
19331933 var parameters = new MessageCountTokensParams
19341934 {
1935 Model = Messages::Model.ClaudeOpus5,
1935 Model = Messages::Model.ClaudeOpus5_5,
19361936 Messages = [new() { Role = Role.User, Content = "Continue our conversation..." }],
19371937 Betas = [AnthropicBeta.ContextManagement2025_06_27],
19381938 ContextManagement = new BetaContextManagementConfig
from line 1958
19581958 client := anthropic.NewClient()
19591959 
19601960 response, err := client.Beta.Messages.CountTokens(context.TODO(), anthropic.BetaMessageCountTokensParams{
1961 Model: anthropic.ModelClaudeOpus5,
1961 Model: anthropic.ModelClaudeOpus5_5,
19621962 Messages: []anthropic.BetaMessageParam{
19631963 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Continue our conversation...")),
19641964 },
from line 2002
20022002 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
20032003 
20042004 MessageCountTokensParams params = MessageCountTokensParams.builder()
2005 .model(Model.CLAUDE_OPUS_5)
2005 .model(Model.CLAUDE_OPUS_5_5)
20062006 .addUserMessage("Continue our conversation...")
20072007 .addBeta(AnthropicBeta.CONTEXT_MANAGEMENT_2025_06_27)
20082008 .contextManagement(BetaContextManagementConfig.builder()
from line 2032
20322032 messages: [
20332033 ['role' => 'user', 'content' => 'Continue our conversation...']
20342034 ],
2035 model: 'claude-opus-5',
2035 model: 'claude-opus-5-5',
20362036 betas: ['context-management-2025-06-27'],
20372037 contextManagement: [
20382038 'edits' => [
from line 2060
20602060 client = Anthropic::Client.new
20612061 
20622062 response = client.beta.messages.count_tokens(
2063 model: "claude-opus-5",
2063 model: "claude-opus-5-5",
20642064 messages: [
20652065 { role: "user", content: "Continue our conversation..." }
20662066 ],
from line 2121
21212121 --header "content-type: application/json" \
21222122 --header "anthropic-beta: context-management-2025-06-27" \
21232123 --data '{
2124 "model": "claude-opus-5",
2124 "model": "claude-opus-5-5",
21252125 "max_tokens": 4096,
21262126 "messages": [
21272127 {
from line 2145
21452145 
21462146 ```bash CLI
21472147 ant beta:messages create --beta context-management-2025-06-27 <<'YAML'
2148 model: claude-opus-5
2148 model: claude-opus-5-5
21492149 max_tokens: 4096
21502150 messages:
21512151 - role: user
from line 2161
21612161 
21622162 ```python Python
21632163 response = client.beta.messages.create(
2164 model="claude-opus-5",
2164 model="claude-opus-5-5",
21652165 max_tokens=4096,
21662166 messages=[{"role": "user", "content": "Hello"}],
21672167 tools=[{"type": "memory_20250818", "name": "memory"}],
from line 2176
21762176 });
21772177 
21782178 const response = await anthropic.beta.messages.create({
2179 model: "claude-opus-5",
2179 model: "claude-opus-5-5",
21802180 max_tokens: 4096,
21812181 messages: [{ role: "user", content: "Hello" }],
21822182 tools: [
from line 2202
22022202 
22032203 var parameters = new MessageCreateParams
22042204 {
2205 Model = Messages::Model.ClaudeOpus5,
2205 Model = Messages::Model.ClaudeOpus5_5,
22062206 MaxTokens = 4096,
22072207 Messages = [
22082208 new() { Role = Role.User, Content = "Hello" }
from line 2225
22252225 client := anthropic.NewClient()
22262226 
22272227 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
2228 Model: anthropic.ModelClaudeOpus5,
2228 Model: anthropic.ModelClaudeOpus5_5,
22292229 MaxTokens: 4096,
22302230 Messages: []anthropic.BetaMessageParam{
22312231 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello")),
from line 2256
22562256 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
22572257 
22582258 MessageCreateParams params = MessageCreateParams.builder()
2259 .model(Model.CLAUDE_OPUS_5)
2259 .model(Model.CLAUDE_OPUS_5_5)
22602260 .maxTokens(4096L)
22612261 .addUserMessage("Hello")
22622262 .addTool(BetaMemoryTool20250818.builder().build())
from line 2279
22792279 messages: [
22802280 ['role' => 'user', 'content' => 'Hello']
22812281 ],
2282 model: 'claude-opus-5',
2282 model: 'claude-opus-5-5',
22832283 betas: ['context-management-2025-06-27'],
22842284 tools: [
22852285 [
from line 2301
23012301 client = Anthropic::Client.new
23022302 
23032303 response = client.beta.messages.create(
2304 model: "claude-opus-5",
2304 model: "claude-opus-5-5",
23052305 max_tokens: 4096,
23062306 messages: [{ role: "user", content: "Hello" }],
23072307 tools: [
from line 2374
23742374 const client = new Anthropic();
23752375 
23762376 const runner = client.beta.messages.toolRunner({
2377 model: "claude-opus-5",
2377 model: "claude-opus-5-5",
23782378 max_tokens: 1024,
23792379 tools: [readFile],
23802380 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2416
24162416 client = Anthropic::Client.new
24172417 
24182418 runner = client.beta.messages.tool_runner(
2419 model: "claude-opus-5",
2419 model: "claude-opus-5-5",
24202420 max_tokens: 1024,
24212421 tools: [ReadFile.new],
24222422 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2506
25062506 const client = new Anthropic();
25072507 
25082508 const runner = client.beta.messages.toolRunner({
2509 model: "claude-opus-5",
2509 model: "claude-opus-5-5",
25102510 max_tokens: 1024,
25112511 tools: [readFile],
25122512 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2549
25492549 client = Anthropic::Client.new
25502550 
25512551 runner = client.beta.messages.tool_runner(
2552 model: "claude-opus-5",
2552 model: "claude-opus-5-5",
25532553 max_tokens: 1024,
25542554 tools: [ReadFile.new],
25552555 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2592
25922592 const client = new Anthropic();
25932593 
25942594 const runner = client.beta.messages.toolRunner({
2595 model: "claude-opus-5",
2595 model: "claude-opus-5-5",
25962596 max_tokens: 1024,
25972597 tools: [readFile],
25982598 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2638
26382638 client = Anthropic::Client.new
26392639 
26402640 runner = client.beta.messages.tool_runner(
2641 model: "claude-opus-5",
2641 model: "claude-opus-5-5",
26422642 max_tokens: 1024,
26432643 tools: [ReadFile.new],
26442644 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2684
26842684 const client = new Anthropic();
26852685 
26862686 const runner = client.beta.messages.toolRunner({
2687 model: "claude-opus-5",
2687 model: "claude-opus-5-5",
26882688 max_tokens: 1024,
26892689 tools: [readFile],
26902690 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2735
27352735 client = Anthropic::Client.new
27362736 
27372737 runner = client.beta.messages.tool_runner(
2738 model: "claude-opus-5",
2738 model: "claude-opus-5-5",
27392739 max_tokens: 1024,
27402740 tools: [ReadFile.new],
27412741 messages: [{ role: "user", content: "What's in config.json?" }],
from line 2911
29112911 client = Anthropic::Client.new
29122912 
29132913 runner = client.beta.messages.tool_runner(
2914 model: "claude-opus-5",
2914 model: "claude-opus-5-5",
29152915 max_tokens: 1024,
29162916 tools: [ReadFile.new],
29172917 messages: [{ role: "user", content: "What's in config.json?" }],

build-with-claude/effort Changed · +25 / -20 lines

### Recommended effort levels for Claude Opus 5.5

from line 13
1313 - claude-fable-5
1414 - claude-mythos-5
1515 - claude-mythos-preview
16 - claude-opus-5-5
1617 - claude-opus-5
1718 - claude-opus-4-8
1819 - claude-opus-4-7
from line 46
4546 -H "anthropic-version: 2023-06-01" \
4647 -H "content-type: application/json" \
4748 -d '{
48 "model": "claude-opus-5",
49 "model": "claude-opus-5-5",
4950 "max_tokens": 4096,
5051 "messages": [{
5152 "role": "user",
from line 60
5960 
6061 ```bash CLI
6162 ant messages create \
62 --model claude-opus-5 \
63 --model claude-opus-5-5 \
6364 --max-tokens 4096 \
6465 --output-config '{effort: medium}' \
6566 --message '{role: user, content: "Analyze the trade-offs between microservices and monolithic architectures"}' \
from line 72
7172 client = anthropic.Anthropic()
7273 
7374 response = client.messages.create(
74 model="claude-opus-5",
75 model="claude-opus-5-5",
7576 max_tokens=4096,
7677 messages=[
7778 {
from line 92
9192 const client = new Anthropic();
9293 
9394 const response = await client.messages.create({
94 model: "claude-opus-5",
95 model: "claude-opus-5-5",
9596 max_tokens: 4096,
9697 messages: [
9798 {
from line 116
115116 
116117 var parameters = new MessageCreateParams
117118 {
118 Model = Model.ClaudeOpus5,
119 Model = Model.ClaudeOpus5_5,
119120 MaxTokens = 4096,
120121 Messages = [
121122 new() {
from line 138
137138 client := anthropic.NewClient()
138139 
139140 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
140 Model: anthropic.ModelClaudeOpus5,
141 Model: anthropic.ModelClaudeOpus5_5,
141142 MaxTokens: 4096,
142143 Messages: []anthropic.MessageParam{
143144 anthropic.NewUserMessage(anthropic.NewTextBlock("Analyze the trade-offs between microservices and monolithic architectures")),
from line 164
163164 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
164165 
165166 MessageCreateParams params = MessageCreateParams.builder()
166 .model(Model.CLAUDE_OPUS_5)
167 .model(Model.CLAUDE_OPUS_5_5)
167168 .maxTokens(4096L)
168169 .addUserMessage("Analyze the trade-offs between microservices and monolithic architectures")
169170 .outputConfig(OutputConfig.builder()
from line 187
186187 messages: [
187188 ['role' => 'user', 'content' => 'Analyze the trade-offs between microservices and monolithic architectures']
188189 ],
189 model: 'claude-opus-5',
190 model: 'claude-opus-5-5',
190191 outputConfig: ['effort' => 'medium'],
191192 );
192193 
from line 202
201202 client = Anthropic::Client.new
202203 
203204 message = client.messages.create(
204 model: "claude-opus-5",
205 model: "claude-opus-5-5",
205206 max_tokens: 4096,
206207 messages: [
207208 { role: "user", content: "Analyze the trade-offs between microservices and monolithic architectures" }
from line 220
219220 
220221## How effort works
221222 
222By default, Claude uses high effort, spending as many tokens as needed for excellent results. You can raise the effort level to `max` for the absolute highest capability, or lower it to be more conservative with token usage, optimizing for speed and cost while accepting some reduction in capability.
223Most Claude models default to high effort, spending as many tokens as needed for excellent results; Claude Opus 5.5 defaults to medium. You can raise the effort level to `max` for the absolute highest capability, or lower it to be more conservative with token usage, optimizing for speed and cost while accepting some reduction in capability.
223224 
224225<Tip>
225 Setting `effort` to `"high"` produces exactly the same behavior as omitting the `effort` parameter entirely.
226 Setting `effort` to the model's default (`"medium"` on Claude Opus 5.5, `"high"` on other models) produces exactly the same behavior as omitting the `effort` parameter entirely.
226227</Tip>
227228 
228229The effort parameter affects **all tokens** in the response, including:
from line 236
235236 
236237### Effort levels
237238 
238| Level | Description | Typical use case |
239| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
240| `max` | Absolute maximum capability with no constraints on token spending. Available on Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, Claude Mythos 5, Claude Mythos Preview, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, and Claude Sonnet 4.6. | Tasks requiring the deepest possible reasoning and most thorough analysis |
241| `xhigh` | Extended capability for long-horizon work. Available on Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, Claude Mythos 5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, and Claude Sonnet 5. | Long-running agentic and coding tasks (over 30 minutes) with token budgets in the millions |
242| `high` | High capability. Equivalent to not setting the parameter. | Complex reasoning, difficult coding problems, agentic tasks |
243| `medium` | Balanced approach with moderate token savings. | Agentic tasks that require a balance of speed, cost, and performance |
244| `low` | Most efficient. Significant token savings with some capability reduction. | Simpler tasks that need the best speed and lowest costs, such as subagents |
239| Level | Description | Typical use case |
240| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
241| `max` | Absolute maximum capability with no constraints on token spending. Available on Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, Claude Mythos 5, Claude Mythos Preview, Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, and Claude Sonnet 4.6. | Tasks requiring the deepest possible reasoning and most thorough analysis |
242| `xhigh` | Extended capability for long-horizon work. Available on Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, Claude Mythos 5, Claude Opus 5.5, Claude Opus 5, Claude Opus 4.8, Claude Opus 4.7, and Claude Sonnet 5. | Long-running agentic and coding tasks (over 30 minutes) with token budgets in the millions |
243| `high` | Spends as many tokens as the task needs for excellent results. The default on every model that supports effort except Claude Opus 5.5. | Complex reasoning, difficult coding problems, agentic tasks |
244| `medium` | Balanced approach with moderate token savings. The default on Claude Opus 5.5. | Agentic tasks that require a balance of speed, cost, and performance |
245| `low` | Most efficient. Significant token savings with some capability reduction. | Simpler tasks that need the best speed and lowest costs, such as subagents |
245246 
246247Not every model that supports `max` supports `xhigh`.
247248 
from line 264
263264 
264265Reduce effort if a task completes but takes longer than necessary, or if you want a faster, more interactive working style. The same recommendations apply to Claude Mythos 5. For fuller guidance, see [Prompting Claude Fable 5](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-fable-5).
265266 
267### Recommended effort levels for Claude Opus 5.5
268 
269Claude Opus 5.5 supports all five effort levels, and `medium` is the default (Claude Opus 5 and earlier Opus models default to `high`, so a request that omits `effort` runs one level lower than it did on Claude Opus 5). Adaptive thinking is always on and can't be turned off, so effort is the primary control for how much the model reasons and what a request costs. Run an effort sweep on your own evals rather than carrying settings over from an earlier model, and set a large `max_tokens` at the higher levels: it's a hard limit on total output (thinking plus response text). Requests that set `thinking: {"type": "disabled"}` return a 400 error at every effort level. Claude Opus 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. See [Prompting Claude Opus 5.5](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-opus-5-5).
270 
266271### Recommended effort levels for Claude Opus 5
267272 
268273Claude Opus 5 supports all five effort levels. **Start with `high`, the default**, and adjust based on your evals: step up to `xhigh` for demanding coding and agentic work, or to `max` when a task justifies unconstrained token spending, and use `low` and `medium` liberally as your primary control for token cost and response time wherever your evals show quality holds. If you carried effort settings over from an earlier model, run a fresh effort sweep on your evals rather than reusing them.
from line 355
350355 
351356## Change effort mid-conversation
352357 
353You can run later turns of a conversation at a different effort level in two ways. On Claude Fable 5.1, Claude Mythos 5.1, and Claude Opus 5, use a per-message effort change, which keeps the prompt cache. On other models, set a new top-level value on the next request, which starts the cache over.
358You can run later turns of a conversation at a different effort level in two ways. On Claude Fable 5.1, Claude Mythos 5.1, Claude Opus 5.5, and Claude Opus 5, use a per-message effort change, which keeps the prompt cache. On other models, set a new top-level value on the next request, which starts the cache over.
354359 
355360### Per-message effort (beta)
356361 
from line 642
637642 
638643## Best practices
639644 
6401. **Set effort explicitly:** The API defaults to `high`, but the right starting point depends on your model and workload.
6451. **Set effort explicitly:** The API defaults to `high` (`medium` on Claude Opus 5.5), but the right starting point depends on your model and workload.
6416462. **Use low for speed-sensitive or simple tasks:** When latency matters or tasks are straightforward, low effort can significantly reduce response times and costs.
6426473. **Test your use case:** The impact of effort levels varies by task type. Evaluate performance on your specific use cases before deploying.
6436484. **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.

build-with-claude/fast-mode Changed · +33 / -31 lines

from line 4
44description: Get up to 2.5x higher output tokens per second from supported Claude Opus models.
55---
66 
7Fast mode delivers up to 2.5x higher output tokens per second from Claude Opus 5 and Claude Opus 4.8 at premium pricing. Set `speed: "fast"` with the `fast-mode-2026-02-01` beta header on your request to opt in.
7Fast mode delivers up to 2.5x higher output tokens per second from Claude Opus 5.5, Claude Opus 5, and Claude Opus 4.8 at premium pricing. Set `speed: "fast"` with the `fast-mode-2026-02-01` beta header on your request to opt in.
88 
99<Note>
1010 Fast mode is in research preview. Contact your account manager to request access. If you do not have an account manager, [join the waitlist](https://claude.com/fast-mode) for fast mode.
from line 18
1818 
1919Fast mode is supported on the following models:
2020 
21* Claude Opus 5.5 (claude-opus-5-5)
2122* Claude Opus 5 (claude-opus-5)
2223* Claude Opus 4.8 (claude-opus-4-8)
2324 
2425<Note>
25 Fast mode for Claude Opus 5 and Claude Opus 4.8 is available as a research preview on the Claude API, including [Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview), only. It is not available on Amazon Bedrock, Claude Platform on AWS, Google Cloud, or Microsoft Foundry.
26 Fast mode for Claude Opus 5.5, Claude Opus 5, and Claude Opus 4.8 is available as a research preview on the Claude API, including [Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview), only. It is not available on Amazon Bedrock, Claude Platform on AWS, Google Cloud, or Microsoft Foundry.
2627</Note>
2728 
2829<Note>
29 Fast mode is not available on Claude Opus 4.7. Requests to `claude-opus-4-7` with `speed: "fast"` return an error; unlike Claude Opus 4.6 (see the following note), requests do not fall back to standard speed. The model itself remains available at standard speed. To continue using fast mode, migrate to [Claude Opus 5](https://platform.claude.com/docs/en/models/opus-5/migration-guide#migrating-from-claude-opus-47) or Claude Opus 4.8.
30 Fast mode is not available on Claude Opus 4.7. Requests to `claude-opus-4-7` with `speed: "fast"` return an error; unlike Claude Opus 4.6 (see the following note), requests do not fall back to standard speed. The model itself remains available at standard speed. To continue using fast mode, migrate to Claude Opus 5.5, [Claude Opus 5](https://platform.claude.com/docs/en/models/opus-5/migration-guide#migrating-from-claude-opus-47), or Claude Opus 4.8.
3031</Note>
3132 
3233<Note>
33 Fast mode is not available on Claude Opus 4.6. Requests to `claude-opus-4-6` with `speed: "fast"` do not return an error: they run at standard speed and are billed at [standard rates](https://platform.claude.com/docs/en/about-claude/pricing) rather than fast mode's premium rates, and the response reports [`usage.speed: "standard"`](https://platform.claude.com/docs/en/build-with-claude/fast-mode#checking-which-speed-was-used). To continue using fast mode, migrate to [Claude Opus 5](https://platform.claude.com/docs/en/models/opus-5/migration-guide#migrating-from-claude-opus-46) or Claude Opus 4.8.
34 Fast mode is not available on Claude Opus 4.6. Requests to `claude-opus-4-6` with `speed: "fast"` do not return an error: they run at standard speed and are billed at [standard rates](https://platform.claude.com/docs/en/about-claude/pricing) rather than fast mode's premium rates, and the response reports [`usage.speed: "standard"`](https://platform.claude.com/docs/en/build-with-claude/fast-mode#checking-which-speed-was-used). To continue using fast mode, migrate to Claude Opus 5.5, [Claude Opus 5](https://platform.claude.com/docs/en/models/opus-5/migration-guide#migrating-from-claude-opus-46), or Claude Opus 4.8.
3435</Note>
3536 
3637## How fast mode works
from line 53
5253 -H "anthropic-beta: fast-mode-2026-02-01" \
5354 -H "content-type: application/json" \
5455 -d '{
55 "model": "claude-opus-5",
56 "model": "claude-opus-5-5",
5657 "max_tokens": 4096,
5758 "speed": "fast",
5859 "messages": [{
from line 68
6768 --beta fast-mode-2026-02-01 \
6869 --transform 'content.#(type=="text").text' \
6970 --raw-output <<'YAML'
70 model: claude-opus-5
71 model: claude-opus-5-5
7172 max_tokens: 4096
7273 speed: fast
7374 messages:
from line 81
8081 client = anthropic.Anthropic()
8182 
8283 response = client.beta.messages.create(
83 model="claude-opus-5",
84 model="claude-opus-5-5",
8485 max_tokens=4096,
8586 speed="fast",
8687 betas=["fast-mode-2026-02-01"],
from line 99
9899 const client = new Anthropic();
99100 
100101 const response = await client.beta.messages.create({
101 model: "claude-opus-5",
102 model: "claude-opus-5-5",
102103 max_tokens: 4096,
103104 speed: "fast",
104105 betas: ["fast-mode-2026-02-01"],
from line 122
121122 
122123 var response = await client.Beta.Messages.Create(new MessageCreateParams
123124 {
124 Model = "claude-opus-5",
125 Model = "claude-opus-5-5",
125126 MaxTokens = 4096,
126127 Speed = Speed.Fast,
127128 Betas = ["fast-mode-2026-02-01"],
from line 144
143144 client := anthropic.NewClient()
144145 
145146 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
146 Model: anthropic.ModelClaudeOpus5,
147 Model: anthropic.ModelClaudeOpus5_5,
147148 MaxTokens: 4096,
148149 Speed: anthropic.BetaMessageNewParamsSpeedFast,
149150 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaFastMode2026_02_01},
from line 167
166167 
167168 BetaMessage response = client.beta().messages().create(
168169 MessageCreateParams.builder()
169 .model(Model.CLAUDE_OPUS_5)
170 .model(Model.CLAUDE_OPUS_5_5)
170171 .maxTokens(4096L)
171172 .speed(MessageCreateParams.Speed.FAST)
172173 .addBeta(AnthropicBeta.FAST_MODE_2026_02_01)
from line 183
182183 $client = new Client();
183184 
184185 $response = $client->beta->messages->create(
185 model: 'claude-opus-5',
186 model: 'claude-opus-5-5',
186187 maxTokens: 4096,
187188 speed: 'fast',
188189 betas: ['fast-mode-2026-02-01'],
from line 203
202203 client = Anthropic::Client.new
203204 
204205 response = client.beta.messages.create(
205 model: "claude-opus-5",
206 model: "claude-opus-5-5",
206207 max_tokens: 4096,
207208 speed: "fast",
208209 betas: ["fast-mode-2026-02-01"],
from line 222
221222 
222223| Model | Input | Output |
223224| ------------------------------- | -------------- | -------------- |
225| Claude Opus 5.5 | $8 USD / MTok | $40 USD / MTok |
224226| Claude Opus 5 / Claude Opus 4.8 | $10 USD / MTok | $50 USD / MTok |
225227 
226228Fast mode pricing stacks with other pricing modifiers:
from line 261
259261 -H "anthropic-beta: fast-mode-2026-02-01" \
260262 -H "content-type: application/json" \
261263 -d '{
262 "model": "claude-opus-5",
264 "model": "claude-opus-5-5",
263265 "max_tokens": 1024,
264266 "speed": "fast",
265267 "messages": [{"role": "user", "content": "Hello"}]
from line 273
271273 --beta fast-mode-2026-02-01 \
272274 --transform usage.speed \
273275 --raw-output <<'YAML'
274 model: claude-opus-5
276 model: claude-opus-5-5
275277 max_tokens: 1024
276278 speed: fast
277279 messages:
from line 286
284286 client = anthropic.Anthropic()
285287 
286288 response = client.beta.messages.create(
287 model="claude-opus-5",
289 model="claude-opus-5-5",
288290 max_tokens=1024,
289291 speed="fast",
290292 betas=["fast-mode-2026-02-01"],
from line 300
298300 const client = new Anthropic();
299301 
300302 const response = await client.beta.messages.create({
301 model: "claude-opus-5",
303 model: "claude-opus-5-5",
302304 max_tokens: 1024,
303305 speed: "fast",
304306 betas: ["fast-mode-2026-02-01"],
from line 315
313315 
314316 var response = await client.Beta.Messages.Create(new MessageCreateParams
315317 {
316 Model = "claude-opus-5",
318 Model = "claude-opus-5-5",
317319 MaxTokens = 1024,
318320 Speed = Speed.Fast,
319321 Betas = ["fast-mode-2026-02-01"],
from line 329
327329 client := anthropic.NewClient()
328330 
329331 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
330 Model: anthropic.ModelClaudeOpus5,
332 Model: anthropic.ModelClaudeOpus5_5,
331333 MaxTokens: 1024,
332334 Speed: anthropic.BetaMessageNewParamsSpeedFast,
333335 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaFastMode2026_02_01},
from line 347
345347 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
346348 
347349 MessageCreateParams params = MessageCreateParams.builder()
348 .model(Model.CLAUDE_OPUS_5)
350 .model(Model.CLAUDE_OPUS_5_5)
349351 .maxTokens(1024L)
350352 .speed(MessageCreateParams.Speed.FAST)
351353 .addBeta(AnthropicBeta.FAST_MODE_2026_02_01)
from line 362
360362 $client = new Client();
361363 
362364 $response = $client->beta->messages->create(
363 model: 'claude-opus-5',
365 model: 'claude-opus-5-5',
364366 maxTokens: 1024,
365367 speed: 'fast',
366368 betas: ['fast-mode-2026-02-01'],
from line 376
374376 client = Anthropic::Client.new
375377 
376378 response = client.beta.messages.create(
377 model: "claude-opus-5",
379 model: "claude-opus-5-5",
378380 max_tokens: 1024,
379381 speed: "fast",
380382 betas: ["fast-mode-2026-02-01"],
from line 454
452454 
453455 MESSAGE=$(
454456 create_message_with_fast_fallback fast <<'YAML'
455 model: claude-opus-5
457 model: claude-opus-5-5
456458 max_tokens: 1024
457459 messages:
458460 - role: user
from line 491
489491 
490492 
491493 message = create_message_with_fast_fallback(
492 model="claude-opus-5",
494 model="claude-opus-5-5",
493495 max_tokens=1024,
494496 messages=[{"role": "user", "content": "Hello"}],
495497 betas=["fast-mode-2026-02-01"],
from line 529
527529 
528530 const message = await createMessageWithFastFallback(
529531 {
530 model: "claude-opus-5",
532 model: "claude-opus-5-5",
531533 max_tokens: 1024,
532534 messages: [{ role: "user", content: "Hello" }],
533535 betas: ["fast-mode-2026-02-01"],
from line 577
575577 var message = await CreateMessageWithFastFallback(
576578 new MessageCreateParams
577579 {
578 Model = "claude-opus-5",
580 Model = "claude-opus-5-5",
579581 MaxTokens = 1024,
580582 Messages = [new() { Role = Role.User, Content = "Hello" }],
581583 Betas = ["fast-mode-2026-02-01"],
from line 617
615617 context.TODO(),
616618 &client,
617619 anthropic.BetaMessageNewParams{
618 Model: anthropic.ModelClaudeOpus5,
620 Model: anthropic.ModelClaudeOpus5_5,
619621 MaxTokens: 1024,
620622 Messages: []anthropic.BetaMessageParam{
621623 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Hello")),
from line 666
664666 void main() {
665667 BetaMessage message = createMessageWithFastFallback(
666668 MessageCreateParams.builder()
667 .model(Model.CLAUDE_OPUS_5)
669 .model(Model.CLAUDE_OPUS_5_5)
668670 .maxTokens(1024L)
669671 .addUserMessage("Hello")
670672 .addBeta(AnthropicBeta.FAST_MODE_2026_02_01)
from line 717
715717 $message = createMessageWithFastFallback(
716718 $client,
717719 [
718 'model' => 'claude-opus-5',
720 'model' => 'claude-opus-5-5',
719721 'maxTokens' => 1024,
720722 'messages' => [['role' => 'user', 'content' => 'Hello']],
721723 'betas' => ['fast-mode-2026-02-01'],
from line 743
741743 
742744 message = create_message_with_fast_fallback(
743745 client,
744 model: "claude-opus-5",
746 model: "claude-opus-5-5",
745747 max_tokens: 1024,
746748 messages: [{ role: "user", content: "Hello" }],
747749 betas: ["fast-mode-2026-02-01"],
from line 756
754756## Considerations
755757 
756758* **Prompt caching:** Switching between fast and standard speed invalidates the prompt cache. Requests at different speeds do not share cached prefixes.
757* **Supported models:** Fast mode is supported on Claude Opus 5 and Claude Opus 4.8. See [Supported models](https://platform.claude.com/docs/en/build-with-claude/fast-mode#supported-models).
759* **Supported models:** Fast mode is supported on Claude Opus 5.5, Claude Opus 5, and Claude Opus 4.8. See [Supported models](https://platform.claude.com/docs/en/build-with-claude/fast-mode#supported-models).
758760* **TTFT:** Fast mode's benefits are focused on output tokens per second (OTPS), not time to first token (TTFT).
759761* **Batch API:** Fast mode is not available with the [Batch API](https://platform.claude.com/docs/en/build-with-claude/batch-processing).
760762* **Priority Tier:** Fast mode is not available with a [Priority Tier](https://platform.claude.com/docs/en/api/service-tiers) commitment.

build-with-claude/files Changed · +18 / -18 lines

from line 179
179179 -H "content-type: application/json" \
180180 -d @- <<EOF
181181 {
182 "model": "claude-opus-5",
182 "model": "claude-opus-5-5",
183183 "max_tokens": 1024,
184184 "messages": [
185185 {
from line 205
205205 
206206 ```bash CLI
207207 ant messages create <<YAML
208 model: claude-opus-5
208 model: claude-opus-5-5
209209 max_tokens: 1024
210210 messages:
211211 - role: user
from line 221
221221 
222222 ```python Python
223223 response = client.messages.create(
224 model="claude-opus-5",
224 model="claude-opus-5-5",
225225 max_tokens=1024,
226226 messages=[
227227 {
from line 244
244244 
245245 ```typescript TypeScript
246246 const response = await client.messages.create({
247 model: "claude-opus-5",
247 model: "claude-opus-5-5",
248248 max_tokens: 1024,
249249 messages: [
250250 {
from line 273
273273 var response = await client.Messages.Create(
274274 new MessageCreateParams
275275 {
276 Model = Model.ClaudeOpus5,
276 Model = Model.ClaudeOpus5_5,
277277 MaxTokens = 1024,
278278 Messages =
279279 [
from line 298
298298 ```go Go
299299 msg, err := client.Messages.New(context.Background(),
300300 anthropic.MessageNewParams{
301 Model: anthropic.ModelClaudeOpus5,
301 Model: anthropic.ModelClaudeOpus5_5,
302302 MaxTokens: 1024,
303303 Messages: []anthropic.MessageParam{
304304 anthropic.NewUserMessage(
from line 318
318318 
319319 ```java Java
320320 MessageCreateParams params = MessageCreateParams.builder()
321 .model(Model.CLAUDE_OPUS_5)
321 .model(Model.CLAUDE_OPUS_5_5)
322322 .maxTokens(1024)
323323 .addUserMessageOfBlockParams(List.of(
324324 ContentBlockParam.ofText(TextBlockParam.builder()
from line 352
352352 ],
353353 ],
354354 ],
355 model: 'claude-opus-5',
355 model: 'claude-opus-5-5',
356356 );
357357 
358358 echo $response;
from line 360
360360 
361361 ```ruby Ruby
362362 response = client.messages.create(
363 model: "claude-opus-5",
363 model: "claude-opus-5-5",
364364 max_tokens: 1024,
365365 messages: [
366366 {
from line 454
454454 -H "anthropic-version: 2023-06-01" \
455455 -d @- <<EOF
456456 {
457 "model": "claude-opus-5",
457 "model": "claude-opus-5-5",
458458 "max_tokens": 1024,
459459 "messages": [
460460 {
from line 474
474474 ```bash CLI
475475 # The "@./path" reference inlines the file contents directly into the field.
476476 ant messages create \
477 --model claude-opus-5 \
477 --model claude-opus-5-5 \
478478 --max-tokens 1024 \
479479 --transform 'content.#(type=="text").text' \
480480 --raw-output <<'YAML'
from line 498
498498 text_content = f.read()
499499 
500500 response = client.messages.create(
501 model="claude-opus-5",
501 model="claude-opus-5-5",
502502 max_tokens=1024,
503503 messages=[
504504 {
from line 527
527527 const textContent = await fs.readFile("document.txt", "utf-8");
528528 
529529 const response = await client.messages.create({
530 model: "claude-opus-5",
530 model: "claude-opus-5-5",
531531 max_tokens: 1024,
532532 messages: [
533533 {
from line 556
556556 
557557 var parameters = new MessageCreateParams
558558 {
559 Model = Model.ClaudeOpus5,
559 Model = Model.ClaudeOpus5_5,
560560 MaxTokens = 1024,
561561 Messages = [new()
562562 {
from line 585
585585 }
586586 
587587 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
588 Model: anthropic.ModelClaudeOpus5,
588 Model: anthropic.ModelClaudeOpus5_5,
589589 MaxTokens: 1024,
590590 Messages: []anthropic.MessageParam{
591591 anthropic.NewUserMessage(anthropic.NewTextBlock(
from line 611
611611 String textContent = Files.readString(Path.of("document.txt"));
612612 
613613 MessageCreateParams params = MessageCreateParams.builder()
614 .model(Model.CLAUDE_OPUS_5)
614 .model(Model.CLAUDE_OPUS_5_5)
615615 .maxTokens(1024L)
616616 .addUserMessage("Here's the document content:\n\n" + textContent + "\n\nPlease summarize this document.")
617617 .build();
from line 641
641641 ]
642642 ]
643643 ],
644 model: 'claude-opus-5',
644 model: 'claude-opus-5-5',
645645 );
646646 
647647 foreach ($message->content as $block) {
from line 658
658658 text_content = File.read("document.txt")
659659 
660660 message = client.messages.create(
661 model: "claude-opus-5",
661 model: "claude-opus-5-5",
662662 max_tokens: 1024,
663663 messages: [
664664 {

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

from line 58
5858 -H "anthropic-version: 2023-06-01" \
5959 -H "content-type: application/json" \
6060 -d '{
61 "model": "claude-opus-5",
61 "model": "claude-opus-5-5",
6262 "max_tokens": 1024,
6363 "messages": [{"role": "user", "content": "Hello!"}]
6464 }' | jq 'if .stop_reason == "end_turn" then (.content[] | select(.type == "text") | .text) else . end'
from line 66
6666 
6767 ```bash CLI
6868 ant messages create \
69 --model claude-opus-5 \
69 --model claude-opus-5-5 \
7070 --max-tokens 1024 \
7171 --message '{role: user, content: "Hello!"}' \
7272 --format json | jq 'if .stop_reason == "end_turn" then (.content[] | select(.type == "text") | .text) else . end'
from line 76
7676 client = anthropic.Anthropic()
7777 
7878 response = client.messages.create(
79 model="claude-opus-5",
79 model="claude-opus-5-5",
8080 max_tokens=1024,
8181 messages=[{"role": "user", "content": "Hello!"}],
8282 )
from line 91
9191 const client = new Anthropic();
9292 
9393 const response = await client.messages.create({
94 model: "claude-opus-5",
94 model: "claude-opus-5-5",
9595 max_tokens: 1024,
9696 messages: [{ role: "user", content: "Hello!" }]
9797 });
from line 110
110110 
111111 var response = await client.Messages.Create(new MessageCreateParams
112112 {
113 Model = Model.ClaudeOpus5,
113 Model = Model.ClaudeOpus5_5,
114114 MaxTokens = 1024,
115115 Messages = [new() { Role = Role.User, Content = "Hello!" }]
116116 });
from line 132
132132 client := anthropic.NewClient()
133133 
134134 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
135 Model: anthropic.ModelClaudeOpus5,
135 Model: anthropic.ModelClaudeOpus5_5,
136136 MaxTokens: 1024,
137137 Messages: []anthropic.MessageParam{
138138 anthropic.NewUserMessage(anthropic.NewTextBlock("Hello!")),
from line 157
157157 
158158 Message response = client.messages().create(
159159 MessageCreateParams.builder()
160 .model(Model.CLAUDE_OPUS_5)
160 .model(Model.CLAUDE_OPUS_5_5)
161161 .maxTokens(1024L)
162162 .addUserMessage("Hello!")
163163 .build()
from line 177
177177 $response = $client->messages->create(
178178 maxTokens: 1024,
179179 messages: [['role' => 'user', 'content' => 'Hello!']],
180 model: 'claude-opus-5',
180 model: 'claude-opus-5-5',
181181 );
182182 
183183 if ($response->stopReason === 'end_turn') {
from line 194
194194 client = Anthropic::Client.new
195195 
196196 response = client.messages.create(
197 model: "claude-opus-5",
197 model: "claude-opus-5-5",
198198 max_tokens: 1024,
199199 messages: [{ role: "user", content: "Hello!" }]
200200 )
from line 544
544544 ```python Python
545545 def handle_empty_response(client, messages):
546546 response = client.messages.create(
547 model="claude-opus-5", max_tokens=1024, messages=messages
547 model="claude-opus-5-5", max_tokens=1024, messages=messages
548548 )
549549 
550550 # Check if response is empty
from line 556
556556 messages.append({"role": "user", "content": "Please continue"})
557557 
558558 response = client.messages.create(
559 model="claude-opus-5", max_tokens=1024, messages=messages
559 model="claude-opus-5-5", max_tokens=1024, messages=messages
560560 )
561561 
562562 return response
from line 568
568568 messages: Anthropic.MessageParam[]
569569 ): Promise<Anthropic.Message> {
570570 let response = await client.messages.create({
571 model: "claude-opus-5",
571 model: "claude-opus-5-5",
572572 max_tokens: 1024,
573573 messages
574574 });
from line 582
582582 messages.push({ role: "user", content: "Please continue" });
583583 
584584 response = await client.messages.create({
585 model: "claude-opus-5",
585 model: "claude-opus-5-5",
586586 max_tokens: 1024,
587587 messages
588588 });
from line 597
597597 {
598598 var response = await client.Messages.Create(new MessageCreateParams
599599 {
600 Model = Model.ClaudeOpus5,
600 Model = Model.ClaudeOpus5_5,
601601 MaxTokens = 1024,
602602 Messages = messages
603603 });
from line 610
610610 
611611 response = await client.Messages.Create(new MessageCreateParams
612612 {
613 Model = Model.ClaudeOpus5,
613 Model = Model.ClaudeOpus5_5,
614614 MaxTokens = 1024,
615615 Messages = messages
616616 });
from line 623
623623 ```go Go
624624 func handleEmptyResponse(client anthropic.Client, messages []anthropic.MessageParam) (*anthropic.Message, error) {
625625 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
626 Model: anthropic.ModelClaudeOpus5,
626 Model: anthropic.ModelClaudeOpus5_5,
627627 MaxTokens: 1024,
628628 Messages: messages,
629629 })
from line 637
637637 messages = append(messages, anthropic.NewUserMessage(anthropic.NewTextBlock("Please continue")))
638638 
639639 response, err = client.Messages.New(context.TODO(), anthropic.MessageNewParams{
640 Model: anthropic.ModelClaudeOpus5,
640 Model: anthropic.ModelClaudeOpus5_5,
641641 MaxTokens: 1024,
642642 Messages: messages,
643643 })
from line 654
654654 static Message handleEmptyResponse(AnthropicClient client, List<MessageParam> messages) {
655655 Message response = client.messages().create(
656656 MessageCreateParams.builder()
657 .model(Model.CLAUDE_OPUS_5)
657 .model(Model.CLAUDE_OPUS_5_5)
658658 .maxTokens(1024L)
659659 .messages(messages)
660660 .build()
from line 672
672672 
673673 response = client.messages().create(
674674 MessageCreateParams.builder()
675 .model(Model.CLAUDE_OPUS_5)
675 .model(Model.CLAUDE_OPUS_5_5)
676676 .maxTokens(1024L)
677677 .messages(extended)
678678 .build()
from line 689
689689 $response = $client->messages->create(
690690 maxTokens: 1024,
691691 messages: $messages,
692 model: 'claude-opus-5',
692 model: 'claude-opus-5-5',
693693 );
694694 
695695 // Check if response is empty
from line 700
700700 $response = $client->messages->create(
701701 maxTokens: 1024,
702702 messages: $messages,
703 model: 'claude-opus-5',
703 model: 'claude-opus-5-5',
704704 );
705705 }
706706 
from line 711
711711 ```ruby Ruby
712712 def handle_empty_response(client, messages)
713713 response = client.messages.create(
714 model: "claude-opus-5",
714 model: "claude-opus-5-5",
715715 max_tokens: 1024,
716716 messages: messages
717717 )
from line 722
722722 messages << { role: "user", content: "Please continue" }
723723 
724724 response = client.messages.create(
725 model: "claude-opus-5",
725 model: "claude-opus-5-5",
726726 max_tokens: 1024,
727727 messages: messages
728728 )
from line 751
751751 -H "anthropic-version: 2023-06-01" \
752752 -H "content-type: application/json" \
753753 -d '{
754 "model": "claude-opus-5",
754 "model": "claude-opus-5-5",
755755 "max_tokens": 10,
756756 "messages": [{"role": "user", "content": "Explain quantum physics"}]
757757 }' | jq '.stop_reason'
from line 759
759759 
760760 ```bash CLI
761761 ant messages create \
762 --model claude-opus-5 \
762 --model claude-opus-5-5 \
763763 --max-tokens 10 \
764764 --message '{role: user, content: "Explain quantum physics"}' \
765765 --format json | jq '.stop_reason'
from line 769
769769 client = anthropic.Anthropic()
770770 # Request with limited tokens
771771 response = client.messages.create(
772 model="claude-opus-5",
772 model="claude-opus-5-5",
773773 max_tokens=10,
774774 messages=[{"role": "user", "content": "Explain quantum physics"}],
775775 )
from line 785
785785 
786786 // Request with limited tokens
787787 const response = await client.messages.create({
788 model: "claude-opus-5",
788 model: "claude-opus-5-5",
789789 max_tokens: 10,
790790 messages: [{ role: "user", content: "Explain quantum physics" }]
791791 });
from line 803
803803 // Request with limited tokens
804804 var response = await client.Messages.Create(new MessageCreateParams
805805 {
806 Model = Model.ClaudeOpus5,
806 Model = Model.ClaudeOpus5_5,
807807 MaxTokens = 10,
808808 Messages = [new() { Role = Role.User, Content = "Explain quantum physics" }]
809809 });
from line 821
821821 
822822 // Request with limited tokens
823823 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
824 Model: anthropic.ModelClaudeOpus5,
824 Model: anthropic.ModelClaudeOpus5_5,
825825 MaxTokens: 10,
826826 Messages: []anthropic.MessageParam{
827827 anthropic.NewUserMessage(anthropic.NewTextBlock("Explain quantum physics")),
from line 844
844844 // Request with limited tokens
845845 Message response = client.messages().create(
846846 MessageCreateParams.builder()
847 .model(Model.CLAUDE_OPUS_5)
847 .model(Model.CLAUDE_OPUS_5_5)
848848 .maxTokens(10L)
849849 .addUserMessage("Explain quantum physics")
850850 .build()
from line 864
864864 $response = $client->messages->create(
865865 maxTokens: 10,
866866 messages: [['role' => 'user', 'content' => 'Explain quantum physics']],
867 model: 'claude-opus-5',
867 model: 'claude-opus-5-5',
868868 );
869869 
870870 if ($response->stopReason === 'max_tokens') {
from line 879
879879 
880880 # Request with limited tokens
881881 response = client.messages.create(
882 model: "claude-opus-5",
882 model: "claude-opus-5-5",
883883 max_tokens: 10,
884884 messages: [{ role: "user", content: "Explain quantum physics" }]
885885 )
from line 916
916916 if last_block.type == "tool_use":
917917 # Send the request with higher max_tokens
918918 response = client.messages.create(
919 model="claude-opus-5",
919 model="claude-opus-5-5",
920920 max_tokens=4096, # Increased limit
921921 messages=messages,
922922 tools=tools,
from line 931
931931 if (lastBlock.type === "tool_use") {
932932 // Send the request with higher max_tokens
933933 response = await client.messages.create({
934 model: "claude-opus-5",
934 model: "claude-opus-5-5",
935935 max_tokens: 4096, // Increased limit
936936 messages: messages,
937937 tools: tools
from line 949
949949 
950950 var parameters = new MessageCreateParams
951951 {
952 Model = Model.ClaudeOpus5,
952 Model = Model.ClaudeOpus5_5,
953953 MaxTokens = 1024,
954954 Messages = messages,
955955 Tools = tools
from line 969
969969 
970970 ```go Go
971971 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
972 Model: anthropic.ModelClaudeOpus5,
972 Model: anthropic.ModelClaudeOpus5_5,
973973 MaxTokens: 1024,
974974 Messages: messages,
975975 Tools: tools,
from line 983
983983 switch lastBlock.AsAny().(type) {
984984 case anthropic.ToolUseBlock:
985985 response, err = client.Messages.New(context.TODO(), anthropic.MessageNewParams{
986 Model: anthropic.ModelClaudeOpus5,
986 Model: anthropic.ModelClaudeOpus5_5,
987987 MaxTokens: 4096,
988988 Messages: messages,
989989 Tools: tools,
from line 1003
10031003 // Send the request with higher max_tokens
10041004 response = client.messages().create(
10051005 MessageCreateParams.builder()
1006 .model(Model.CLAUDE_OPUS_5)
1006 .model(Model.CLAUDE_OPUS_5_5)
10071007 .maxTokens(4096L) // Increased limit
10081008 .messages(messages)
10091009 .tools(tools)
from line 1017
10171017 $response = $client->messages->create(
10181018 maxTokens: 1024,
10191019 messages: $messages,
1020 model: 'claude-opus-5',
1020 model: 'claude-opus-5-5',
10211021 tools: $tools,
10221022 );
10231023 
from line 1027
10271027 $response = $client->messages->create(
10281028 maxTokens: 4096,
10291029 messages: $messages,
1030 model: 'claude-opus-5',
1030 model: 'claude-opus-5-5',
10311031 tools: $tools,
10321032 );
10331033 }
from line 1036
10361036 
10371037 ```ruby Ruby
10381038 response = client.messages.create(
1039 model: "claude-opus-5",
1039 model: "claude-opus-5-5",
10401040 max_tokens: 1024,
10411041 messages: messages,
10421042 tools: tools
from line 1046
10461046 last_block = response.content.last
10471047 if last_block.type == :tool_use
10481048 response = client.messages.create(
1049 model: "claude-opus-5",
1049 model: "claude-opus-5-5",
10501050 max_tokens: 4096,
10511051 messages: messages,
10521052 tools: tools
from line 1068
10681068 -H "anthropic-version: 2023-06-01" \
10691069 -H "content-type: application/json" \
10701070 -d '{
1071 "model": "claude-opus-5",
1071 "model": "claude-opus-5-5",
10721072 "max_tokens": 1024,
10731073 "stop_sequences": ["END", "STOP"],
10741074 "messages": [{"role": "user", "content": "Generate text until you say END"}]
from line 1077
10771077 
10781078 ```bash CLI
10791079 ant messages create \
1080 --model claude-opus-5 \
1080 --model claude-opus-5-5 \
10811081 --max-tokens 1024 \
10821082 --stop-sequence END --stop-sequence STOP \
10831083 --message '{role: user, content: "Generate text until you say END"}' \
from line 1087
10871087 ```python Python
10881088 client = anthropic.Anthropic()
10891089 response = client.messages.create(
1090 model="claude-opus-5",
1090 model="claude-opus-5-5",
10911091 max_tokens=1024,
10921092 stop_sequences=["END", "STOP"],
10931093 messages=[{"role": "user", "content": "Generate text until you say END"}],
from line 1101
11011101 const client = new Anthropic();
11021102 
11031103 const response = await client.messages.create({
1104 model: "claude-opus-5",
1104 model: "claude-opus-5-5",
11051105 max_tokens: 1024,
11061106 stop_sequences: ["END", "STOP"],
11071107 messages: [{ role: "user", content: "Generate text until you say END" }]
from line 1117
11171117 
11181118 var response = await client.Messages.Create(new MessageCreateParams
11191119 {
1120 Model = Model.ClaudeOpus5,
1120 Model = Model.ClaudeOpus5_5,
11211121 MaxTokens = 1024,
11221122 StopSequences = ["END", "STOP"],
11231123 Messages = [new() { Role = Role.User, Content = "Generate text until you say END" }]
from line 1133
11331133 client := anthropic.NewClient()
11341134 
11351135 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1136 Model: anthropic.ModelClaudeOpus5,
1136 Model: anthropic.ModelClaudeOpus5_5,
11371137 MaxTokens: 1024,
11381138 StopSequences: []string{"END", "STOP"},
11391139 Messages: []anthropic.MessageParam{
from line 1154
11541154 
11551155 Message response = client.messages().create(
11561156 MessageCreateParams.builder()
1157 .model(Model.CLAUDE_OPUS_5)
1157 .model(Model.CLAUDE_OPUS_5_5)
11581158 .maxTokens(1024L)
11591159 .addStopSequence("END")
11601160 .addStopSequence("STOP")
from line 1173
11731173 $response = $client->messages->create(
11741174 maxTokens: 1024,
11751175 messages: [['role' => 'user', 'content' => 'Generate text until you say END']],
1176 model: 'claude-opus-5',
1176 model: 'claude-opus-5-5',
11771177 stopSequences: ['END', 'STOP'],
11781178 );
11791179 
from line 1186
11861186 client = Anthropic::Client.new
11871187 
11881188 response = client.messages.create(
1189 model: "claude-opus-5",
1189 model: "claude-opus-5-5",
11901190 max_tokens: 1024,
11911191 stop_sequences: ["END", "STOP"],
11921192 messages: [{ role: "user", content: "Generate text until you say END" }]
from line 1213
12131213 -H "anthropic-version: 2023-06-01" \
12141214 -H "content-type: application/json" \
12151215 -d '{
1216 "model": "claude-opus-5",
1216 "model": "claude-opus-5-5",
12171217 "max_tokens": 1024,
12181218 "tools": [{
12191219 "name": "get_weather",
from line 1230
12301230 
12311231 ```bash CLI
12321232 ant messages create --format json <<'YAML' | jq '.stop_reason, (.content[] | select(.type == "tool_use"))'
1233 model: claude-opus-5
1233 model: claude-opus-5-5
12341234 max_tokens: 1024
12351235 messages:
12361236 - role: user
from line 1267
12671267 
12681268 
12691269 response = client.messages.create(
1270 model="claude-opus-5",
1270 model="claude-opus-5-5",
12711271 max_tokens=1024,
12721272 tools=[weather_tool],
12731273 messages=[{"role": "user", "content": "What is the weather in San Francisco?"}],
from line 1300
13001300 }
13011301 
13021302 const response = await client.messages.create({
1303 model: "claude-opus-5",
1303 model: "claude-opus-5-5",
13041304 max_tokens: 1024,
13051305 tools: [weatherTool],
13061306 messages: [{ role: "user", content: "What is the weather in San Francisco?" }]
from line 1338
13381338 
13391339 var response = await client.Messages.Create(new MessageCreateParams
13401340 {
1341 Model = Model.ClaudeOpus5,
1341 Model = Model.ClaudeOpus5_5,
13421342 MaxTokens = 1024,
13431343 Tools = [weatherTool],
13441344 Messages = [new() { Role = Role.User, Content = "What is the weather in San Francisco?" }]
from line 1372
13721372 }
13731373 
13741374 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1375 Model: anthropic.ModelClaudeOpus5,
1375 Model: anthropic.ModelClaudeOpus5_5,
13761376 MaxTokens: 1024,
13771377 Tools: []anthropic.ToolUnionParam{{OfTool: &weatherTool}},
13781378 Messages: []anthropic.MessageParam{
from line 1411
14111411 
14121412 Message response = client.messages().create(
14131413 MessageCreateParams.builder()
1414 .model(Model.CLAUDE_OPUS_5)
1414 .model(Model.CLAUDE_OPUS_5_5)
14151415 .maxTokens(1024L)
14161416 .addTool(weatherTool)
14171417 .addUserMessage("What is the weather in San Francisco?")
from line 1446
14461446 $response = $client->messages->create(
14471447 maxTokens: 1024,
14481448 messages: [['role' => 'user', 'content' => 'What is the weather in San Francisco?']],
1449 model: 'claude-opus-5',
1449 model: 'claude-opus-5-5',
14501450 tools: [$weatherTool],
14511451 );
14521452 
from line 1476
14761476 }
14771477 
14781478 response = client.messages.create(
1479 model: "claude-opus-5",
1479 model: "claude-opus-5-5",
14801480 max_tokens: 1024,
14811481 tools: [weather_tool],
14821482 messages: [{ role: "user", content: "What is the weather in San Francisco?" }]
from line 1556
15561556 -H "anthropic-version: 2023-06-01" \
15571557 -H "content-type: application/json" \
15581558 -d '{
1559 "model": "claude-opus-5",
1559 "model": "claude-opus-5-5",
15601560 "max_tokens": 4096,
15611561 "tools": [{"type": "web_search_20250305", "name": "web_search"}],
15621562 "messages": [{"role": "user", "content": "Search for latest AI news"}]
from line 1567
15671567 # Inspect stop_reason; if it is pause_turn, re-run with the assistant
15681568 # response appended to --message.
15691569 ant messages create --format json <<'YAML' | jq '{stop_reason, content}'
1570 model: claude-opus-5
1570 model: claude-opus-5-5
15711571 max_tokens: 4096
15721572 tools:
15731573 - {type: web_search_20250305, name: web_search}
from line 1578
15781578 
15791579 ```python Python
15801580 response = client.messages.create(
1581 model="claude-opus-5",
1581 model="claude-opus-5-5",
15821582 max_tokens=4096,
15831583 tools=[{"type": "web_search_20250305", "name": "web_search"}],
15841584 messages=[{"role": "user", "content": "Search for latest AI news"}],
from line 1591
15911591 {"role": "assistant", "content": response.content},
15921592 ]
15931593 continuation = client.messages.create(
1594 model="claude-opus-5",
1594 model="claude-opus-5-5",
15951595 max_tokens=4096,
15961596 messages=messages,
15971597 tools=[{"type": "web_search_20250305", "name": "web_search"}],
from line 1600
16001600 
16011601 ```typescript TypeScript
16021602 const response = await client.messages.create({
1603 model: "claude-opus-5",
1603 model: "claude-opus-5-5",
16041604 max_tokens: 4096,
16051605 tools: [{ type: "web_search_20250305", name: "web_search" }],
16061606 messages: [{ role: "user", content: "Search for latest AI news" }]
from line 1609
16091609 if (response.stop_reason === "pause_turn") {
16101610 // Continue the conversation by sending the response back
16111611 const continuation = await client.messages.create({
1612 model: "claude-opus-5",
1612 model: "claude-opus-5-5",
16131613 max_tokens: 4096,
16141614 tools: [{ type: "web_search_20250305", name: "web_search" }],
16151615 messages: [
from line 1626
16261626 
16271627 var response = await client.Messages.Create(new MessageCreateParams
16281628 {
1629 Model = Model.ClaudeOpus5,
1629 Model = Model.ClaudeOpus5_5,
16301630 MaxTokens = 4096,
16311631 Tools = tools,
16321632 Messages = [userMessage]
from line 1637
16371637 // Continue the conversation by sending the response back
16381638 var continuation = await client.Messages.Create(new MessageCreateParams
16391639 {
1640 Model = Model.ClaudeOpus5,
1640 Model = Model.ClaudeOpus5_5,
16411641 MaxTokens = 4096,
16421642 Tools = tools,
16431643 Messages =
from line 1660
16601660 userMessage := anthropic.NewUserMessage(anthropic.NewTextBlock("Search for latest AI news"))
16611661 
16621662 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1663 Model: anthropic.ModelClaudeOpus5,
1663 Model: anthropic.ModelClaudeOpus5_5,
16641664 MaxTokens: 4096,
16651665 Tools: tools,
16661666 Messages: []anthropic.MessageParam{userMessage},
from line 1676
16761676 contentParams = append(contentParams, block.ToParam())
16771677 }
16781678 continuation, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1679 Model: anthropic.ModelClaudeOpus5,
1679 Model: anthropic.ModelClaudeOpus5_5,
16801680 MaxTokens: 4096,
16811681 Tools: tools,
16821682 Messages: []anthropic.MessageParam{userMessage, anthropic.NewAssistantMessage(contentParams...)},
from line 1691
16911691 ```java Java
16921692 Message response = client.messages().create(
16931693 MessageCreateParams.builder()
1694 .model(Model.CLAUDE_OPUS_5)
1694 .model(Model.CLAUDE_OPUS_5_5)
16951695 .maxTokens(4096L)
16961696 .addTool(WebSearchTool20250305.builder().build())
16971697 .addUserMessage("Search for latest AI news")
from line 1702
17021702 // Continue the conversation by sending the response back
17031703 Message continuation = client.messages().create(
17041704 MessageCreateParams.builder()
1705 .model(Model.CLAUDE_OPUS_5)
1705 .model(Model.CLAUDE_OPUS_5_5)
17061706 .maxTokens(4096L)
17071707 .addTool(WebSearchTool20250305.builder().build())
17081708 .addUserMessage("Search for latest AI news")
from line 1719
17191719 $response = $client->messages->create(
17201720 maxTokens: 4096,
17211721 messages: [$userMessage],
1722 model: 'claude-opus-5',
1722 model: 'claude-opus-5-5',
17231723 tools: $tools,
17241724 );
17251725 
from line 1731
17311731 $userMessage,
17321732 ['role' => 'assistant', 'content' => $response->content],
17331733 ],
1734 model: 'claude-opus-5',
1734 model: 'claude-opus-5-5',
17351735 tools: $tools,
17361736 );
17371737 }
from line 1742
17421742 user_message = { role: "user", content: "Search for latest AI news" }
17431743 
17441744 response = client.messages.create(
1745 model: "claude-opus-5",
1745 model: "claude-opus-5-5",
17461746 max_tokens: 4096,
17471747 tools: tools,
17481748 messages: [user_message]
from line 1751
17511751 if response.stop_reason == :pause_turn
17521752 # Continue the conversation by sending the response back
17531753 continuation = client.messages.create(
1754 model: "claude-opus-5",
1754 model: "claude-opus-5-5",
17551755 max_tokens: 4096,
17561756 tools: tools,
17571757 messages: [user_message, { role: "assistant", content: response.content }]
from line 1775
17751775 -H "anthropic-version: 2023-06-01" \
17761776 -H "content-type: application/json" \
17771777 -d '{
1778 "model": "claude-opus-5",
1778 "model": "claude-opus-5-5",
17791779 "max_tokens": 1024,
17801780 "messages": [{"role": "user", "content": "[Unsafe request]"}]
17811781 }' | jq '{stop_reason, stop_details}'
from line 1783
17831783 
17841784 ```bash CLI
17851785 ant messages create \
1786 --model claude-opus-5 \
1786 --model claude-opus-5-5 \
17871787 --max-tokens 1024 \
17881788 --message '{role: user, content: "[Unsafe request]"}' \
17891789 --format json | jq '{stop_reason, stop_details}'
from line 1792
17921792 ```python Python
17931793 client = anthropic.Anthropic()
17941794 response = client.messages.create(
1795 model="claude-opus-5",
1795 model="claude-opus-5-5",
17961796 max_tokens=1024,
17971797 messages=[{"role": "user", "content": "[Unsafe request]"}],
17981798 )
from line 1807
18071807 const client = new Anthropic();
18081808 
18091809 const response = await client.messages.create({
1810 model: "claude-opus-5",
1810 model: "claude-opus-5-5",
18111811 max_tokens: 1024,
18121812 messages: [{ role: "user", content: "[Unsafe request]" }]
18131813 });
from line 1824
18241824 
18251825 var response = await client.Messages.Create(new MessageCreateParams
18261826 {
1827 Model = Model.ClaudeOpus5,
1827 Model = Model.ClaudeOpus5_5,
18281828 MaxTokens = 1024,
18291829 Messages = [new() { Role = Role.User, Content = "[Unsafe request]" }]
18301830 });
from line 1841
18411841 client := anthropic.NewClient()
18421842 
18431843 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1844 Model: anthropic.ModelClaudeOpus5,
1844 Model: anthropic.ModelClaudeOpus5_5,
18451845 MaxTokens: 1024,
18461846 Messages: []anthropic.MessageParam{
18471847 anthropic.NewUserMessage(anthropic.NewTextBlock("[Unsafe request]")),
from line 1863
18631863 
18641864 Message response = client.messages().create(
18651865 MessageCreateParams.builder()
1866 .model(Model.CLAUDE_OPUS_5)
1866 .model(Model.CLAUDE_OPUS_5_5)
18671867 .maxTokens(1024L)
18681868 .addUserMessage("[Unsafe request]")
18691869 .build()
from line 1882
18821882 $response = $client->messages->create(
18831883 maxTokens: 1024,
18841884 messages: [['role' => 'user', 'content' => '[Unsafe request]']],
1885 model: 'claude-opus-5',
1885 model: 'claude-opus-5-5',
18861886 );
18871887 
18881888 if ($response->stopReason === 'refusal') {
from line 1896
18961896 client = Anthropic::Client.new
18971897 
18981898 response = client.messages.create(
1899 model: "claude-opus-5",
1899 model: "claude-opus-5-5",
19001900 max_tokens: 1024,
19011901 messages: [{ role: "user", content: "[Unsafe request]" }]
19021902 )
from line 1915
19151915 
19161916On 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`.
19171917 
1918A refused request on Claude Fable 5.1, Claude Fable 5, or Claude Opus 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. If you build the retry yourself from Claude Fable 5.1, Claude Fable 5, or Claude Opus 5, [fallback credit](https://platform.claude.com/docs/en/build-with-claude/fallback-credit) covers how to avoid paying the prompt-cache cost twice.
1918A refused request on Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, or Claude Opus 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. If you build the retry yourself from Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, or Claude Opus 5, [fallback credit](https://platform.claude.com/docs/en/build-with-claude/fallback-credit) covers how to avoid paying the prompt-cache cost twice.
19191919 
19201920### model\_context\_window\_exceeded
19211921 
from line 1932
19321932 -H "anthropic-version: 2023-06-01" \
19331933 -H "content-type: application/json" \
19341934 -d '{
1935 "model": "claude-opus-5",
1935 "model": "claude-opus-5-5",
19361936 "max_tokens": 20000,
19371937 "messages": [{"role": "user", "content": "Large input that uses most of context window..."}]
19381938 }' | jq '.stop_reason'
from line 1940
19401940 
19411941 ```bash CLI
19421942 ant messages create \
1943 --model claude-opus-5 \
1943 --model claude-opus-5-5 \
19441944 --max-tokens 20000 \
19451945 --message '{role: user, content: "Large input that uses most of context window..."}' \
19461946 --format json | jq '.stop_reason'
from line 1949
19491949 ```python Python
19501950 # Request with maximum tokens to get as much as possible
19511951 response = client.beta.messages.create(
1952 model="claude-opus-5",
1952 model="claude-opus-5-5",
19531953 max_tokens=20000, # Python SDK requires streaming for max_tokens above ~21k
19541954 messages=[
19551955 {"role": "user", "content": "Large input that uses most of context window..."}
from line 1965
19651965 ```typescript TypeScript
19661966 // Request with maximum tokens to get as much as possible
19671967 const response = await client.beta.messages.create({
1968 model: "claude-opus-5",
1968 model: "claude-opus-5-5",
19691969 max_tokens: 20000,
19701970 messages: [{ role: "user", content: "Large input that uses most of context window..." }]
19711971 });
from line 1984
19841984 // Request with maximum tokens to get as much as possible
19851985 var response = await client.Beta.Messages.Create(new MessageCreateParams
19861986 {
1987 Model = Model.ClaudeOpus5,
1987 Model = Model.ClaudeOpus5_5,
19881988 MaxTokens = 20000,
19891989 Messages = [new() { Role = Role.User, Content = "Large input that uses most of context window..." }]
19901990 });
from line 2000
20002000 ```go Go
20012001 // Request with maximum tokens to get as much as possible
20022002 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
2003 Model: anthropic.ModelClaudeOpus5,
2003 Model: anthropic.ModelClaudeOpus5_5,
20042004 MaxTokens: 20000,
20052005 Messages: []anthropic.BetaMessageParam{
20062006 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Large input that uses most of context window...")),
from line 2025
20252025 // Request with maximum tokens to get as much as possible
20262026 BetaMessage response = client.beta().messages().create(
20272027 MessageCreateParams.builder()
2028 .model(Model.CLAUDE_OPUS_5)
2028 .model(Model.CLAUDE_OPUS_5_5)
20292029 .maxTokens(20000L)
20302030 .addUserMessage("Large input that uses most of context window...")
20312031 .build()
from line 2043
20432043 $response = $client->beta->messages->create(
20442044 maxTokens: 20000,
20452045 messages: [['role' => 'user', 'content' => 'Large input that uses most of context window...']],
2046 model: 'claude-opus-5',
2046 model: 'claude-opus-5-5',
20472047 );
20482048 
20492049 if ($response->stopReason === 'model_context_window_exceeded') {
from line 2056
20562056 ```ruby Ruby
20572057 # Request with maximum tokens to get as much as possible
20582058 response = client.beta.messages.create(
2059 model: "claude-opus-5",
2059 model: "claude-opus-5-5",
20602060 max_tokens: 20000,
20612061 messages: [{ role: "user", content: "Large input that uses most of context window..." }]
20622062 )
from line 2363
23632363 
23642364 for _ in range(max_continuations):
23652365 response = client.messages.create(
2366 model="claude-opus-5", max_tokens=4096, messages=messages, tools=tools
2366 model="claude-opus-5-5", max_tokens=4096, messages=messages, tools=tools
23672367 )
23682368 
23692369 if response.stop_reason != "pause_turn":
from line 2392
23922392 
23932393 for (let i = 0; i < maxContinuations; i++) {
23942394 response = await client.messages.create({
2395 model: "claude-opus-5",
2395 model: "claude-opus-5-5",
23962396 max_tokens: 4096,
23972397 messages,
23982398 tools
from line 2429
24292429 {
24302430 response = await client.Messages.Create(new MessageCreateParams
24312431 {
2432 Model = Model.ClaudeOpus5,
2432 Model = Model.ClaudeOpus5_5,
24332433 MaxTokens = 4096,
24342434 Messages = messages,
24352435 Tools = tools
from line 2471
24712471 
24722472 for range maxContinuations {
24732473 response, err = client.Messages.New(context.TODO(), anthropic.MessageNewParams{
2474 Model: anthropic.ModelClaudeOpus5,
2474 Model: anthropic.ModelClaudeOpus5_5,
24752475 MaxTokens: 4096,
24762476 Messages: messages,
24772477 Tools: tools,
from line 2513
25132513 for (int i = 0; i < maxContinuations; i++) {
25142514 // Rebuild the params each iteration so messages aren't accumulated
25152515 MessageCreateParams.Builder params = MessageCreateParams.builder()
2516 .model(Model.CLAUDE_OPUS_5)
2516 .model(Model.CLAUDE_OPUS_5_5)
25172517 .maxTokens(4096L)
25182518 .addUserMessage(userQuery);
25192519 tools.forEach(params::addTool);
from line 2549
25492549 $response = $client->messages->create(
25502550 maxTokens: 4096,
25512551 messages: $messages,
2552 model: 'claude-opus-5',
2552 model: 'claude-opus-5-5',
25532553 tools: $tools,
25542554 );
25552555 
from line 2577
25772577 
25782578 max_continuations.times do
25792579 response = client.messages.create(
2580 model: "claude-opus-5",
2580 model: "claude-opus-5-5",
25812581 max_tokens: 4096,
25822582 messages: messages,
25832583 tools: tools
from line 2624
26242624 -H "anthropic-version: 2023-06-01" \
26252625 -H "content-type: application/json" \
26262626 -d '{
2627 "model": "claude-opus-5",
2627 "model": "claude-opus-5-5",
26282628 "max_tokens": 1024,
26292629 "messages": [{"role": "user", "content": "Hello!"}]
26302630 }' | jq '.stop_reason'
from line 2633
26332633 ```bash CLI
26342634 # The CLI exits non-zero on API errors; stop_reason appears on success.
26352635 ant messages create \
2636 --model claude-opus-5 \
2636 --model claude-opus-5-5 \
26372637 --max-tokens 1024 \
26382638 --message '{role: user, content: "Hello!"}' \
26392639 --format json | jq '.stop_reason'
from line 2644
26442644 
26452645 try:
26462646 response = client.messages.create(
2647 model="claude-opus-5",
2647 model="claude-opus-5-5",
26482648 max_tokens=1024,
26492649 messages=[{"role": "user", "content": "Hello!"}],
26502650 )
from line 2667
26672667 
26682668 try {
26692669 const response = await client.messages.create({
2670 model: "claude-opus-5",
2670 model: "claude-opus-5-5",
26712671 max_tokens: 1024,
26722672 messages: [{ role: "user", content: "Hello!" }]
26732673 });
from line 2700
27002700 {
27012701 var response = await client.Messages.Create(new MessageCreateParams
27022702 {
2703 Model = Model.ClaudeOpus5,
2703 Model = Model.ClaudeOpus5_5,
27042704 MaxTokens = 1024,
27052705 Messages = [new() { Role = Role.User, Content = "Hello!" }]
27062706 });
from line 2726
27262726 client := anthropic.NewClient()
27272727 
27282728 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
2729 Model: anthropic.ModelClaudeOpus5,
2729 Model: anthropic.ModelClaudeOpus5_5,
27302730 MaxTokens: 1024,
27312731 Messages: []anthropic.MessageParam{
27322732 anthropic.NewUserMessage(anthropic.NewTextBlock("Hello!")),
from line 2758
27582758 try {
27592759 Message response = client.messages().create(
27602760 MessageCreateParams.builder()
2761 .model(Model.CLAUDE_OPUS_5)
2761 .model(Model.CLAUDE_OPUS_5_5)
27622762 .maxTokens(1024L)
27632763 .addUserMessage("Hello!")
27642764 .build()
from line 2785
27852785 $response = $client->messages->create(
27862786 maxTokens: 1024,
27872787 messages: [['role' => 'user', 'content' => 'Hello!']],
2788 model: 'claude-opus-5',
2788 model: 'claude-opus-5-5',
27892789 );
27902790 
27912791 // Handle successful response with stop_reason
from line 2805
28052805 
28062806 begin
28072807 response = client.messages.create(
2808 model: "claude-opus-5",
2808 model: "claude-opus-5-5",
28092809 max_tokens: 1024,
28102810 messages: [{ role: "user", content: "Hello!" }]
28112811 )
from line 2839
28392839 -H "anthropic-version: 2023-06-01" \
28402840 -H "content-type: application/json" \
28412841 -d '{
2842 "model": "claude-opus-5",
2842 "model": "claude-opus-5-5",
28432843 "max_tokens": 1024,
28442844 "stream": true,
28452845 "messages": [{"role": "user", "content": "Hello!"}]
from line 2849
28492849 ```bash CLI
28502850 # stop_reason appears in the message_delta event.
28512851 ant messages create --stream --format jsonl \
2852 --model claude-opus-5 \
2852 --model claude-opus-5-5 \
28532853 --max-tokens 1024 \
28542854 --message '{role: user, content: "Hello!"}' |
28552855 jq -c 'select(.type == "message_delta") | .delta.stop_reason'
from line 2859
28592859 client = anthropic.Anthropic()
28602860 
28612861 with client.messages.stream(
2862 model="claude-opus-5",
2862 model="claude-opus-5-5",
28632863 max_tokens=1024,
28642864 messages=[{"role": "user", "content": "Hello!"}],
28652865 ) as stream:
from line 2874
28742874 const client = new Anthropic();
28752875 
28762876 const stream = client.messages.stream({
2877 model: "claude-opus-5",
2877 model: "claude-opus-5-5",
28782878 max_tokens: 1024,
28792879 messages: [{ role: "user", content: "Hello!" }]
28802880 });
from line 2891
28912891 
28922892 var parameters = new MessageCreateParams
28932893 {
2894 Model = Model.ClaudeOpus5,
2894 Model = Model.ClaudeOpus5_5,
28952895 MaxTokens = 1024,
28962896 Messages = [new() { Role = Role.User, Content = "Hello!" }]
28972897 };
from line 2911
29112911 client := anthropic.NewClient()
29122912 
29132913 stream := client.Messages.NewStreaming(context.TODO(), anthropic.MessageNewParams{
2914 Model: anthropic.ModelClaudeOpus5,
2914 Model: anthropic.ModelClaudeOpus5_5,
29152915 MaxTokens: 1024,
29162916 Messages: []anthropic.MessageParam{
29172917 anthropic.NewUserMessage(anthropic.NewTextBlock("Hello!")),
from line 2938
29382938 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
29392939 
29402940 MessageCreateParams params = MessageCreateParams.builder()
2941 .model(Model.CLAUDE_OPUS_5)
2941 .model(Model.CLAUDE_OPUS_5_5)
29422942 .maxTokens(1024L)
29432943 .addUserMessage("Hello!")
29442944 .build();
from line 2961
29612961 $stream = $client->messages->createStream(
29622962 maxTokens: 1024,
29632963 messages: [['role' => 'user', 'content' => 'Hello!']],
2964 model: 'claude-opus-5',
2964 model: 'claude-opus-5-5',
29652965 );
29662966 
29672967 foreach ($stream as $event) {
from line 2975
29752975 client = Anthropic::Client.new
29762976 
29772977 stream = client.messages.stream(
2978 model: "claude-opus-5",
2978 model: "claude-opus-5-5",
29792979 max_tokens: 1024,
29802980 messages: [{ role: "user", content: "Hello!" }]
29812981 )
from line 3003
30033003 
30043004 while True:
30053005 response = client.messages.create(
3006 model="claude-opus-5", max_tokens=1024, messages=messages, tools=tools
3006 model="claude-opus-5-5", max_tokens=1024, messages=messages, tools=tools
30073007 )
30083008 
30093009 if response.stop_reason == "tool_use":
from line 3026
30263026 
30273027 while (true) {
30283028 const response = await client.messages.create({
3029 model: "claude-opus-5",
3029 model: "claude-opus-5-5",
30303030 max_tokens: 1024,
30313031 messages,
30323032 tools
from line 3057
30573057 {
30583058 var response = await client.Messages.Create(new MessageCreateParams
30593059 {
3060 Model = Model.ClaudeOpus5,
3060 Model = Model.ClaudeOpus5_5,
30613061 MaxTokens = 1024,
30623062 Messages = messages,
30633063 Tools = tools
from line 3093
30933093 
30943094 for {
30953095 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
3096 Model: anthropic.ModelClaudeOpus5,
3096 Model: anthropic.ModelClaudeOpus5_5,
30973097 MaxTokens: 1024,
30983098 Messages: messages,
30993099 Tools: tools,
from line 3130
31303130 
31313131 while (true) {
31323132 MessageCreateParams.Builder params = MessageCreateParams.builder()
3133 .model(Model.CLAUDE_OPUS_5)
3133 .model(Model.CLAUDE_OPUS_5_5)
31343134 .maxTokens(1024L)
31353135 .messages(messages);
31363136 tools.forEach(params::addTool);
from line 3162
31623162 $response = $client->messages->create(
31633163 maxTokens: 1024,
31643164 messages: $messages,
3165 model: 'claude-opus-5',
3165 model: 'claude-opus-5-5',
31663166 tools: $tools,
31673167 );
31683168 
from line 3185
31853185 
31863186 loop do
31873187 response = client.messages.create(
3188 model: "claude-opus-5",
3188 model: "claude-opus-5-5",
31893189 max_tokens: 1024,
31903190 messages: messages,
31913191 tools: tools
from line 3213
32133213 
32143214 for _ in range(max_attempts):
32153215 response = client.messages.create(
3216 model="claude-opus-5", messages=messages, max_tokens=4096
3216 model="claude-opus-5-5", messages=messages, max_tokens=4096
32173217 )
32183218 
32193219 full_response += next(
from line 3244
32443244 
32453245 for (let i = 0; i < maxAttempts; i++) {
32463246 const response = await client.messages.create({
3247 model: "claude-opus-5",
3247 model: "claude-opus-5-5",
32483248 max_tokens: 4096,
32493249 messages
32503250 });
from line 3280
32803280 {
32813281 var response = await client.Messages.Create(new MessageCreateParams
32823282 {
3283 Model = Model.ClaudeOpus5,
3283 Model = Model.ClaudeOpus5_5,
32843284 MaxTokens = 4096,
32853285 Messages = messages
32863286 });
from line 3319
33193319 
33203320 for range maxAttempts {
33213321 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
3322 Model: anthropic.ModelClaudeOpus5,
3322 Model: anthropic.ModelClaudeOpus5_5,
33233323 MaxTokens: 4096,
33243324 Messages: messages,
33253325 })
from line 3360
33603360 for (int i = 0; i < maxAttempts; i++) {
33613361 Message response = client.messages().create(
33623362 MessageCreateParams.builder()
3363 .model(Model.CLAUDE_OPUS_5)
3363 .model(Model.CLAUDE_OPUS_5_5)
33643364 .maxTokens(4096L)
33653365 .messages(messages)
33663366 .build()
from line 3397
33973397 $response = $client->messages->create(
33983398 maxTokens: 4096,
33993399 messages: $messages,
3400 model: 'claude-opus-5',
3400 model: 'claude-opus-5-5',
34013401 );
34023402 
34033403 $fullResponse .= array_find($response->content, static fn ($block): bool => $block->type === 'text')?->text ?? '';
from line 3425
34253425 
34263426 max_attempts.times do
34273427 response = client.messages.create(
3428 model: "claude-opus-5",
3428 model: "claude-opus-5-5",
34293429 max_tokens: 4096,
34303430 messages: messages
34313431 )
from line 3459
34593459 without needing to calculate input token count
34603460 """
34613461 response = client.beta.messages.create(
3462 model="claude-opus-5",
3462 model="claude-opus-5-5",
34633463 messages=[{"role": "user", "content": prompt}],
34643464 max_tokens=20000, # Python SDK requires streaming for max_tokens above ~21k
34653465 )
from line 3487
34873487 ```typescript TypeScript
34883488 async function getMaxPossibleTokens(client: Anthropic, prompt: string): Promise<string> {
34893489 const response = await client.beta.messages.create({
3490 model: "claude-opus-5",
3490 model: "claude-opus-5-5",
34913491 max_tokens: 20000,
34923492 messages: [{ role: "user", content: prompt }]
34933493 });
from line 3522
35223522 {
35233523 var response = await client.Beta.Messages.Create(new MessageCreateParams
35243524 {
3525 Model = Model.ClaudeOpus5,
3525 Model = Model.ClaudeOpus5_5,
35263526 MaxTokens = 20000,
35273527 Messages = [new() { Role = Role.User, Content = prompt }]
35283528 });
from line 3552
35523552 ```go Go
35533553 func getMaxPossibleTokens(client anthropic.Client, prompt string) (string, error) {
35543554 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
3555 Model: anthropic.ModelClaudeOpus5,
3555 Model: anthropic.ModelClaudeOpus5_5,
35563556 MaxTokens: 20000,
35573557 Messages: []anthropic.BetaMessageParam{
35583558 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock(prompt)),
from line 3593
35933593 static String getMaxPossibleTokens(AnthropicClient client, String prompt) {
35943594 BetaMessage response = client.beta().messages().create(
35953595 MessageCreateParams.builder()
3596 .model(Model.CLAUDE_OPUS_5)
3596 .model(Model.CLAUDE_OPUS_5_5)
35973597 .maxTokens(20000L)
35983598 .addUserMessage(prompt)
35993599 .build()
from line 3626
36263626 $response = $client->beta->messages->create(
36273627 maxTokens: 20000,
36283628 messages: [['role' => 'user', 'content' => $prompt]],
3629 model: 'claude-opus-5',
3629 model: 'claude-opus-5-5',
36303630 );
36313631 
36323632 $tokens = $response->usage->outputTokens;
from line 3646
36463646 ```ruby Ruby
36473647 def get_max_possible_tokens(client, prompt)
36483648 response = client.beta.messages.create(
3649 model: "claude-opus-5",
3649 model: "claude-opus-5-5",
36503650 max_tokens: 20000,
36513651 messages: [{ role: "user", content: prompt }]
36523652 )

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

from line 37
3737 
3838 client = anthropic.Anthropic()
3939 
40 MODEL = "claude-opus-5"
40 MODEL = "claude-opus-5-5"
4141 EFFORT = "xhigh"
4242 
4343 SYSTEM_PROMPT = "You are a helpful general-purpose agent. Answer the user's request directly."
from line 67
6767 
6868 const client = new Anthropic();
6969 
70 const MODEL = "claude-opus-5";
70 const MODEL = "claude-opus-5-5";
7171 const EFFORT = "xhigh";
7272 
7373 const SYSTEM_PROMPT =
from line 95
9595 
9696 AnthropicClient client = new();
9797 
98 const Model model = Model.ClaudeOpus5;
98 const Model model = Model.ClaudeOpus5_5;
9999 var effort = Effort.Xhigh;
100100 
101101 const string systemPrompt = "You are a helpful general-purpose agent. Answer the user's request directly.";
from line 141
141141 var client = anthropic.NewClient()
142142 
143143 const (
144 modelID = anthropic.ModelClaudeOpus5
144 modelID = anthropic.ModelClaudeOpus5_5
145145 effort = anthropic.OutputConfigEffortXhigh
146146 
147147 systemPrompt = "You are a helpful general-purpose agent. Answer the user's request directly."
from line 223
223223 
224224 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
225225 
226 static final Model MODEL = Model.CLAUDE_OPUS_5;
226 static final Model MODEL = Model.CLAUDE_OPUS_5_5;
227227 static final boolean DOC_TEST_MODE =
228228 !Objects.requireNonNullElse(System.getenv("DOC_TEST_MODE"), "").isEmpty();
229229 static final OutputConfig.Effort EFFORT = OutputConfig.Effort.XHIGH;
from line 251
251251 
252252 $client = new Client();
253253 
254 const MODEL = 'claude-opus-5';
254 const MODEL = 'claude-opus-5-5';
255255 define('DOC_TEST_MODE', (string) getenv('DOC_TEST_MODE') !== '');
256256 const EFFORT = 'xhigh';
257257 
from line 278
278278 
279279 CLIENT = Anthropic::Client.new
280280 
281 MODEL = "claude-opus-5"
281 MODEL = "claude-opus-5-5"
282282 EFFORT = :xhigh
283283 
284284 SYSTEM_PROMPT = "You are a helpful general-purpose agent. Answer the user's request directly."
from line 2867
28672867 -H "content-type: application/json" \
28682868 -d @- <<'EOF'
28692869 {
2870 "model": "claude-opus-5",
2870 "model": "claude-opus-5-5",
28712871 "max_tokens": 64000,
28722872 "system": "You are a helpful general-purpose agent. Answer the user's request directly.",
28732873 "output_config": {"effort": "xhigh"},
from line 2910
29102910 # subagents is shown in the SDK tabs; the Workflow description is condensed here,
29112911 # the SDK examples carry the full standing-consent text.
29122912 ant messages create <<'YAML'
2913 model: claude-opus-5
2913 model: claude-opus-5-5
29142914 max_tokens: 64000
29152915 system: You are a helpful general-purpose agent. Answer the user's request directly.
29162916 output_config: {effort: xhigh}

build-with-claude/mid-conversation-system-messages Changed · +1196 / -26 lines

### Define tools in a message (beta) ### Add an MCP server mid-conversation (beta)

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 15
1515<Note>
1616 Mid-conversation system messages are available on the Claude API, [Claude in Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock), and [Google Cloud](https://platform.claude.com/docs/en/build-with-claude/claude-on-vertex-ai).
1717 
18 This feature is available on Claude Fable 5.1, [Claude Mythos 5.1](https://anthropic.com/glasswing), Claude Fable 5, [Claude Mythos 5](https://anthropic.com/glasswing), Claude Opus 4.8, and Claude Opus 5. No beta header is required for mid-conversation system messages. This feature is not available on Claude Sonnet 5. Use the top-level `system` field there instead.
19 
20 [Mid-conversation tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#mid-conversation-tool-changes) are in beta and require the `mid-conversation-tool-changes-2026-07-01` beta header. They are available on the same models, on the Claude API, Amazon Bedrock, and Google Cloud.
18 This feature is available on Claude Fable 5.1, [Claude Mythos 5.1](https://anthropic.com/glasswing), Claude Fable 5, [Claude Mythos 5](https://anthropic.com/glasswing), Claude Opus 5.5, Claude Opus 4.8, and Claude Opus 5. No beta header is required for mid-conversation system messages. This feature is not available on Claude Sonnet 5. Use the top-level `system` field there instead.
19 
20 [Mid-conversation tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#mid-conversation-tool-changes) are in beta and require the `mid-conversation-tool-changes-2026-07-01` beta header. They are available on the same models, on the Claude API, Amazon Bedrock, and Google Cloud. [Defining a tool inside a `tool_addition` block](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#define-tools-in-a-message-beta) uses the `inline-tools-2026-09-15` beta header in place of that one, and is available on the Claude API. [Adding an MCP server that way](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#add-an-mcp-server-mid-conversation-beta) also needs the `mcp-client-2026-09-15` beta header.
2121 
2222 [Turn-scoped system messages](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#turn-scoped-system-messages) (`clear_at`) are in beta and require the `mid-conversation-system-clear-at-2026-08-21` beta header, on the same models and platforms as mid-conversation system messages.
2323</Note>
from line 26
2626 
2727The `tools` array sits even earlier in the hashed request prefix than the top-level `system` field, so editing it invalidates the [prompt cache](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for the entire conversation. Mid-conversation tool changes are the tools counterpart to mid-conversation system messages. Instead of fixing the tool list for the lifetime of the conversation, you change which tools are offered to the model between turns: declare the full tool set in `tools` up front, then use `tool_addition` and `tool_removal` blocks to offer a tool to the model, or withdraw it, from a specific point in the conversation onward. The `tools` array itself never changes, so the cached prefix stays intact.
2828 
29`tool_addition` and `tool_removal` are content blocks in the `content` array of a `role: "system"` message, and they can be mixed with `text` blocks in the same message. The message follows the placement rules for any mid-conversation system message, with one extra restriction after a paused turn (see [Limitations](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#limitations)), and the change applies from that point in the conversation onward. Each block's `tool` field references a tool rather than defining one: `{"type": "tool_reference", "name": "..."}` names a tool declared in the request's `tools` array, and [MCP connector](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector) tools can be referenced individually with `mcp_tool_reference` (`server_name` and `name`) or as a whole toolset with `mcp_toolset_reference` (`server_name`). Referencing a name that is not declared in `tools` returns a 400 error (on the Claude API, with `error.details.error_code` set to `tool_reference_unresolved`).
29`tool_addition` and `tool_removal` are content blocks in the `content` array of a `role: "system"` message, and they can be mixed with `text` blocks in the same message. The message follows the placement rules for any mid-conversation system message, with one extra restriction after a paused turn (see [Limitations](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#limitations)), and the change applies from that point in the conversation onward. Each block's `tool` field references a tool rather than defining one: `{"type": "tool_reference", "name": "..."}` names a tool declared in the request's `tools` array, and [MCP connector](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector) tools can be referenced individually with `mcp_tool_reference` (`server_name` and `name`) or as a whole toolset with `mcp_toolset_reference` (`server_name`). Referencing a name that is not declared in `tools` returns a 400 error (on the Claude API, with `error.details.error_code` set to `tool_reference_unresolved`). With the `inline-tools-2026-09-15` beta header, a `tool_addition` block can instead [carry the tool's full definition](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#define-tools-in-a-message-beta).
3030 
3131Every tool declared in `tools` is offered to the model from the start of the conversation unless it is declared with `defer_loading: true`, which keeps it withheld until a `tool_addition` block surfaces it. `tool_addition` also re-offers a tool that an earlier `tool_removal` withdrew.
3232 
from line 40
4040 -H "anthropic-version: 2023-06-01" \
4141 -H "anthropic-beta: mid-conversation-tool-changes-2026-07-01" \
4242 -d '{
43 "model": "claude-opus-5",
43 "model": "claude-opus-5-5",
4444 "max_tokens": 1024,
4545 "tools": [
4646 {
from line 76
7676 ```bash CLI
7777 ant beta:messages create --beta mid-conversation-tool-changes-2026-07-01 \
7878 --transform 'content.#(type=="text").text' --raw-output <<'YAML'
79 model: claude-opus-5
79 model: claude-opus-5-5
8080 max_tokens: 1024
8181 tools:
8282 - name: get_weather
from line 105
105105 client = anthropic.Anthropic()
106106 
107107 response = client.beta.messages.create(
108 model="claude-opus-5",
108 model="claude-opus-5-5",
109109 max_tokens=1024,
110110 betas=["mid-conversation-tool-changes-2026-07-01"],
111111 # The full tool set is declared up front and never changes, so the
from line 152
152152 const client = new Anthropic();
153153 
154154 const response = await client.beta.messages.create({
155 model: "claude-opus-5",
155 model: "claude-opus-5-5",
156156 max_tokens: 1024,
157157 betas: ["mid-conversation-tool-changes-2026-07-01"],
158158 // The full tool set is declared up front and never changes, so the
from line 205
205205 
206206 var response = await client.Beta.Messages.Create(new MessageCreateParams
207207 {
208 Model = Messages::Model.ClaudeOpus5,
208 Model = Messages::Model.ClaudeOpus5_5,
209209 MaxTokens = 1024,
210210 Betas = ["mid-conversation-tool-changes-2026-07-01"],
211211 // The full tool set is declared up front and never changes, so the
from line 259
259259 client := anthropic.NewClient()
260260 
261261 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
262 Model: anthropic.ModelClaudeOpus5,
262 Model: anthropic.ModelClaudeOpus5_5,
263263 MaxTokens: 1024,
264264 Betas: []anthropic.AnthropicBeta{"mid-conversation-tool-changes-2026-07-01"},
265265 // The full tool set is declared up front and never changes, so the
from line 331
331331 .build();
332332 
333333 MessageCreateParams params = MessageCreateParams.builder()
334 .model(Model.CLAUDE_OPUS_5)
334 .model(Model.CLAUDE_OPUS_5_5)
335335 .maxTokens(1024)
336336 .addBeta("mid-conversation-tool-changes-2026-07-01")
337337 .addTool(weatherTool)
from line 358
358358 $client = new Client();
359359 
360360 $response = $client->beta->messages->create(
361 model: 'claude-opus-5',
361 model: 'claude-opus-5-5',
362362 maxTokens: 1024,
363363 betas: ['mid-conversation-tool-changes-2026-07-01'],
364364 // The full tool set is declared up front and never changes, so the
from line 407
407407 client = Anthropic::Client.new
408408 
409409 response = client.beta.messages.create(
410 model: "claude-opus-5",
410 model: "claude-opus-5-5",
411411 max_tokens: 1024,
412412 betas: ["mid-conversation-tool-changes-2026-07-01"],
413413 # The full tool set is declared up front and never changes, so the
from line 448
448448 ```
449449</CodeGroup>
450450 
451### Define tools in a message (beta)
452 
453With the `inline-tools-2026-09-15` beta header, a `tool_addition` block can define a tool by value, carrying its full definition, instead of naming it by reference. This lets you introduce a tool that is unknown at the start of the conversation, or whose schema changes later, by appending a `role: "system"` message. The `tools` array and every earlier message stay exactly as sent, so the prompt cache still hits and only the appended message is processed as new input. The one exception, a `tools` array with no non-deferred tool, is covered in the rules below. The header also covers adding and removing tools by reference, so you don't need to send `mid-conversation-tool-changes-2026-07-01` as well.
454 
455Wrap the definition in a `tool` object of type `tool_definition`. The `definition` is a `tools` entry, such as a custom tool or an Anthropic-defined client or server tool, with its usual configuration, including `cache_control` and `defer_loading`. During the beta, some tool types (the computer use tool among them) can't be defined in a message yet and return a 400 error that says so; declare those in `tools` and add them by reference. For example, to define a custom tool mid-conversation:
456 
457```json
458{
459 "role": "system",
460 "content": [
461 {
462 "type": "tool_addition",
463 "tool": {
464 "type": "tool_definition",
465 "definition": {
466 "name": "db_query",
467 "description": "Run a read-only SQL query against the analytics database.",
468 "input_schema": {
469 "type": "object",
470 "properties": { "sql": { "type": "string" } },
471 "required": ["sql"]
472 }
473 }
474 }
475 }
476 ]
477}
478```
479 
480From that position onward, the model can call the tool the same way it calls a tool declared in `tools`. Sending an identical definition again changes nothing, so a client can safely resend it, for example on a retry.
481 
482The following request keeps `get_weather` in `tools` and defines `db_query` after the first user turn:
483 
484<CodeGroup>
485 ```bash cURL
486 curl https://api.anthropic.com/v1/messages \
487 -H "content-type: application/json" \
488 -H "x-api-key: $ANTHROPIC_API_KEY" \
489 -H "anthropic-version: 2023-06-01" \
490 -H "anthropic-beta: inline-tools-2026-09-15" \
491 -d '{
492 "model": "claude-opus-5-5",
493 "max_tokens": 1024,
494 "tools": [
495 {
496 "name": "get_weather",
497 "description": "Get the current weather for a location.",
498 "input_schema": {
499 "type": "object",
500 "properties": {
501 "location": {"type": "string", "description": "City name"}
502 },
503 "required": ["location"]
504 }
505 }
506 ],
507 "messages": [
508 {
509 "role": "user",
510 "content": "How many orders shipped yesterday?"
511 },
512 {
513 "role": "system",
514 "content": [
515 {
516 "type": "tool_addition",
517 "tool": {
518 "type": "tool_definition",
519 "definition": {
520 "name": "db_query",
521 "description": "Run a read-only SQL query against the analytics database.",
522 "input_schema": {
523 "type": "object",
524 "properties": {"sql": {"type": "string"}},
525 "required": ["sql"]
526 }
527 }
528 }
529 }
530 ]
531 }
532 ]
533 }'
534 ```
535 
536 <MultiFileExample language="cli" label="CLI">
537 ```bash CLI
538 ant beta:messages create --beta inline-tools-2026-09-15 < request.yaml
539 ```
540 
541 <File filename="request.yaml">
542 ```yaml
543 model: claude-opus-5-5
544 max_tokens: 1024
545 # Keep at least one non-deferred tool in `tools`, so a tool defined
546 # later doesn't change the start of the rendered prompt.
547 tools:
548 - name: get_weather
549 description: Get the current weather for a location.
550 input_schema:
551 type: object
552 properties:
553 location:
554 type: string
555 description: City name
556 required:
557 - location
558 messages:
559 - role: user
560 content: How many orders shipped yesterday?
561 # Define db_query by value from this point onward. `tools` and the
562 # earlier messages stay exactly as sent, so the cache still hits.
563 - role: system
564 content:
565 - type: tool_addition
566 tool:
567 type: tool_definition
568 definition:
569 name: db_query
570 description: Run a read-only SQL query against the analytics database.
571 input_schema:
572 type: object
573 properties:
574 sql:
575 type: string
576 required:
577 - sql
578 ```
579 </File>
580 </MultiFileExample>
581 
582 ```python Python
583 client = anthropic.Anthropic()
584 
585 response = client.beta.messages.create(
586 model="claude-opus-5-5",
587 max_tokens=1024,
588 betas=["inline-tools-2026-09-15"],
589 # Keep at least one non-deferred tool in `tools`, so a tool defined
590 # later doesn't change the start of the rendered prompt.
591 tools=[
592 {
593 "name": "get_weather",
594 "description": "Get the current weather for a location.",
595 "input_schema": {
596 "type": "object",
597 "properties": {
598 "location": {"type": "string", "description": "City name"},
599 },
600 "required": ["location"],
601 },
602 },
603 ],
604 messages=[
605 {"role": "user", "content": "How many orders shipped yesterday?"},
606 # Define db_query by value from this point onward. `tools` and the
607 # earlier messages stay exactly as sent, so the cache still hits.
608 {
609 "role": "system",
610 "content": [
611 {
612 "type": "tool_addition",
613 "tool": {
614 "type": "tool_definition",
615 "definition": {
616 "name": "db_query",
617 "description": "Run a read-only SQL query against the analytics database.",
618 "input_schema": {
619 "type": "object",
620 "properties": {"sql": {"type": "string"}},
621 "required": ["sql"],
622 },
623 },
624 },
625 },
626 ],
627 },
628 ],
629 )
630 
631 for block in response.content:
632 if block.type == "tool_use":
633 print(block.name, block.input)
634 ```
635 
636 ```typescript TypeScript
637 const client = new Anthropic();
638 
639 const response = await client.beta.messages.create({
640 model: "claude-opus-5-5",
641 max_tokens: 1024,
642 betas: ["inline-tools-2026-09-15"],
643 // Keep at least one non-deferred tool in `tools`, so a tool defined
644 // later doesn't change the start of the rendered prompt.
645 tools: [
646 {
647 name: "get_weather",
648 description: "Get the current weather for a location.",
649 input_schema: {
650 type: "object",
651 properties: {
652 location: { type: "string", description: "City name" }
653 },
654 required: ["location"]
655 }
656 }
657 ],
658 messages: [
659 { role: "user", content: "How many orders shipped yesterday?" },
660 // Define db_query by value from this point onward. `tools` and the
661 // earlier messages stay exactly as sent, so the cache still hits.
662 {
663 role: "system",
664 content: [
665 {
666 type: "tool_addition",
667 tool: {
668 type: "tool_definition",
669 definition: {
670 name: "db_query",
671 description: "Run a read-only SQL query against the analytics database.",
672 input_schema: {
673 type: "object",
674 properties: { sql: { type: "string" } },
675 required: ["sql"]
676 }
677 }
678 }
679 }
680 ]
681 }
682 ]
683 });
684 
685 for (const block of response.content) {
686 if (block.type === "tool_use") {
687 console.log(block.name, JSON.stringify(block.input));
688 }
689 }
690 ```
691 
692 ```csharp C#
693 using Anthropic.Models.Beta;
694 using Anthropic.Models.Beta.Messages;
695 using Messages = Anthropic.Models.Messages;
696 
697 AnthropicClient client = new();
698 
699 var response = await client.Beta.Messages.Create(new MessageCreateParams
700 {
701 Model = Messages::Model.ClaudeOpus5_5,
702 MaxTokens = 1024,
703 Betas = [AnthropicBeta.InlineTools2026_09_15],
704 // Keep at least one non-deferred tool in `Tools`, so a tool defined
705 // later doesn't change the start of the rendered prompt.
706 Tools =
707 [
708 new BetaTool
709 {
710 Name = "get_weather",
711 Description = "Get the current weather for a location.",
712 InputSchema = new InputSchema
713 {
714 Properties = new Dictionary<string, JsonElement>
715 {
716 ["location"] = JsonSerializer.SerializeToElement(new { type = "string", description = "City name" }),
717 },
718 Required = ["location"],
719 },
720 },
721 ],
722 Messages =
723 [
724 new() { Role = Role.User, Content = "How many orders shipped yesterday?" },
725 // Define db_query by value from this point onward. `Tools` and the
726 // earlier messages stay exactly as sent, so the cache still hits.
727 new()
728 {
729 Role = Role.System,
730 Content = new(
731 [
732 new BetaRequestToolAdditionBlock
733 {
734 Tool = new BetaToolChangeToolDefinitionParam
735 {
736 Definition = new BetaTool
737 {
738 Name = "db_query",
739 Description = "Run a read-only SQL query against the analytics database.",
740 InputSchema = new InputSchema
741 {
742 Properties = new Dictionary<string, JsonElement>
743 {
744 ["sql"] = JsonSerializer.SerializeToElement(new { type = "string" }),
745 },
746 Required = ["sql"],
747 },
748 },
749 },
750 },
751 ]),
752 },
753 ],
754 });
755 
756 foreach (var block in response.Content)
757 {
758 if (block.TryPickToolUse(out var toolUse))
759 {
760 Console.WriteLine($"{toolUse.Name} {JsonSerializer.Serialize(toolUse.Input)}");
761 }
762 }
763 ```
764 
765 ```go Go
766 client := anthropic.NewClient()
767 
768 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
769 Model: anthropic.ModelClaudeOpus5_5,
770 MaxTokens: 1024,
771 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaInlineTools2026_09_15},
772 // Keep at least one non-deferred tool in Tools, so a tool defined
773 // later doesn't change the start of the rendered prompt.
774 Tools: []anthropic.BetaToolUnionParam{
775 {OfTool: &anthropic.BetaToolParam{
776 Name: "get_weather",
777 Description: anthropic.String("Get the current weather for a location."),
778 InputSchema: anthropic.BetaToolInputSchemaParam{
779 Properties: map[string]any{
780 "location": map[string]any{
781 "type": "string",
782 "description": "City name",
783 },
784 },
785 Required: []string{"location"},
786 },
787 }},
788 },
789 Messages: []anthropic.BetaMessageParam{
790 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("How many orders shipped yesterday?")),
791 // Define db_query by value from this point onward. Tools and the
792 // earlier messages stay exactly as sent, so the cache still hits.
793 {
794 Role: anthropic.BetaMessageParamRoleSystem,
795 Content: []anthropic.BetaContentBlockParamUnion{
796 anthropic.NewBetaToolAdditionBlock(anthropic.BetaToolChangeToolDefinitionParam{
797 Definition: anthropic.BetaToolUnionParam{OfTool: &anthropic.BetaToolParam{
798 Name: "db_query",
799 Description: anthropic.String("Run a read-only SQL query against the analytics database."),
800 InputSchema: anthropic.BetaToolInputSchemaParam{
801 Properties: map[string]any{
802 "sql": map[string]any{"type": "string"},
803 },
804 Required: []string{"sql"},
805 },
806 }},
807 }),
808 },
809 },
810 },
811 })
812 if err != nil {
813 log.Fatal(err)
814 }
815 
816 for _, block := range response.Content {
817 if toolUse, ok := block.AsAny().(anthropic.BetaToolUseBlock); ok {
818 fmt.Println(toolUse.Name, toolUse.Input)
819 }
820 }
821 ```
822 
823 ```java Java
824 import com.anthropic.models.beta.AnthropicBeta;
825 import com.anthropic.models.beta.messages.BetaContentBlockParam;
826 import com.anthropic.models.beta.messages.BetaMessage;
827 import com.anthropic.models.beta.messages.BetaRequestToolAdditionBlock;
828 import com.anthropic.models.beta.messages.BetaTool;
829 import com.anthropic.models.beta.messages.MessageCreateParams;
830 // ...
831 
832 void main() {
833 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
834 
835 BetaTool weatherTool = BetaTool.builder()
836 .name("get_weather")
837 .description("Get the current weather for a location.")
838 .inputSchema(BetaTool.InputSchema.builder()
839 .properties(BetaTool.InputSchema.Properties.builder()
840 .putAdditionalProperty("location", JsonValue.from(Map.of(
841 "type", "string",
842 "description", "City name")))
843 .build())
844 .addRequired("location")
845 .build())
846 .build();
847 
848 BetaTool dbQueryTool = BetaTool.builder()
849 .name("db_query")
850 .description("Run a read-only SQL query against the analytics database.")
851 .inputSchema(BetaTool.InputSchema.builder()
852 .properties(BetaTool.InputSchema.Properties.builder()
853 .putAdditionalProperty("sql", JsonValue.from(Map.of("type", "string")))
854 .build())
855 .addRequired("sql")
856 .build())
857 .build();
858 
859 MessageCreateParams params = MessageCreateParams.builder()
860 .model(Model.CLAUDE_OPUS_5_5)
861 .maxTokens(1024)
862 .addBeta(AnthropicBeta.INLINE_TOOLS_2026_09_15)
863 // Keep at least one non-deferred tool in `tools`, so a tool defined
864 // later doesn't change the start of the rendered prompt.
865 .addTool(weatherTool)
866 .addUserMessage("How many orders shipped yesterday?")
867 // Define db_query by value from this point onward. `tools` and the
868 // earlier messages stay exactly as sent, so the cache still hits.
869 .addSystemMessageOfBetaContentBlockParams(List.of(
870 BetaContentBlockParam.ofToolAddition(BetaRequestToolAdditionBlock.builder()
871 .definitionTool(dbQueryTool)
872 .build())))
873 .build();
874 
875 BetaMessage response = client.beta().messages().create(params);
876 response.content().stream()
877 .flatMap(block -> block.toolUse().stream())
878 .forEach(toolUse -> IO.println(toolUse.name() + " " + toolUse._input()));
879 }
880 ```
881 
882 ```php PHP
883 use Anthropic\Beta\AnthropicBeta;
884 use Anthropic\Beta\Messages\BetaToolUseBlock;
885 // ...
886 
887 $client = new Client();
888 
889 $response = $client->beta->messages->create(
890 model: Model::CLAUDE_OPUS_5_5,
891 maxTokens: 1024,
892 betas: [AnthropicBeta::INLINE_TOOLS_2026_09_15],
893 // Keep at least one non-deferred tool in `tools`, so a tool defined
894 // later doesn't change the start of the rendered prompt.
895 tools: [
896 [
897 'name' => 'get_weather',
898 'description' => 'Get the current weather for a location.',
899 'input_schema' => [
900 'type' => 'object',
901 'properties' => [
902 'location' => [
903 'type' => 'string',
904 'description' => 'City name',
905 ],
906 ],
907 'required' => ['location'],
908 ],
909 ],
910 ],
911 messages: [
912 ['role' => 'user', 'content' => 'How many orders shipped yesterday?'],
913 // Define db_query by value from this point onward. `tools` and the
914 // earlier messages stay exactly as sent, so the cache still hits.
915 [
916 'role' => 'system',
917 'content' => [
918 [
919 'type' => 'tool_addition',
920 'tool' => [
921 'type' => 'tool_definition',
922 'definition' => [
923 'name' => 'db_query',
924 'description' => 'Run a read-only SQL query against the analytics database.',
925 'input_schema' => [
926 'type' => 'object',
927 'properties' => ['sql' => ['type' => 'string']],
928 'required' => ['sql'],
929 ],
930 ],
931 ],
932 ],
933 ],
934 ],
935 ],
936 );
937 
938 foreach ($response->content as $block) {
939 if ($block instanceof BetaToolUseBlock) {
940 echo $block->name, ' ', json_encode($block->input), PHP_EOL;
941 }
942 }
943 ```
944 
945 ```ruby Ruby
946 client = Anthropic::Client.new
947 
948 response = client.beta.messages.create(
949 model: Anthropic::Model::CLAUDE_OPUS_5_5,
950 max_tokens: 1024,
951 betas: [Anthropic::AnthropicBeta::INLINE_TOOLS_2026_09_15],
952 # Keep at least one non-deferred tool in `tools`, so a tool defined
953 # later doesn't change the start of the rendered prompt.
954 tools: [
955 {
956 name: "get_weather",
957 description: "Get the current weather for a location.",
958 input_schema: {
959 type: "object",
960 properties: {
961 location: { type: "string", description: "City name" }
962 },
963 required: ["location"]
964 }
965 }
966 ],
967 messages: [
968 { role: "user", content: "How many orders shipped yesterday?" },
969 # Define db_query by value from this point onward. `tools` and the
970 # earlier messages stay exactly as sent, so the cache still hits.
971 {
972 role: "system",
973 content: [
974 {
975 type: "tool_addition",
976 tool: {
977 type: "tool_definition",
978 definition: {
979 name: "db_query",
980 description: "Run a read-only SQL query against the analytics database.",
981 input_schema: {
982 type: "object",
983 properties: { sql: { type: "string" } },
984 required: ["sql"]
985 }
986 }
987 }
988 }
989 ]
990 }
991 ]
992 )
993 
994 response.content.each do |block|
995 puts "#{block.name} #{block.input}" if block.is_a?(Anthropic::Beta::BetaToolUseBlock)
996 end
997 ```
998</CodeGroup>
999 
1000The response's `content` includes a `tool_use` block for the new tool, for example:
1001 
1002```json
1003{
1004 "type": "tool_use",
1005 "id": "toolu_01A09q90qw90lq917835lq9",
1006 "name": "db_query",
1007 "input": {
1008 "sql": "SELECT COUNT(*) FROM orders WHERE shipped_at::date = CURRENT_DATE - 1"
1009 }
1010}
1011```
1012 
1013To change a tool's schema, or to move a server tool to a newer version, send a different definition under the same name. The new definition replaces the earlier one from that position onward. A definition that reuses the name of a different type of tool returns a 400 error with `error.details.error_code` set to `tool_name_conflict`. A newer version of the same tool doesn't count as a different type. `tool_removal` still takes a reference, and a removed tool can be defined or re-offered again later.
1014 
1015A few rules follow from where the definition renders:
1016 
1017* **Declare what you know up front.** A tool you know about at the first request belongs in `tools`, with `defer_loading: true` and a later `tool_addition` reference if the model shouldn't see it yet. Define by value only what is unknown at the first request or changes later.
1018* **Keep at least one non-deferred tool in `tools`.** A conversation whose `tools` array has no non-deferred tool is accepted, but the first tool it defines by value changes the start of the rendered prompt, which costs one full cache miss on that request. A [tool search tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool) counts as non-deferred.
1019* **Dated tool types keep their own beta headers.** If a server tool you define by value requires its own beta header, send that header on every later request in the conversation.
1020* **`cache_control` goes on the block or in the definition, not both,** and counts toward the request's breakpoint limit. A deferred definition can't carry `cache_control`.
1021 
1022A request returns a 400 error with `error.details.error_code` set to `available_tools_limit_exceeded` when any of these limits is exceeded:
1023 
1024* More than 10,000 deferred tools are available after any message.
1025* More than 10,000 tools defined after the first user message are available after any message.
1026* The tool definitions sent after the first user message that are still available after any message total more than 4 MB (4,194,304 bytes).
1027* The rendered tool text is larger than 4 MB (4,194,304 bytes).
1028 
1029### Add an MCP server mid-conversation (beta)
1030 
1031To add an [MCP connector](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector) server partway through a conversation, send the `mcp-client-2026-09-15` beta header along with `inline-tools-2026-09-15`. The `definition` in a `tool_addition` block can then be an `mcp_toolset`, so the server's tools become available without editing `tools`. List the server's connection details in `mcp_servers` as usual, then append the toolset where the server became available:
1032 
1033```json
1034{
1035 "role": "system",
1036 "content": [
1037 {
1038 "type": "tool_addition",
1039 "tool": {
1040 "type": "tool_definition",
1041 "definition": { "type": "mcp_toolset", "mcp_server_name": "calendar" }
1042 }
1043 }
1044 ]
1045}
1046```
1047 
1048The `mcp_toolset` object is the same one you would put in `tools`, including `default_config` and `configs`. A `tool_addition` block never holds a server URL or token. Those stay in `mcp_servers`.
1049 
1050The following request keeps `get_weather` in `tools`, lists the calendar server in `mcp_servers`, and adds the server's toolset after the first user turn:
1051 
1052<CodeGroup>
1053 ```bash cURL
1054 curl https://api.anthropic.com/v1/messages \
1055 -H "content-type: application/json" \
1056 -H "x-api-key: $ANTHROPIC_API_KEY" \
1057 -H "anthropic-version: 2023-06-01" \
1058 -H "anthropic-beta: inline-tools-2026-09-15,mcp-client-2026-09-15" \
1059 -d '{
1060 "model": "claude-opus-5-5",
1061 "max_tokens": 1024,
1062 "mcp_servers": [
1063 {
1064 "type": "url",
1065 "url": "https://mcp.example.com/calendar",
1066 "name": "calendar",
1067 "authorization_token": "YOUR_TOKEN"
1068 }
1069 ],
1070 "tools": [
1071 {
1072 "name": "get_weather",
1073 "description": "Get the current weather for a location.",
1074 "input_schema": {
1075 "type": "object",
1076 "properties": {
1077 "location": {"type": "string", "description": "City name"}
1078 },
1079 "required": ["location"]
1080 }
1081 }
1082 ],
1083 "messages": [
1084 {
1085 "role": "user",
1086 "content": "What'\''s on my calendar tomorrow?"
1087 },
1088 {
1089 "role": "system",
1090 "content": [
1091 {
1092 "type": "tool_addition",
1093 "tool": {
1094 "type": "tool_definition",
1095 "definition": {
1096 "type": "mcp_toolset",
1097 "mcp_server_name": "calendar"
1098 }
1099 }
1100 }
1101 ]
1102 }
1103 ]
1104 }'
1105 ```
1106 
1107 ```bash CLI
1108 ant beta:messages create \
1109 --beta inline-tools-2026-09-15,mcp-client-2026-09-15 <<'YAML'
1110 model: claude-opus-5-5
1111 max_tokens: 1024
1112 mcp_servers:
1113 - type: url
1114 url: https://mcp.example.com/calendar
1115 name: calendar
1116 authorization_token: YOUR_TOKEN
1117 tools:
1118 - name: get_weather
1119 description: Get the current weather for a location.
1120 input_schema:
1121 type: object
1122 properties:
1123 location:
1124 type: string
1125 description: City name
1126 required:
1127 - location
1128 messages:
1129 - role: user
1130 content: What's on my calendar tomorrow?
1131 # Make the calendar server's tools available from this point onward.
1132 # The block names the server; it never holds a URL or token.
1133 - role: system
1134 content:
1135 - type: tool_addition
1136 tool:
1137 type: tool_definition
1138 definition:
1139 type: mcp_toolset
1140 mcp_server_name: calendar
1141 YAML
1142 ```
1143 
1144 ```python Python
1145 client = anthropic.Anthropic()
1146 
1147 response = client.beta.messages.create(
1148 model="claude-opus-5-5",
1149 max_tokens=1024,
1150 betas=["inline-tools-2026-09-15", "mcp-client-2026-09-15"],
1151 mcp_servers=[
1152 {
1153 "type": "url",
1154 "url": "https://mcp.example.com/calendar",
1155 "name": "calendar",
1156 "authorization_token": "YOUR_TOKEN",
1157 },
1158 ],
1159 tools=[
1160 {
1161 "name": "get_weather",
1162 "description": "Get the current weather for a location.",
1163 "input_schema": {
1164 "type": "object",
1165 "properties": {
1166 "location": {"type": "string", "description": "City name"},
1167 },
1168 "required": ["location"],
1169 },
1170 },
1171 ],
1172 messages=[
1173 {"role": "user", "content": "What's on my calendar tomorrow?"},
1174 # Make the calendar server's tools available from this point onward.
1175 # The block names the server; it never holds a URL or token.
1176 {
1177 "role": "system",
1178 "content": [
1179 {
1180 "type": "tool_addition",
1181 "tool": {
1182 "type": "tool_definition",
1183 "definition": {
1184 "type": "mcp_toolset",
1185 "mcp_server_name": "calendar",
1186 },
1187 },
1188 },
1189 ],
1190 },
1191 ],
1192 )
1193 
1194 # The response starts with an mcp_tool_listing block for the calendar server,
1195 # so check each block's type instead of reading content[0].
1196 for block in response.content:
1197 match block.type:
1198 case "mcp_tool_listing":
1199 print(block.mcp_server_name, [tool.name for tool in block.tools])
1200 case "text":
1201 print(block.text)
1202 ```
1203 
1204 ```typescript TypeScript
1205 const client = new Anthropic();
1206 
1207 const response = await client.beta.messages.create({
1208 model: "claude-opus-5-5",
1209 max_tokens: 1024,
1210 betas: ["inline-tools-2026-09-15", "mcp-client-2026-09-15"],
1211 mcp_servers: [
1212 {
1213 type: "url",
1214 url: "https://mcp.example.com/calendar",
1215 name: "calendar",
1216 authorization_token: "YOUR_TOKEN"
1217 }
1218 ],
1219 tools: [
1220 {
1221 name: "get_weather",
1222 description: "Get the current weather for a location.",
1223 input_schema: {
1224 type: "object",
1225 properties: {
1226 location: { type: "string", description: "City name" }
1227 },
1228 required: ["location"]
1229 }
1230 }
1231 ],
1232 messages: [
1233 { role: "user", content: "What's on my calendar tomorrow?" },
1234 // Make the calendar server's tools available from this point onward.
1235 // The block names the server; it never holds a URL or token.
1236 {
1237 role: "system",
1238 content: [
1239 {
1240 type: "tool_addition",
1241 tool: {
1242 type: "tool_definition",
1243 definition: { type: "mcp_toolset", mcp_server_name: "calendar" }
1244 }
1245 }
1246 ]
1247 }
1248 ]
1249 });
1250 
1251 // The response starts with an mcp_tool_listing block for the calendar server,
1252 // so check each block's type instead of reading content[0].
1253 for (const block of response.content) {
1254 switch (block.type) {
1255 case "mcp_tool_listing":
1256 console.log(
1257 block.mcp_server_name,
1258 block.tools.map((tool) => tool.name)
1259 );
1260 break;
1261 case "text":
1262 console.log(block.text);
1263 break;
1264 }
1265 }
1266 ```
1267 
1268 ```csharp C#
1269 using Anthropic.Models.Beta;
1270 using Anthropic.Models.Beta.Messages;
1271 using Messages = Anthropic.Models.Messages;
1272 
1273 AnthropicClient client = new();
1274 
1275 var response = await client.Beta.Messages.Create(new MessageCreateParams
1276 {
1277 Model = Messages::Model.ClaudeOpus5_5,
1278 MaxTokens = 1024,
1279 Betas = [AnthropicBeta.InlineTools2026_09_15, AnthropicBeta.McpClient2026_09_15],
1280 McpServers =
1281 [
1282 new BetaRequestMcpServerUrlDefinition
1283 {
1284 Url = "https://mcp.example.com/calendar",
1285 Name = "calendar",
1286 AuthorizationToken = "YOUR_TOKEN",
1287 },
1288 ],
1289 Tools =
1290 [
1291 new BetaTool
1292 {
1293 Name = "get_weather",
1294 Description = "Get the current weather for a location.",
1295 InputSchema = new InputSchema
1296 {
1297 Properties = new Dictionary<string, JsonElement>
1298 {
1299 ["location"] = JsonSerializer.SerializeToElement(new { type = "string", description = "City name" }),
1300 },
1301 Required = ["location"],
1302 },
1303 },
1304 ],
1305 Messages =
1306 [
1307 new() { Role = Role.User, Content = "What's on my calendar tomorrow?" },
1308 // Make the calendar server's tools available from this point onward.
1309 // The block names the server; it never holds a URL or token.
1310 new()
1311 {
1312 Role = Role.System,
1313 Content = new(
1314 [
1315 new BetaRequestToolAdditionBlock
1316 {
1317 Tool = new BetaToolChangeToolDefinitionParam
1318 {
1319 Definition = new BetaMcpToolset("calendar"),
1320 },
1321 },
1322 ]),
1323 },
1324 ],
1325 });
1326 
1327 // The response starts with an mcp_tool_listing block for the calendar server,
1328 // so check each block's type instead of reading Content[0].
1329 foreach (var block in response.Content)
1330 {
1331 if (block.TryPickMcpToolListing(out var listing))
1332 {
1333 Console.WriteLine($"{listing.McpServerName} {JsonSerializer.Serialize(listing.Tools.Select(tool => tool.Name))}");
1334 }
1335 else if (block.TryPickText(out var text))
1336 {
1337 Console.WriteLine(text.Text);
1338 }
1339 }
1340 ```
1341 
1342 ```go Go
1343 client := anthropic.NewClient()
1344 
1345 response, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
1346 Model: anthropic.ModelClaudeOpus5_5,
1347 MaxTokens: 1024,
1348 Betas: []anthropic.AnthropicBeta{
1349 anthropic.AnthropicBetaInlineTools2026_09_15,
1350 anthropic.AnthropicBetaMCPClient2026_09_15,
1351 },
1352 MCPServers: []anthropic.BetaRequestMCPServerURLDefinitionParam{
1353 {
1354 URL: "https://mcp.example.com/calendar",
1355 Name: "calendar",
1356 AuthorizationToken: anthropic.String("YOUR_TOKEN"),
1357 },
1358 },
1359 Tools: []anthropic.BetaToolUnionParam{
1360 {OfTool: &anthropic.BetaToolParam{
1361 Name: "get_weather",
1362 Description: anthropic.String("Get the current weather for a location."),
1363 InputSchema: anthropic.BetaToolInputSchemaParam{
1364 Properties: map[string]any{
1365 "location": map[string]any{
1366 "type": "string",
1367 "description": "City name",
1368 },
1369 },
1370 Required: []string{"location"},
1371 },
1372 }},
1373 },
1374 Messages: []anthropic.BetaMessageParam{
1375 anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("What's on my calendar tomorrow?")),
1376 // Make the calendar server's tools available from this point onward.
1377 // The block names the server; it never holds a URL or token.
1378 {
1379 Role: anthropic.BetaMessageParamRoleSystem,
1380 Content: []anthropic.BetaContentBlockParamUnion{
1381 anthropic.NewBetaToolAdditionBlock(anthropic.BetaToolChangeToolDefinitionParam{
1382 Definition: anthropic.BetaToolUnionParam{OfMCPToolset: &anthropic.BetaMCPToolsetParam{
1383 MCPServerName: "calendar",
1384 }},
1385 }),
1386 },
1387 },
1388 },
1389 })
1390 if err != nil {
1391 log.Fatal(err)
1392 }
1393 
1394 // The response starts with an mcp_tool_listing block for the calendar server,
1395 // so check each block's type instead of reading Content[0].
1396 for _, block := range response.Content {
1397 switch variant := block.AsAny().(type) {
1398 case anthropic.BetaMCPToolListingBlock:
1399 var toolNames []string
1400 for _, tool := range variant.Tools {
1401 toolNames = append(toolNames, tool.Name)
1402 }
1403 fmt.Println(variant.MCPServerName, toolNames)
1404 case anthropic.BetaTextBlock:
1405 fmt.Println(variant.Text)
1406 }
1407 }
1408 ```
1409 
1410 ```java Java
1411 import com.anthropic.models.beta.AnthropicBeta;
1412 import com.anthropic.models.beta.messages.BetaContentBlockParam;
1413 import com.anthropic.models.beta.messages.BetaMcpTool;
1414 import com.anthropic.models.beta.messages.BetaMcpToolset;
1415 import com.anthropic.models.beta.messages.BetaMessage;
1416 import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition;
1417 import com.anthropic.models.beta.messages.BetaRequestToolAdditionBlock;
1418 import com.anthropic.models.beta.messages.BetaTool;
1419 import com.anthropic.models.beta.messages.MessageCreateParams;
1420 // ...
1421 
1422 void main() {
1423 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
1424 
1425 BetaTool weatherTool = BetaTool.builder()
1426 .name("get_weather")
1427 .description("Get the current weather for a location.")
1428 .inputSchema(BetaTool.InputSchema.builder()
1429 .properties(BetaTool.InputSchema.Properties.builder()
1430 .putAdditionalProperty("location", JsonValue.from(Map.of(
1431 "type", "string",
1432 "description", "City name")))
1433 .build())
1434 .addRequired("location")
1435 .build())
1436 .build();
1437 
1438 MessageCreateParams params = MessageCreateParams.builder()
1439 .model(Model.CLAUDE_OPUS_5_5)
1440 .maxTokens(1024)
1441 .addBeta(AnthropicBeta.INLINE_TOOLS_2026_09_15)
1442 .addBeta(AnthropicBeta.MCP_CLIENT_2026_09_15)
1443 .addMcpServer(BetaRequestMcpServerUrlDefinition.builder()
1444 .url("https://mcp.example.com/calendar")
1445 .name("calendar")
1446 .authorizationToken("YOUR_TOKEN")
1447 .build())
1448 .addTool(weatherTool)
1449 .addUserMessage("What's on my calendar tomorrow?")
1450 // Make the calendar server's tools available from this point onward.
1451 // The block names the server; it never holds a URL or token.
1452 .addSystemMessageOfBetaContentBlockParams(List.of(
1453 BetaContentBlockParam.ofToolAddition(BetaRequestToolAdditionBlock.builder()
1454 .definitionTool(BetaMcpToolset.builder()
1455 .mcpServerName("calendar")
1456 .build())
1457 .build())))
1458 .build();
1459 
1460 BetaMessage response = client.beta().messages().create(params);
1461 
1462 // The response starts with an mcp_tool_listing block for the calendar server,
1463 // so check each block's type instead of reading the first block.
1464 for (var block : response.content()) {
1465 switch (block.type().value()) {
1466 case MCP_TOOL_LISTING -> {
1467 var listing = block.asMcpToolListing();
1468 var toolNames = listing.tools().stream().map(BetaMcpTool::name).toList();
1469 IO.println(listing.mcpServerName() + " " + toolNames);
1470 }
1471 case TEXT -> IO.println(block.asText().text());
1472 }
1473 }
1474 }
1475 ```
1476 
1477 ```php PHP
1478 use Anthropic\Beta\AnthropicBeta;
1479 use Anthropic\Beta\Messages\BetaMCPTool;
1480 use Anthropic\Beta\Messages\BetaMCPToolListingBlock;
1481 use Anthropic\Beta\Messages\BetaTextBlock;
1482 // ...
1483 
1484 $client = new Client();
1485 
1486 $response = $client->beta->messages->create(
1487 model: Model::CLAUDE_OPUS_5_5,
1488 maxTokens: 1024,
1489 betas: [
1490 AnthropicBeta::INLINE_TOOLS_2026_09_15,
1491 AnthropicBeta::MCP_CLIENT_2026_09_15,
1492 ],
1493 mcpServers: [
1494 [
1495 'type' => 'url',
1496 'url' => 'https://mcp.example.com/calendar',
1497 'name' => 'calendar',
1498 'authorization_token' => 'YOUR_TOKEN',
1499 ],
1500 ],
1501 tools: [
1502 [
1503 'name' => 'get_weather',
1504 'description' => 'Get the current weather for a location.',
1505 'input_schema' => [
1506 'type' => 'object',
1507 'properties' => [
1508 'location' => [
1509 'type' => 'string',
1510 'description' => 'City name',
1511 ],
1512 ],
1513 'required' => ['location'],
1514 ],
1515 ],
1516 ],
1517 messages: [
1518 ['role' => 'user', 'content' => "What's on my calendar tomorrow?"],
1519 // Make the calendar server's tools available from this point onward.
1520 // The block names the server; it never holds a URL or token.
1521 [
1522 'role' => 'system',
1523 'content' => [
1524 [
1525 'type' => 'tool_addition',
1526 'tool' => [
1527 'type' => 'tool_definition',
1528 'definition' => [
1529 'type' => 'mcp_toolset',
1530 'mcp_server_name' => 'calendar',
1531 ],
1532 ],
1533 ],
1534 ],
1535 ],
1536 ],
1537 );
1538 
1539 // The response starts with an mcp_tool_listing block for the calendar server,
1540 // so check each block's type instead of reading content[0].
1541 foreach ($response->content as $block) {
1542 switch (true) {
1543 case $block instanceof BetaMCPToolListingBlock:
1544 $toolNames = array_map(fn (BetaMCPTool $tool) => $tool->name, $block->tools);
1545 echo $block->mcpServerName, ' ', json_encode($toolNames), PHP_EOL;
1546 break;
1547 case $block instanceof BetaTextBlock:
1548 echo $block->text, PHP_EOL;
1549 break;
1550 }
1551 }
1552 ```
1553 
1554 ```ruby Ruby
1555 client = Anthropic::Client.new
1556 
1557 response = client.beta.messages.create(
1558 model: Anthropic::Model::CLAUDE_OPUS_5_5,
1559 max_tokens: 1024,
1560 betas: [
1561 Anthropic::AnthropicBeta::INLINE_TOOLS_2026_09_15,
1562 Anthropic::AnthropicBeta::MCP_CLIENT_2026_09_15
1563 ],
1564 mcp_servers: [
1565 {
1566 type: "url",
1567 url: "https://mcp.example.com/calendar",
1568 name: "calendar",
1569 authorization_token: "YOUR_TOKEN"
1570 }
1571 ],
1572 tools: [
1573 {
1574 name: "get_weather",
1575 description: "Get the current weather for a location.",
1576 input_schema: {
1577 type: "object",
1578 properties: {
1579 location: { type: "string", description: "City name" }
1580 },
1581 required: ["location"]
1582 }
1583 }
1584 ],
1585 messages: [
1586 { role: "user", content: "What's on my calendar tomorrow?" },
1587 # Make the calendar server's tools available from this point onward.
1588 # The block names the server; it never holds a URL or token.
1589 {
1590 role: "system",
1591 content: [
1592 {
1593 type: "tool_addition",
1594 tool: {
1595 type: "tool_definition",
1596 definition: { type: "mcp_toolset", mcp_server_name: "calendar" }
1597 }
1598 }
1599 ]
1600 }
1601 ]
1602 )
1603 
1604 # The response starts with an mcp_tool_listing block for the calendar server,
1605 # so check each block's type instead of reading content[0].
1606 response.content.each do |block|
1607 case block
1608 when Anthropic::Beta::BetaMCPToolListingBlock
1609 puts "#{block.mcp_server_name} #{block.tools.map(&:name)}"
1610 when Anthropic::Beta::BetaTextBlock
1611 puts block.text
1612 end
1613 end
1614 ```
1615</CodeGroup>
1616 
1617With `mcp-client-2026-09-15`, a response for which the API fetched a server's tool list starts with an `mcp_tool_listing` block, one for each server it fetched. If your code reads `content[0]`, skip these blocks. Send the assistant message back unchanged, this block included, and keep sending `mcp-client-2026-09-15` on every request that carries it. Later requests then use the recorded list instead of asking the server again. To pin a toolset yourself, copy that list into the `mcp_toolset`'s `tools` field, as described in [Pin an MCP server's tool list](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector#pin-mcp-tool-list).
1618 
1619`mcp-client-2026-09-15` includes everything `mcp-client-2025-11-20` does, so you don't need to send both. These features are available on the Claude API. Requests that use the MCP connector keep its [data retention](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector#data-retention) terms.
1620 
4511621## When to use a mid-conversation system message
4521622 
4531623[Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) hashes the request prefix in order: `tools`, then `system`, then `messages`. A cache hit requires the prefix to match a recent request exactly, byte for byte, up to the cache breakpoint.
from line 1643
4731643 
4741644You can still set the top-level `system` field for instructions that should apply to the entire conversation. Reserve mid-conversation system messages for instructions that only become relevant later, or that you want to add without invalidating the cached prefix.
4751645 
476A `role: "system"` message can also carry `output_config.effort` to change the [effort](https://platform.claude.com/docs/en/build-with-claude/effort) level from the next `user` turn on. This is in beta on Claude Fable 5.1, Claude Mythos 5.1, and Claude Opus 5 on the Claude API and Google Cloud, and requires the `mid-conversation-output-config-2026-07-01` beta header. See [Per-message effort](https://platform.claude.com/docs/en/build-with-claude/effort#change-effort-mid-conversation-beta).
1646A `role: "system"` message can also carry `output_config.effort` to change the [effort](https://platform.claude.com/docs/en/build-with-claude/effort) level from the next `user` turn on. This is in beta on Claude Fable 5.1, Claude Mythos 5.1, Claude Opus 5.5, and Claude Opus 5 on the Claude API and Google Cloud, and requires the `mid-conversation-output-config-2026-07-01` beta header. See [Per-message effort](https://platform.claude.com/docs/en/build-with-claude/effort#change-effort-mid-conversation-beta).
4771647 
4781648<CodeGroup>
4791649 ```bash cURL
from line 1652
4821652 -H "x-api-key: $ANTHROPIC_API_KEY" \
4831653 -H "anthropic-version: 2023-06-01" \
4841654 -d '{
485 "model": "claude-opus-5",
1655 "model": "claude-opus-5-5",
4861656 "max_tokens": 1024,
4871657 "cache_control": {"type": "ephemeral"},
4881658 "system": "You are a code review assistant. Be concise.",
from line 1679
5091679 
5101680 ```bash CLI
5111681 ant messages create --transform 'content.#(type=="text").text' --raw-output <<'YAML'
512 model: claude-opus-5
1682 model: claude-opus-5-5
5131683 max_tokens: 1024
5141684 cache_control:
5151685 type: ephemeral
from line 1702
5321702 client = anthropic.Anthropic()
5331703 
5341704 response = client.messages.create(
535 model="claude-opus-5",
1705 model="claude-opus-5-5",
5361706 max_tokens=1024,
5371707 # Automatic prompt caching: each request caches the conversation so far,
5381708 # and the next request reads the unchanged prefix from cache.
from line 1741
5711741 const client = new Anthropic();
5721742 
5731743 const response = await client.messages.create({
574 model: "claude-opus-5",
1744 model: "claude-opus-5-5",
5751745 max_tokens: 1024,
5761746 // Automatic prompt caching: each request caches the conversation so far,
5771747 // and the next request reads the unchanged prefix from cache.
from line 1783
6131783 
6141784 var parameters = new MessageCreateParams
6151785 {
616 Model = Model.ClaudeOpus5,
1786 Model = Model.ClaudeOpus5_5,
6171787 MaxTokens = 1024,
6181788 // Automatic prompt caching: each request caches the conversation so far,
6191789 // and the next request reads the unchanged prefix from cache.
from line 1826
6561826 client := anthropic.NewClient()
6571827 
6581828 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
659 Model: anthropic.ModelClaudeOpus5,
1829 Model: anthropic.ModelClaudeOpus5_5,
6601830 MaxTokens: 1024,
6611831 // Automatic prompt caching: each request caches the conversation so far,
6621832 // and the next request reads the unchanged prefix from cache.
from line 1868
6981868 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
6991869 
7001870 MessageCreateParams params = MessageCreateParams.builder()
701 .model(Model.CLAUDE_OPUS_5)
1871 .model(Model.CLAUDE_OPUS_5_5)
7021872 .maxTokens(1024)
7031873 // Automatic prompt caching: each request caches the conversation so far,
7041874 // and the next request reads the unchanged prefix from cache.
from line 1910
7401910 // request is still read from cache.
7411911 ['role' => 'system', 'content' => 'From now on, every suggestion must include explicit type annotations.']
7421912 ],
743 model: 'claude-opus-5',
1913 model: 'claude-opus-5-5',
7441914 // Automatic prompt caching: each request caches the conversation so far,
7451915 // and the next request reads the unchanged prefix from cache.
7461916 cacheControl: CacheControlEphemeral::with(),
from line 1928
7581928 client = Anthropic::Client.new
7591929 
7601930 response = client.messages.create(
761 model: "claude-opus-5",
1931 model: "claude-opus-5-5",
7621932 max_tokens: 1024,
7631933 # Automatic prompt caching: each request caches the conversation so far,
7641934 # and the next request reads the unchanged prefix from cache.
from line 2001
8312001}
8322002```
8332003 
834The main use is a per-turn reminder in a tool loop. Append the reminder after the `tool_result` message each time you want the model to see it, and leave every earlier copy where it is. The model sees only the copies that come after the last user message, so the reminder never piles up. Nothing earlier in `messages` changes, so the [prompt cache](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) keeps matching. On Claude Fable 5.1 this also keeps later [thinking blocks valid](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation): deleting an earlier reminder would change the conversation before those blocks and fail the conversation check, while a cleared message stays in the array and leaves that conversation unchanged.
2004The main use is a per-turn reminder in a tool loop. Append the reminder after the `tool_result` message each time you want the model to see it, and leave every earlier copy where it is. The model sees only the copies that come after the last user message, so the reminder never piles up. Nothing earlier in `messages` changes, so the [prompt cache](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) keeps matching. On Claude Fable 5.1 and Claude Opus 5.5 this also keeps later [thinking blocks valid](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation): deleting an earlier reminder would change the conversation before those blocks and fail the conversation check, while a cleared message stays in the array and leaves that conversation unchanged.
8352005 
8362006The following request is a later step of an agent loop. `messages[3]` rendered on the earlier request, when it was the last message in the array. Once `messages[5]` (a later user message) exists, `messages[3]` is cleared: the cleared message stays in the array, so the conversation before the thinking block in `messages[4]` is unchanged, but the model no longer sees its text. `messages[6]` and `messages[7]` both render, in order.
8372007 
from line 2078
9082078 
9092079Rules for turn-scoped messages:
9102080 
911* **Re-send cleared messages verbatim.** A cleared message is still part of the conversation history. Rebuilding it from current state (a fresh token count, a timestamp), dropping it as redundant, or changing its `clear_at` value is an edit to an earlier message. The prompt cache misses from that point, and on Claude Fable 5.1 every thinking block produced after it fails the [conversation check](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation).
2081* **Re-send cleared messages verbatim.** A cleared message is still part of the conversation history. Rebuilding it from current state (a fresh token count, a timestamp), dropping it as redundant, or changing its `clear_at` value is an edit to an earlier message. The prompt cache misses from that point, and on Claude Fable 5.1 and Claude Opus 5.5 every thinking block produced after it fails the [conversation check](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation).
9122082* **Text only.** `content` is one or more `text` blocks (or a string). `tool_addition` and `tool_removal` blocks return a 400 error on a turn-scoped message, and so does `output_config`. Use a separate `role: "system"` message without `clear_at` for those.
9132083* **No `cache_control` on its blocks.** A cleared message is never part of a cache key, so a breakpoint on it could never match. Put the breakpoint on the last block of the preceding user turn instead, as the example does. The top-level [automatic caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#automatic-caching) field skips turn-scoped messages when it picks a breakpoint. On the request that clears a message, the reusable cached prefix ends at the user turn before it, so only the one assistant turn between that message and the new user message is reprocessed.
9142084* **Placement rules still apply**, cleared or not. A turn-scoped message must follow a `user` turn (or an `assistant` turn ending in a server tool result) and precede an `assistant` turn or end the array, like any mid-conversation system message. One that ends the array always renders. One followed directly by another `user` message is a 400 error, not a cleared message: put all of a tool round's results in one user message and the reminders after it.
from line 2335
11652335* **Append the system message after the breakpoint.** Because it comes after the cached prefix, it does not change the prefix hash and the cache still hits.
11662336* **A mid-conversation system message is itself cacheable.** Once it is in the conversation, it becomes part of the stable history. On the next turn you can move your cache breakpoint past it (or rely on [automatic caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#automatic-caching) to do so) and the system message is read from cache like any other turn.
11672337 
1168Avoid editing or removing a mid-conversation system message that has already been sent. Like any other change to earlier messages, that invalidates the cache from that point forward. On Claude Fable 5.1 it also invalidates the [thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation) in every later assistant turn. For guidance that should apply to one turn only, use a [turn-scoped system message](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#turn-scoped-system-messages) and leave it in place. If the instruction needs to evolve, append a new system message rather than rewriting the old one. Consecutive system messages are accepted and treated as a single system section, which follows the same placement rule as a whole.
2338Avoid editing or removing a mid-conversation system message that has already been sent. Like any other change to earlier messages, that invalidates the cache from that point forward. On Claude Fable 5.1 and Claude Opus 5.5 it also invalidates the [thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-in-conversation) in every later assistant turn. For guidance that should apply to one turn only, use a [turn-scoped system message](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#turn-scoped-system-messages) and leave it in place. If the instruction needs to evolve, append a new system message rather than rewriting the old one. Consecutive system messages are accepted and treated as a single system section, which follows the same placement rule as a whole.
11692339 
11702340## Limitations
11712341 
11722342 

build-with-claude/multilingual-support Changed · +9 / -9 lines

from line 51
5151 -H "x-api-key: $ANTHROPIC_API_KEY" \
5252 -H "anthropic-version: 2023-06-01" \
5353 -d '{
54 "model": "claude-opus-5",
54 "model": "claude-opus-5-5",
5555 "max_tokens": 1024,
5656 "system": "Always respond in French, regardless of the language the user writes in.",
5757 "messages": [
from line 62
6262 
6363 ```bash CLI
6464 ant messages create \
65 --model claude-opus-5 \
65 --model claude-opus-5-5 \
6666 --max-tokens 1024 \
6767 --system "Always respond in French, regardless of the language the user writes in." \
6868 --message '{role: user, content: "How do I reset my password?"}'
from line 72
7272 client = anthropic.Anthropic()
7373 
7474 message = client.messages.create(
75 model="claude-opus-5",
75 model="claude-opus-5-5",
7676 max_tokens=1024,
7777 system="Always respond in French, regardless of the language the user writes in.",
7878 messages=[{"role": "user", "content": "How do I reset my password?"}],
from line 85
8585 const client = new Anthropic();
8686 
8787 const message = await client.messages.create({
88 model: "claude-opus-5",
88 model: "claude-opus-5-5",
8989 max_tokens: 1024,
9090 system: "Always respond in French, regardless of the language the user writes in.",
9191 messages: [{ role: "user", content: "How do I reset my password?" }]
from line 99
9999 
100100 var parameters = new MessageCreateParams
101101 {
102 Model = Model.ClaudeOpus5,
102 Model = Model.ClaudeOpus5_5,
103103 MaxTokens = 1024,
104104 System = "Always respond in French, regardless of the language the user writes in.",
105105 Messages =
from line 116
116116 client := anthropic.NewClient()
117117 
118118 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
119 Model: anthropic.ModelClaudeOpus5,
119 Model: anthropic.ModelClaudeOpus5_5,
120120 MaxTokens: 1024,
121121 System: []anthropic.TextBlockParam{
122122 {Text: "Always respond in French, regardless of the language the user writes in."},
from line 135
135135 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
136136 
137137 MessageCreateParams params = MessageCreateParams.builder()
138 .model(Model.CLAUDE_OPUS_5)
138 .model(Model.CLAUDE_OPUS_5_5)
139139 .maxTokens(1024)
140140 .system("Always respond in French, regardless of the language the user writes in.")
141141 .addUserMessage("How do I reset my password?")
from line 153
153153 messages: [
154154 ['role' => 'user', 'content' => 'How do I reset my password?']
155155 ],
156 model: 'claude-opus-5',
156 model: 'claude-opus-5-5',
157157 system: 'Always respond in French, regardless of the language the user writes in.',
158158 );
159159 
from line 164
164164 client = Anthropic::Client.new
165165 
166166 message = client.messages.create(
167 model: "claude-opus-5",
167 model: "claude-opus-5-5",
168168 max_tokens: 1024,
169169 system: "Always respond in French, regardless of the language the user writes in.",
170170 messages: [

build-with-claude/pdf-support Changed · +55 / -55 lines

from line 113
113113 -H "x-api-key: $ANTHROPIC_API_KEY" \
114114 -H "anthropic-version: 2023-06-01" \
115115 -d '{
116 "model": "claude-opus-5",
116 "model": "claude-opus-5-5",
117117 "max_tokens": 1024,
118118 "messages": [{
119119 "role": "user",
from line 134
134134 
135135 ```bash CLI
136136 ant messages create --transform content --format yaml <<'YAML'
137 model: claude-opus-5
137 model: claude-opus-5-5
138138 max_tokens: 1024
139139 messages:
140140 - role: user
from line 151
151151 ```python Python
152152 client = anthropic.Anthropic()
153153 message = client.messages.create(
154 model="claude-opus-5",
154 model="claude-opus-5-5",
155155 max_tokens=1024,
156156 messages=[
157157 {
from line 177
177177 const anthropic = new Anthropic();
178178 
179179 const response = await anthropic.messages.create({
180 model: "claude-opus-5",
180 model: "claude-opus-5-5",
181181 max_tokens: 1024,
182182 messages: [
183183 {
from line 217
217217 // Create a message with document and text content blocks
218218 var message = await client.Messages.Create(new MessageCreateParams
219219 {
220 Model = Model.ClaudeOpus5,
220 Model = Model.ClaudeOpus5_5,
221221 MaxTokens = 1024,
222222 Messages =
223223 [
from line 240
240240 client := anthropic.NewClient()
241241 
242242 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
243 Model: anthropic.ModelClaudeOpus5,
243 Model: anthropic.ModelClaudeOpus5_5,
244244 MaxTokens: 1024,
245245 Messages: []anthropic.MessageParam{
246246 anthropic.NewUserMessage(
from line 274
274274 
275275 // Create a message with document and text content blocks
276276 MessageCreateParams params = MessageCreateParams.builder()
277 .model(Model.CLAUDE_OPUS_5)
277 .model(Model.CLAUDE_OPUS_5_5)
278278 .maxTokens(1024)
279279 .addUserMessageOfBlockParams(
280280 List.of(
from line 315
315315 ],
316316 ],
317317 ],
318 model: 'claude-opus-5',
318 model: 'claude-opus-5-5',
319319 );
320320 
321321 echo $message;
from line 325
325325 anthropic = Anthropic::Client.new
326326 
327327 message = anthropic.messages.create(
328 model: "claude-opus-5",
328 model: "claude-opus-5-5",
329329 max_tokens: 1024,
330330 messages: [
331331 {
from line 355
355355 "id": "msg_01Hfp8YuFjQ55VgWbpdHDehB",
356356 "type": "message",
357357 "role": "assistant",
358 "model": "claude-opus-5",
358 "model": "claude-opus-5-5",
359359 "content": [
360360 {
361361 "type": "text",
from line 384
384384 
385385 # Create a JSON request file using the pdf_base64.txt content
386386 jq -n --rawfile PDF_BASE64 pdf_base64.txt '{
387 "model": "claude-opus-5",
387 "model": "claude-opus-5-5",
388388 "max_tokens": 1024,
389389 "messages": [{
390390 "role": "user",
from line 413
413413 
414414 ```bash CLI
415415 ant messages create \
416 --model claude-opus-5 \
416 --model claude-opus-5-5 \
417417 --max-tokens 1024 \
418418 --transform content \
419419 --format yaml <<'YAML'
from line 447
447447 # Send to Claude using base64 encoding
448448 client = anthropic.Anthropic()
449449 message = client.messages.create(
450 model="claude-opus-5",
450 model="claude-opus-5-5",
451451 max_tokens=1024,
452452 messages=[
453453 {
from line 485
485485 // Send the API request with base64-encoded PDF
486486 const anthropic = new Anthropic();
487487 const response = await anthropic.messages.create({
488 model: "claude-opus-5",
488 model: "claude-opus-5-5",
489489 max_tokens: 1024,
490490 messages: [
491491 {
from line 531
531531 // Create a message with document and text content blocks
532532 var message = await client.Messages.Create(new MessageCreateParams
533533 {
534 Model = Model.ClaudeOpus5,
534 Model = Model.ClaudeOpus5_5,
535535 MaxTokens = 1024,
536536 Messages =
537537 [
from line 571
571571 // Send to Claude using base64 encoding
572572 client := anthropic.NewClient()
573573 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
574 Model: anthropic.ModelClaudeOpus5,
574 Model: anthropic.ModelClaudeOpus5_5,
575575 MaxTokens: 1024,
576576 Messages: []anthropic.MessageParam{
577577 anthropic.NewUserMessage(
from line 615
615615 
616616 // Create a message with document and text content blocks
617617 MessageCreateParams params = MessageCreateParams.builder()
618 .model(Model.CLAUDE_OPUS_5)
618 .model(Model.CLAUDE_OPUS_5_5)
619619 .maxTokens(1024)
620620 .addUserMessageOfBlockParams(
621621 List.of(
from line 665
665665 ],
666666 ],
667667 ],
668 model: 'claude-opus-5',
668 model: 'claude-opus-5-5',
669669 );
670670 
671671 echo $message;
from line 685
685685 # Send to Claude using base64 encoding
686686 anthropic = Anthropic::Client.new
687687 message = anthropic.messages.create(
688 model: "claude-opus-5",
688 model: "claude-opus-5-5",
689689 max_tokens: 1024,
690690 messages: [
691691 {
from line 728
728728 -H "anthropic-version: 2023-06-01" \
729729 -d @- <<EOF
730730 {
731 "model": "claude-opus-5",
731 "model": "claude-opus-5-5",
732732 "max_tokens": 1024,
733733 "messages": [{
734734 "role": "user",
from line 759
759759 ant messages create \
760760 --transform content \
761761 --format yaml <<YAML
762 model: claude-opus-5
762 model: claude-opus-5-5
763763 max_tokens: 1024
764764 messages:
765765 - role: user
from line 782
782782 
783783 # Use the uploaded file in a message
784784 message = client.messages.create(
785 model="claude-opus-5",
785 model="claude-opus-5-5",
786786 max_tokens=1024,
787787 messages=[
788788 {
from line 816
816816 
817817 // Use the uploaded file in a message
818818 const response = await anthropic.messages.create({
819 model: "claude-opus-5",
819 model: "claude-opus-5-5",
820820 max_tokens: 1024,
821821 messages: [
822822 {
from line 858
858858 // Use the uploaded file in a message
859859 var message = await client.Messages.Create(new MessageCreateParams
860860 {
861 Model = Model.ClaudeOpus5,
861 Model = Model.ClaudeOpus5_5,
862862 MaxTokens = 1024,
863863 Messages =
864864 [
from line 899
899899 
900900 // Use the uploaded file in a message
901901 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
902 Model: anthropic.ModelClaudeOpus5,
902 Model: anthropic.ModelClaudeOpus5_5,
903903 MaxTokens: 1024,
904904 Messages: []anthropic.MessageParam{
905905 anthropic.NewUserMessage(
from line 927
927927 
928928 // Use the uploaded file in a message
929929 MessageCreateParams params = MessageCreateParams.builder()
930 .model(Model.CLAUDE_OPUS_5)
930 .model(Model.CLAUDE_OPUS_5_5)
931931 .maxTokens(1024)
932932 .addUserMessageOfBlockParams(
933933 List.of(
from line 978
978978 ],
979979 ],
980980 ],
981 model: 'claude-opus-5',
981 model: 'claude-opus-5-5',
982982 );
983983 
984984 echo $message;
from line 996
996996 
997997 # Use the uploaded file in a message
998998 message = anthropic.messages.create(
999 model: "claude-opus-5",
999 model: "claude-opus-5-5",
10001000 max_tokens: 1024,
10011001 messages: [
10021002 {
from line 1076
10761076 curl -sL "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf" | base64 | tr -d '\n' > pdf_base64.txt
10771077 # Create a JSON request file using the pdf_base64.txt content
10781078 jq -n --rawfile PDF_BASE64 pdf_base64.txt '{
1079 "model": "claude-opus-5",
1079 "model": "claude-opus-5-5",
10801080 "max_tokens": 1024,
10811081 "messages": [{
10821082 "role": "user",
from line 1108
11081108 
11091109 ```bash CLI
11101110 ant messages create --transform content --format yaml <<'YAML'
1111 model: claude-opus-5
1111 model: claude-opus-5-5
11121112 max_tokens: 1024
11131113 messages:
11141114 - role: user
from line 1138
11381138 # Create a message with the cached document
11391139 client = anthropic.Anthropic()
11401140 message = client.messages.create(
1141 model="claude-opus-5",
1141 model="claude-opus-5-5",
11421142 max_tokens=1024,
11431143 messages=[
11441144 {
from line 1176
11761176 // Create a message with the cached document
11771177 const anthropic = new Anthropic();
11781178 const response = await anthropic.messages.create({
1179 model: "claude-opus-5",
1179 model: "claude-opus-5-5",
11801180 max_tokens: 1024,
11811181 messages: [
11821182 {
from line 1213
12131213 
12141214 var message = await client.Messages.Create(new MessageCreateParams
12151215 {
1216 Model = Model.ClaudeOpus5,
1216 Model = Model.ClaudeOpus5_5,
12171217 MaxTokens = 1024,
12181218 Messages =
12191219 [
from line 1253
12531253 // Create a document block with cache control
12541254 client := anthropic.NewClient()
12551255 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1256 Model: anthropic.ModelClaudeOpus5,
1256 Model: anthropic.ModelClaudeOpus5_5,
12571257 MaxTokens: 1024,
12581258 Messages: []anthropic.MessageParam{
12591259 anthropic.NewUserMessage(
from line 1294
12941294 String pdfBase64 = Base64.getEncoder().encodeToString(response.body());
12951295 
12961296 MessageCreateParams params = MessageCreateParams.builder()
1297 .model(Model.CLAUDE_OPUS_5)
1297 .model(Model.CLAUDE_OPUS_5_5)
12981298 .maxTokens(1024)
12991299 .addUserMessageOfBlockParams(
13001300 List.of(
from line 1348
13481348 ],
13491349 ],
13501350 ],
1351 model: 'claude-opus-5',
1351 model: 'claude-opus-5-5',
13521352 );
13531353 
13541354 echo $message;
from line 1365
13651365 anthropic = Anthropic::Client.new
13661366 
13671367 message = anthropic.messages.create(
1368 model: "claude-opus-5",
1368 model: "claude-opus-5-5",
13691369 max_tokens: 1024,
13701370 messages: [
13711371 {
from line 1406
14061406 {
14071407 "custom_id": "my-first-request",
14081408 "params": {
1409 "model": "claude-opus-5",
1409 "model": "claude-opus-5-5",
14101410 "max_tokens": 1024,
14111411 "messages": [{
14121412 "role": "user",
from line 1428
14281428 {
14291429 "custom_id": "my-second-request",
14301430 "params": {
1431 "model": "claude-opus-5",
1431 "model": "claude-opus-5-5",
14321432 "max_tokens": 1024,
14331433 "messages": [{
14341434 "role": "user",
from line 1462
14621462 requests:
14631463 - custom_id: my-first-request
14641464 params:
1465 model: claude-opus-5
1465 model: claude-opus-5-5
14661466 max_tokens: 1024
14671467 messages:
14681468 - role: user
from line 1478
14781478 across each use-case?
14791479 - custom_id: my-second-request
14801480 params:
1481 model: claude-opus-5
1481 model: claude-opus-5-5
14821482 max_tokens: 1024
14831483 messages:
14841484 - role: user
from line 1510
15101510 {
15111511 "custom_id": "my-first-request",
15121512 "params": {
1513 "model": "claude-opus-5",
1513 "model": "claude-opus-5-5",
15141514 "max_tokens": 1024,
15151515 "messages": [
15161516 {
from line 1536
15361536 {
15371537 "custom_id": "my-second-request",
15381538 "params": {
1539 "model": "claude-opus-5",
1539 "model": "claude-opus-5-5",
15401540 "max_tokens": 1024,
15411541 "messages": [
15421542 {
from line 1580
15801580 {
15811581 custom_id: "my-first-request",
15821582 params: {
1583 model: "claude-opus-5",
1583 model: "claude-opus-5-5",
15841584 max_tokens: 1024,
15851585 messages: [
15861586 {
from line 1606
16061606 {
16071607 custom_id: "my-second-request",
16081608 params: {
1609 model: "claude-opus-5",
1609 model: "claude-opus-5-5",
16101610 max_tokens: 1024,
16111611 messages: [
16121612 {
from line 1652
16521652 CustomID = "my-first-request",
16531653 Params = new()
16541654 {
1655 Model = Model.ClaudeOpus5,
1655 Model = Model.ClaudeOpus5_5,
16561656 MaxTokens = 1024,
16571657 Messages =
16581658 [
from line 1676
16761676 CustomID = "my-second-request",
16771677 Params = new()
16781678 {
1679 Model = Model.ClaudeOpus5,
1679 Model = Model.ClaudeOpus5_5,
16801680 MaxTokens = 1024,
16811681 Messages =
16821682 [
from line 1722
17221722 {
17231723 CustomID: "my-first-request",
17241724 Params: anthropic.MessageBatchNewParamsRequestParams{
1725 Model: anthropic.ModelClaudeOpus5,
1725 Model: anthropic.ModelClaudeOpus5_5,
17261726 MaxTokens: 1024,
17271727 Messages: []anthropic.MessageParam{
17281728 anthropic.NewUserMessage(
from line 1737
17371737 {
17381738 CustomID: "my-second-request",
17391739 Params: anthropic.MessageBatchNewParamsRequestParams{
1740 Model: anthropic.ModelClaudeOpus5,
1740 Model: anthropic.ModelClaudeOpus5_5,
17411741 MaxTokens: 1024,
17421742 Messages: []anthropic.MessageParam{
17431743 anthropic.NewUserMessage(
from line 1779
17791779 .customId("my-first-request")
17801780 .params(
17811781 BatchCreateParams.Request.Params.builder()
1782 .model(Model.CLAUDE_OPUS_5)
1782 .model(Model.CLAUDE_OPUS_5_5)
17831783 .maxTokens(1024)
17841784 .addUserMessageOfBlockParams(
17851785 List.of(
from line 1806
18061806 .customId("my-second-request")
18071807 .params(
18081808 BatchCreateParams.Request.Params.builder()
1809 .model(Model.CLAUDE_OPUS_5)
1809 .model(Model.CLAUDE_OPUS_5_5)
18101810 .maxTokens(1024)
18111811 .addUserMessageOfBlockParams(
18121812 List.of(
from line 1844
18441844 [
18451845 'custom_id' => 'my-first-request',
18461846 'params' => [
1847 'model' => 'claude-opus-5',
1847 'model' => 'claude-opus-5-5',
18481848 'max_tokens' => 1024,
18491849 'messages' => [
18501850 [
from line 1870
18701870 [
18711871 'custom_id' => 'my-second-request',
18721872 'params' => [
1873 'model' => 'claude-opus-5',
1873 'model' => 'claude-opus-5-5',
18741874 'max_tokens' => 1024,
18751875 'messages' => [
18761876 [
from line 1914
19141914 {
19151915 custom_id: "my-first-request",
19161916 params: {
1917 model: "claude-opus-5",
1917 model: "claude-opus-5-5",
19181918 max_tokens: 1024,
19191919 messages: [
19201920 {
from line 1940
19401940 {
19411941 custom_id: "my-second-request",
19421942 params: {
1943 model: "claude-opus-5",
1943 model: "claude-opus-5-5",
19441944 max_tokens: 1024,
19451945 messages: [
19461946 {

build-with-claude/preserved-thinking Changed · +62 / -23 lines

from line 6
66 
77Preserved thinking is a property of newer Claude models that guards against distillation. It decides whether the model can use a thinking block that you send back from an earlier turn. Starting with Claude Fable 5.1, when a `thinking` or `redacted_thinking` block comes back in a request, the API checks the block's `signature` for two things:
88 
9* **The model is the one that produced the block, or a newer one.** A model reads its own thinking blocks and those of earlier models. Claude Fable 5.1 reads blocks from Claude Opus 5, but Claude Opus 5 can't read blocks from Claude Fable 5.1. If the current model can't read a block, the API drops it from that request without an error. See [Switching models mid-conversation](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#switching-models).
9* **The model can read the block.** Each model reads its own thinking blocks and those of a fixed set of other models. Claude Fable 5.1 reads blocks from Claude Opus 5 and, on the Claude API, from Claude Opus 5.5; neither Claude Opus 5 nor Claude Opus 5.5 reads blocks from Claude Fable 5.1. If the current model can't read a block, the API drops it from that request without an error. See [Switching models mid-conversation](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#switching-models).
1010* **Nothing before the thinking block has changed.** The top-level `system` prompt, `tools`, and `messages` before the block are its prefix. If the prefix differs from what you sent when the block was produced, that block and every later thinking block are invalid, and the API rejects the request with a 400 error or drops the invalid blocks, whichever you choose. See [Keeping the prefix unchanged](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#prefix-check).
1111 
12The model check applies to every account. The API enforces the prefix check by default for accounts created on or after August 31, 2026, 00:00 UTC. On older accounts, it enforces the prefix check only on requests that set `thinking.block_binding.prefix_mismatch_behavior`. **Later models will enforce the prefix check for all accounts**, so make your integration append-only now.
12The model check applies to every account. The API enforces the prefix check by default for accounts created on or after August 31, 2026, 00:00 UTC. On older accounts, it enforces the prefix check only on requests that set `thinking.block_binding.prefix_mismatch_behavior`. **Make your integration append-only regardless of your account's age**, so the same code works on every account, including newer accounts enforced by default.
1313 
1414## Who needs to change anything
1515 
from line 32
3232 
3333Claude Fable 5.1 and Claude Mythos 5.1 read thinking blocks produced by each other and by earlier Claude models. No earlier model reads thinking blocks from Claude Fable 5.1 or Claude Mythos 5.1.
3434 
35* **A conversation that moves up to Claude Fable 5.1 keeps its reasoning.** The earlier model's thinking blocks stay readable, so the model thinks as usual from the first turn after the switch.
35Claude Opus 5.5 reads thinking blocks from Claude Opus 5 and earlier Opus, Sonnet, and Haiku models, but not from Claude Fable or Claude Mythos models. On the Claude API, Claude Fable 5.1 and Claude Mythos 5.1 read thinking blocks from Claude Opus 5.5; no other model does. So a conversation that moves from Claude Opus 5 onto Claude Opus 5.5 keeps its reasoning, and so does one that moves from Claude Opus 5.5 up to Claude Fable 5.1 or Claude Mythos 5.1 on the Claude API. One that moves from Claude Fable 5.1 or Claude Mythos 5.1 to Claude Opus 5.5, or from Claude Opus 5.5 to any model other than those two, runs the turns after the switch without the previous model's reasoning. The blocks are dropped, not rejected, as described below.
36 
37* **A conversation that moves to Claude Fable 5.1 from an earlier model, or from Claude Opus 5.5 on the Claude API, keeps its reasoning.** The earlier model's thinking blocks stay readable, so the model thinks as usual from the first turn after the switch.
3638* **A conversation that moves down to an earlier model loses Claude Fable 5.1's reasoning for that request.** This happens when a router sends a turn to a cheaper model, after a [classifier refusal fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback), or during a [server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback). The API removes the unreadable blocks before the prompt reaches the model. They aren't billed and don't count toward `input_tokens`.
3739 
3840Keep sending the full history on every request, thinking blocks included, and let the API drop what the current model can't read. The API never edits your `messages` array, so the dropped blocks stay in your history. When the same history goes back to Claude Fable 5.1, its blocks are readable again, along with the earlier model's thinking. The reasoning is lost for good only if your client removes the blocks itself, for example a harness that strips thinking on a model switch or rebuilds the history from what each model used.
from line 59
5759 
5860## Keeping the prefix unchanged
5961 
60On Claude Fable 5.1, a thinking block stays valid only while everything you sent before it is unchanged on later requests. The checked prefix has three parts:
62On Claude Fable 5.1 and Claude Opus 5.5, a thinking block stays valid only while everything you sent before it is unchanged on later requests. The checked prefix has three parts:
6163 
6264* The top-level `system` prompt
6365* The set of `tools`
from line 378
376378 
377379### When the API enforces the check
378380 
379The API enforces the prefix check on Claude Fable 5.1 for new accounts.
381The API enforces the prefix check on Claude Fable 5.1 and Claude Opus 5.5 for new accounts.
380382 
381* **Accounts created on or after August 31, 2026, 00:00 UTC:** the API checks Claude Fable 5.1 requests and applies `"error"` unless you set `"drop_block"`. The same definition of a new account applies to the Claude API and to cloud platforms.
383* **Accounts created on or after August 31, 2026, 00:00 UTC:** the API checks Claude Fable 5.1 and Claude Opus 5.5 requests and applies `"error"` unless you set `"drop_block"`. The same definition of a new account applies to the Claude API and to cloud platforms.
382384* **Older accounts:** the API enforces the check only on requests that set `prefix_mismatch_behavior`. Setting the field opts a request in, so you can see what a new account sees without creating one. On requests that leave it unset, the API still runs the check but lets failing blocks through to the model. With the beta header, the response lists each one in `input_transformations` as `thinking_mismatch_allowed`, so you can find prefix edits without changing what the model receives.
383* **Later models:** every account, on every request.
384385 
385386To find out which group your account is in, take a Claude Fable 5.1 conversation that contains a thinking block, change something before that block, and send it to Claude Fable 5.1 without the beta header or the `block_binding` field. A 400 response that names the header means your account is enforced by default. A 200 response means it isn't. To confirm, send the same request again with the beta header, still without `block_binding`: the response lists every thinking block after your edit in `input_transformations` as `thinking_mismatch_allowed`.
386387 
from line 1205
12041205 
12051206Each common prefix edit has a replacement that gives the model the same information and leaves earlier bytes unchanged, so later thinking stays valid. Find the edit your code makes today in the first column:
12061207 
1207| Instead of | Use | Beta header |
1208| --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
1209| Rebuilding the top-level `system` prompt | A [mid-conversation system message](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#new-instructions) | None |
1210| Re-rendering the context in your first user message (environment, date, memory, project instructions) on each request | Render it once and resend it unchanged. When something changes, [put the new version in the newest turn](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#changing-context) | None |
1211| Clearing or shortening old `tool_result` content, or re-encoding old images, in place | Shorten a tool result or downscale an image before the first time you send it, not after. To clear old results later, [trim context on the server](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#server-side-trimming) with `clear_tool_uses_20250919` | `context-management-2025-06-27` |
1212| Injecting a reminder and deleting it on the next request | A [turn-scoped system message](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#per-turn-reminders) (`clear_at: "next_user_message"`) | `mid-conversation-system-clear-at-2026-08-21` |
1213| Adding or removing entries in `tools` | [`tool_addition` and `tool_removal` blocks](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#tool-changes) | `mid-conversation-tool-changes-2026-07-01` |
1214| Changing top-level `output_config.effort` (restarts the cache, doesn't affect thinking) | A [per-message `output_config`](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#effort-changes) | `mid-conversation-output-config-2026-07-01` |
1215| Dropping or summarizing old turns on the client | [On-demand compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand) to keep the recent turns with their thinking, other server-side [compaction or context editing](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#server-side-trimming), or [client-side compaction](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#custom-compaction-on-the-client) that keeps no stale thinking | `compact-2026-09-04` |
1216| An image or document URL whose bytes change between requests | A [`file_id` from the Files API](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#files-by-id), or base64 | None |
1208| Instead of | Use | Beta header |
1209| --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1210| Rebuilding the top-level `system` prompt | A [mid-conversation system message](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#new-instructions) | None |
1211| Re-rendering the context in your first user message (environment, date, memory, project instructions) on each request | Render it once and resend it unchanged. When something changes, [put the new version in the newest turn](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#changing-context) | None |
1212| Clearing or shortening old `tool_result` content, or re-encoding old images, in place | Shorten a tool result or downscale an image before the first time you send it, not after. To clear old results later, [trim context on the server](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#server-side-trimming) with `clear_tool_uses_20250919` | `context-management-2025-06-27` |
1213| Injecting a reminder and deleting it on the next request | A [turn-scoped system message](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#per-turn-reminders) (`clear_at: "next_user_message"`) | `mid-conversation-system-clear-at-2026-08-21` |
1214| Adding or removing entries in `tools` | [`tool_addition` and `tool_removal` blocks](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#tool-changes) | `inline-tools-2026-09-15` (add `mcp-client-2026-09-15` when the tool comes from an MCP server connected through the MCP connector), or the older `mid-conversation-tool-changes-2026-07-01`, which works on the Claude API, Amazon Bedrock, and Google Cloud |
1215| Changing top-level `output_config.effort` (restarts the cache, doesn't affect thinking) | A [per-message `output_config`](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#effort-changes) | `mid-conversation-output-config-2026-07-01` |
1216| Dropping or summarizing old turns on the client | [On-demand compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand) to keep the recent turns with their thinking, other server-side [compaction or context editing](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#server-side-trimming), or [client-side compaction](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#custom-compaction-on-the-client) that keeps no stale thinking | `compact-2026-09-04` |
1217| An image or document URL whose bytes change between requests | A [`file_id` from the Files API](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#files-by-id), or base64 | None |
12171218 
12181219All of these assume you [send assistant turns back exactly as returned](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#append-assistant-turns-exactly-as-returned). Mid-conversation system messages, turn-scoped system messages, and tool changes aren't available on every model: [Mid-conversation system messages and tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages) lists the models that accept them. If your code serves several models, keep editing the top-level `system` prompt for the models that don't accept them.
12191220 
from line 1221
12201221To use several betas in one request, combine the values in one `anthropic-beta` header. Beta names are the same on Amazon Bedrock and Google Cloud wherever the beta is available there (see [Beta headers](https://platform.claude.com/docs/en/api/beta-headers)):
12211222 
12221223```text wrap
1223anthropic-beta: thinking-binding-controls-2026-08-01,mid-conversation-system-clear-at-2026-08-21,mid-conversation-tool-changes-2026-07-01
1224anthropic-beta: thinking-binding-controls-2026-08-01,mid-conversation-system-clear-at-2026-08-21,inline-tools-2026-09-15
12241225```
12251226 
12261227### Send assistant turns back exactly as returned
from line 1318
13171318 
13181319### Add or remove tools with `tool_addition` and `tool_removal`
13191320 
1320Editing the `tools` array mid-session invalidates preserved thinking blocks. Instead, declare every tool the session might need in `tools` on the first request and never change the array. To change which tools the model can use from some point on, append a `role: "system"` message that carries a `tool_removal` or `tool_addition` block. These are [mid-conversation tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#mid-conversation-tool-changes) and need the beta header `mid-conversation-tool-changes-2026-07-01`. For example, to withdraw a dangerous tool after a mode switch:
1321Editing the `tools` array mid-session invalidates preserved thinking blocks. Leave the array as you first sent it, and change which tools the model can use by appending a `role: "system"` message that carries `tool_addition` or `tool_removal` blocks. These are [mid-conversation tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#mid-conversation-tool-changes) and need the beta header `inline-tools-2026-09-15`, which is available on the Claude API. The older `mid-conversation-tool-changes-2026-07-01` header still works for changes that name a tool by reference, on the Claude API, Amazon Bedrock, and Google Cloud.
13211322 
1323You have two ways to use these blocks:
1324 
1325* **Declare every tool up front.** Put every tool the session might need in `tools` on the first request, with `defer_loading: true` on any the model shouldn't see yet. Then turn tools on and off with `tool_addition` and `tool_removal` blocks that name them.
1326* **Start with a snapshot and add tools as you go.** Put the tools you know about in `tools` on the first request. When a new tool comes along, define it inside a `tool_addition` block instead of editing `tools`.
1327 
1328Either way, `tools` never changes, so earlier thinking stays valid and the prompt cache still hits, with the one exception noted below.
1329 
1330For example, to withdraw a dangerous tool after a mode switch:
1331 
13221332```json
13231333{
13241334 "role": "system",
from line 1339
13291339}
13301340```
13311341 
1332To offer a tool later instead, declare it in `tools` with `defer_loading: true` so the model doesn't see it at first. When it becomes available, append a `tool_addition` block:
1342To turn on a tool you declared with `defer_loading: true`, append a `tool_addition` block that names it:
13331343 
13341344```json
13351345{
from line 1351
13411351}
13421352```
13431353 
1344Sometimes you can't declare a tool up front because you don't know its schema yet. An MCP server discovered at runtime is the common case. Append that tool to `tools` with `defer_loading: true`, then offer it with a `tool_addition` block. Adding a deferred tool is safe: the prefix check ignores a deferred tool until a `tool_addition` block references it, so earlier thinking stays valid. Adding a tool without `defer_loading: true` changes the prefix and invalidates earlier thinking.
1354Sometimes you can't declare a tool up front because you don't know its schema yet: a tool your application discovers at runtime, or an MCP server that connects after the first turn. Define it inside the `tool_addition` block instead of touching `tools`. With `inline-tools-2026-09-15`, the block's `tool` can be `{"type": "tool_definition", "definition": {...}}`, carrying the same entry you would have put in `tools`:
13451355 
1356```json
1357{
1358 "role": "system",
1359 "content": [
1360 {
1361 "type": "tool_addition",
1362 "tool": {
1363 "type": "tool_definition",
1364 "definition": {
1365 "name": "db_query",
1366 "description": "Run a read-only SQL query against the analytics database.",
1367 "input_schema": {
1368 "type": "object",
1369 "properties": { "sql": { "type": "string" } },
1370 "required": ["sql"]
1371 }
1372 }
1373 }
1374 }
1375 ]
1376}
1377```
1378 
1379The new tool arrives in `messages`, `tools` never changes, and earlier thinking stays valid. Keep at least one tool without `defer_loading: true` in `tools`: if every tool there is deferred, the first tool you define this way costs one full prompt cache miss.
1380 
1381If the API connects to the MCP server for you through the [MCP connector](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector), also send `mcp-client-2026-09-15`. It covers everything `mcp-client-2025-11-20` does, so send it instead of that one. The block's `definition` can then be an `mcp_toolset` for a server listed in `mcp_servers`. When the API has to fetch a server's tool list, the response starts with an `mcp_tool_listing` block for that server. Send it back unchanged with the rest of the assistant turn, and keep sending `mcp-client-2026-09-15` on every later request that carries it. The block pins the toolset to that list, so the API doesn't contact the server again for it. These MCP connector features are available on the Claude API.
1382 
1383With only the older header, you can still append a tool you learn about mid-session to `tools` with `defer_loading: true`, then offer it with a `tool_addition` block. That's safe because the prefix check ignores a deferred tool until a `tool_addition` block references it. Adding a tool without `defer_loading: true` changes the prefix and invalidates earlier thinking.
1384 
13461385The `role: "system"` messages that carry these blocks join the prefix for later thinking. Leave them in place on later requests.
13471386 
13481387### Change effort with a per-message `output_config`
from line 1686
16471686 </Accordion>
16481687 
16491688 <Accordion title="My tool list changes mid-session. How do I avoid invalidating the conversation?">
1650 Don't edit `tools`. Declare the full set at session start, mark tools that aren't available yet with `defer_loading: true`, and offer or withdraw them with `tool_addition` and `tool_removal` blocks. If you learn a tool's schema only mid-session, such as from an MCP server discovered at runtime, you can still append it to `tools` with `defer_loading: true` and offer it the same way. That's safe because an unreferenced deferred tool isn't part of the prefix. The `role: "system"` messages that carry these blocks join the prefix for later thinking, so don't move, reword, or delete them afterward. See [Add or remove tools with `tool_addition` and `tool_removal`](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#tool-changes).
1689 Don't edit `tools`. Declare the full set at session start, mark tools that aren't available yet with `defer_loading: true`, and offer or withdraw them with `tool_addition` and `tool_removal` blocks. If you learn a tool's schema only mid-session, define it inside the `tool_addition` block (`inline-tools-2026-09-15`, plus `mcp-client-2026-09-15` for a server the API's MCP connector reaches) and leave `tools` unchanged. The `role: "system"` messages that carry these blocks join the prefix for later thinking, so don't move, reword, or delete them afterward. See [Add or remove tools with `tool_addition` and `tool_removal`](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#tool-changes).
16511690 </Accordion>
16521691 
16531692 <Accordion title="I compact by summarizing older turns and keeping recent turns verbatim. Does that still work?">

build-with-claude/prompt-caching Changed · +95 / -88 lines

from line 24
2424 -H "x-api-key: $ANTHROPIC_API_KEY" \
2525 -H "anthropic-version: 2023-06-01" \
2626 -d '{
27 "model": "claude-opus-5",
27 "model": "claude-opus-5-5",
2828 "max_tokens": 1024,
2929 "cache_control": {"type": "ephemeral"},
3030 "system": "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
from line 39
3939 
4040 ```bash CLI
4141 ant messages create --transform usage <<'YAML'
42 model: claude-opus-5
42 model: claude-opus-5-5
4343 max_tokens: 1024
4444 cache_control:
4545 type: ephemeral
from line 56
5656 client = anthropic.Anthropic()
5757 
5858 response = client.messages.create(
59 model="claude-opus-5",
59 model="claude-opus-5-5",
6060 max_tokens=1024,
6161 cache_control={"type": "ephemeral"},
6262 system="You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
from line 74
7474 const client = new Anthropic();
7575 
7676 const response = await client.messages.create({
77 model: "claude-opus-5",
77 model: "claude-opus-5-5",
7878 max_tokens: 1024,
7979 cache_control: { type: "ephemeral" },
8080 system:
from line 94
9494 
9595 var parameters = new MessageCreateParams
9696 {
97 Model = Model.ClaudeOpus5,
97 Model = Model.ClaudeOpus5_5,
9898 MaxTokens = 1024,
9999 CacheControl = new CacheControlEphemeral(),
100100 System = "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
from line 116
116116 client := anthropic.NewClient()
117117 
118118 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
119 Model: anthropic.ModelClaudeOpus5,
119 Model: anthropic.ModelClaudeOpus5_5,
120120 MaxTokens: 1024,
121121 CacheControl: anthropic.NewCacheControlEphemeralParam(),
122122 System: []anthropic.TextBlockParam{
from line 141
141141 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
142142 
143143 MessageCreateParams params = MessageCreateParams.builder()
144 .model(Model.CLAUDE_OPUS_5)
144 .model(Model.CLAUDE_OPUS_5_5)
145145 .maxTokens(1024)
146146 .cacheControl(CacheControlEphemeral.builder().build())
147147 .system("You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.")
from line 164
164164 messages: [
165165 ['role' => 'user', 'content' => "Analyze the major themes in 'Pride and Prejudice'."]
166166 ],
167 model: 'claude-opus-5',
167 model: 'claude-opus-5-5',
168168 cacheControl: CacheControlEphemeral::with(),
169169 system: "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
170170 );
from line 175
175175 client = Anthropic::Client.new
176176 
177177 response = client.messages.create(
178 model: "claude-opus-5",
178 model: "claude-opus-5-5",
179179 max_tokens: 1024,
180180 cache_control: {type: "ephemeral"},
181181 system: "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
from line 222
222222<Tip>
223223 **Prompt caching caches the full prefix**
224224 
225 Prompt caching references the entire prompt - `tools`, `system`, and `messages` (in that order) up to and including the block designated with `cache_control`.
225 Prompt caching references the entire prompt: `tools`, `system`, and `messages` (in that order), up to and including the block designated with `cache_control`.
226226</Tip>
227227 
228228***
from line 237
237237| Claude Mythos 5.1 ([limited availability](https://anthropic.com/glasswing)) | $10 / MTok | $12.50 / MTok | $20 / MTok | $0.25 / MTok<sup>1</sup> | $50 / MTok |
238238| Claude Fable 5 | $10 / MTok | $12.50 / MTok | $20 / MTok | $1 / MTok | $50 / MTok |
239239| Claude Mythos 5 ([limited availability](https://anthropic.com/glasswing)) | $10 / MTok | $12.50 / MTok | $20 / MTok | $1 / MTok | $50 / MTok |
240| Claude Opus 5.5 | $4 / MTok | $5 / MTok | $8 / MTok | $0.20 / MTok<sup>2</sup> | $20 / MTok |
240241| Claude Opus 5 | $5 / MTok | $6.25 / MTok | $10 / MTok | $0.50 / MTok | $25 / MTok |
241242| Claude Opus 4.8 | $5 / MTok | $6.25 / MTok | $10 / MTok | $0.50 / MTok | $25 / MTok |
242243| Claude Opus 4.7 | $5 / MTok | $6.25 / MTok | $10 / MTok | $0.50 / MTok | $25 / MTok |
from line 252
251252| Claude Haiku 4.5 | $1 / MTok | $1.25 / MTok | $2 / MTok | $0.10 / MTok | $5 / MTok |
252253| Claude Haiku 3.5 ([retired, except on Bedrock and Google Cloud](https://platform.claude.com/docs/en/about-claude/model-deprecations)) | $0.80 / MTok | $1 / MTok | $1.60 / MTok | $0.08 / MTok | $4 / MTok |
253254 
254*<sup>1 Cache hits and refreshes on Claude Fable 5.1 and Claude Mythos 5.1 are priced at 0.025x the base input price. All other models use the standard 0.1x multiplier.</sup>*
255*<sup>1 Cache hits and refreshes on Claude Fable 5.1 and Claude Mythos 5.1 are priced at 0.025x the base input price.</sup>*
255256 
257*<sup>2 Cache hits and refreshes on Claude Opus 5.5 are priced at 0.05x the base input price.</sup>*
258 
259*<sup>All other models use the standard 0.1x multiplier.</sup>*
260 
256261<Note>
257262 The previous table reflects the following pricing multipliers for prompt caching:
258263 
from line 287
282287 -H "x-api-key: $ANTHROPIC_API_KEY" \
283288 -H "anthropic-version: 2023-06-01" \
284289 -d '{
285 "model": "claude-opus-5",
290 "model": "claude-opus-5-5",
286291 "max_tokens": 1024,
287292 "cache_control": {"type": "ephemeral"},
288293 "system": "You are a helpful assistant that remembers our conversation.",
from line 301
296301 
297302 ```bash CLI
298303 ant messages create --transform usage <<'YAML'
299 model: claude-opus-5
304 model: claude-opus-5-5
300305 max_tokens: 1024
301306 cache_control:
302307 type: ephemeral
from line 320
315320 client = anthropic.Anthropic()
316321 
317322 response = client.messages.create(
318 model="claude-opus-5",
323 model="claude-opus-5-5",
319324 max_tokens=1024,
320325 cache_control={"type": "ephemeral"},
321326 system="You are a helpful assistant that remembers our conversation.",
from line 340
335340 const client = new Anthropic();
336341 
337342 const response = await client.messages.create({
338 model: "claude-opus-5",
343 model: "claude-opus-5-5",
339344 max_tokens: 1024,
340345 cache_control: { type: "ephemeral" },
341346 system: "You are a helpful assistant that remembers our conversation.",
from line 361
356361 
357362 var parameters = new MessageCreateParams
358363 {
359 Model = Model.ClaudeOpus5,
364 Model = Model.ClaudeOpus5_5,
360365 MaxTokens = 1024,
361366 CacheControl = new CacheControlEphemeral(),
362367 System = "You are a helpful assistant that remembers our conversation.",
from line 393
388393 client := anthropic.NewClient()
389394 
390395 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
391 Model: anthropic.ModelClaudeOpus5,
396 Model: anthropic.ModelClaudeOpus5_5,
392397 MaxTokens: 1024,
393398 CacheControl: anthropic.NewCacheControlEphemeralParam(),
394399 System: []anthropic.TextBlockParam{
from line 420
415420 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
416421 
417422 MessageCreateParams params = MessageCreateParams.builder()
418 .model(Model.CLAUDE_OPUS_5)
423 .model(Model.CLAUDE_OPUS_5_5)
419424 .maxTokens(1024)
420425 .cacheControl(CacheControlEphemeral.builder().build())
421426 .system("You are a helpful assistant that remembers our conversation.")
from line 447
442447 ['role' => 'assistant', 'content' => 'Nice to meet you, Alex! How can I help with your ML work today?'],
443448 ['role' => 'user', 'content' => 'What did I say I work on?'],
444449 ],
445 model: 'claude-opus-5',
450 model: 'claude-opus-5-5',
446451 cacheControl: CacheControlEphemeral::with(),
447452 system: 'You are a helpful assistant that remembers our conversation.',
448453 );
from line 458
453458 client = Anthropic::Client.new
454459 
455460 response = client.messages.create(
456 model: "claude-opus-5",
461 model: "claude-opus-5-5",
457462 max_tokens: 1024,
458463 cache_control: {type: "ephemeral"},
459464 system: "You are a helpful assistant that remembers our conversation.",
from line 500
495500 
496501```json
497502{
498 "model": "claude-opus-5",
503 "model": "claude-opus-5-5",
499504 "max_tokens": 1024,
500505 "cache_control": { "type": "ephemeral" },
501506 "system": [
from line 523
518523* If the last block already has an explicit `cache_control` with the same TTL, automatic caching is a no-op.
519524* If the last block has an explicit `cache_control` with a different TTL, the API returns a 400 error.
520525* If 4 explicit block-level breakpoints already exist, the API returns a 400 error (no slots left for automatic caching).
521* If the last block is not eligible as an automatic cache breakpoint target, the system silently walks backwards to find the nearest eligible block. If none is found, caching is skipped.
526* If the last block is not eligible as an automatic cache breakpoint target, the system silently walks backward to find the nearest eligible block. If none is found, caching is skipped.
522527 
523528<Note>
524529 Automatic caching is available on every platform except the legacy [Amazon Bedrock (Opus 4.6 and earlier)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy) integration. On that integration, the API returns a 400 error for a top-level `cache_control` field, so use [explicit cache breakpoints](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints) instead.
from line 589
584589**Cache breakpoints themselves don't add any cost.** You are only charged for:
585590 
586591* **Cache writes:** When new content is written to the cache (25% more than base input tokens for 5-minute TTL)
587* **Cache reads:** When cached content is used (10% of base input token price, or 2.5% on Claude Fable 5.1 and Claude Mythos 5.1)
592* **Cache reads:** When cached content is used (10% of base input token price, or 2.5% on Claude Fable 5.1 and Claude Mythos 5.1, and 5% on Claude Opus 5.5)
588593* **Regular input tokens:** For any uncached content
589594 
590Adding more `cache_control` breakpoints doesn't increase your costs - you still pay the same amount based on what content is actually cached and read. The breakpoints give you control over what sections can be cached independently.
595Adding more `cache_control` breakpoints doesn't increase your costs; you still pay the same amount based on what content is actually cached and read. The breakpoints give you control over what sections can be cached independently.
591596 
592597***
593598 
from line 602
597602 
598603On the Claude API, [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws), [Google Cloud](https://platform.claude.com/docs/en/build-with-claude/claude-on-vertex-ai), and [Microsoft Foundry](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry), the minimum cacheable prompt length is:
599604 
600* 512 tokens for Claude Fable 5.1, Claude Mythos 5.1, Claude Opus 5, Claude Fable 5, and [Claude Mythos 5](https://anthropic.com/glasswing)
605* 512 tokens for Claude Fable 5.1, Claude Mythos 5.1, Claude Opus 5.5, Claude Opus 5, Claude Fable 5, and [Claude Mythos 5](https://anthropic.com/glasswing)
601606* 2,048 tokens for [Claude Mythos Preview](https://anthropic.com/glasswing) and Claude Opus 4.7
602607* 4,096 tokens for Claude Opus 4.6 and Claude Opus 4.5
603608* 1,024 tokens for Claude Opus 4.8, Claude Sonnet 5, Claude Sonnet 4.6, Claude Sonnet 4.5, Claude Opus 4.1 ([retired, except on Bedrock and Google Cloud](https://platform.claude.com/docs/en/about-claude/model-deprecations)), Claude Opus 4 ([retired, except on Google Cloud](https://platform.claude.com/docs/en/about-claude/model-deprecations)), and Claude Sonnet 4 ([retired, except on Bedrock and Google Cloud](https://platform.claude.com/docs/en/about-claude/model-deprecations))
from line 668
663668| **Non-tool results passed to extended thinking requests** | ✓ | ✓ | Model-specific | On Opus 4.5+ and Sonnet 4.6+, thinking blocks are preserved by default, so the cache remains valid (✓). On earlier Opus/Sonnet models and all Haiku models, all previously-cached thinking blocks are stripped from context, and any messages that follow those thinking blocks are removed from the cache (✘). For more details, see [Caching with thinking blocks](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#caching-with-thinking-blocks). |
664669| **Dropped thinking blocks** | ✓ | ✓ | ✘ | When the API drops a Claude Fable 5.1 or Claude Mythos 5.1 thinking block that isn't [preserved](https://platform.claude.com/docs/en/build-with-claude/thinking#preserved-thinking) on that request (for example, one you replay to an earlier model), the cached prefix changes from that block's position onward on that request. Blocks the receiving model can read, passed back unchanged, keep the cache intact. |
665670 
671On models that support [mid-conversation tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#mid-conversation-tool-changes), the `inline-tools-2026-09-15` beta header lets you add a tool, or change a tool's definition, partway through a conversation without editing `tools`. Send the definition in a `tool_addition` block in a mid-conversation system message and leave `tools` exactly as you first sent it. The cached prefix still matches, so only the appended message is processed as new input. The one exception is a `tools` array with no non-deferred tool, where the first tool defined this way costs one full cache miss on that request. See [Define tools in a message](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#define-tools-in-a-message-beta).
672 
666673<Note>
667 On Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, [Claude Mythos 5](https://anthropic.com/glasswing), Claude Opus 4.8, and Claude Opus 5, you can add a new system instruction partway through a conversation without invalidating the system or message caches. Append a `{"role": "system"}` message to `messages` instead of editing the top-level `system` field, so the cached prefix stays unchanged. This feature is not available on Claude Sonnet 5. Use the top-level `system` field instead. See [Mid-conversation system messages](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages).
674 On Claude Fable 5.1, Claude Mythos 5.1, Claude Fable 5, [Claude Mythos 5](https://anthropic.com/glasswing), Claude Opus 5.5, Claude Opus 4.8, and Claude Opus 5, you can add a new system instruction partway through a conversation without invalidating the system or message caches. Append a `{"role": "system"}` message to `messages` instead of editing the top-level `system` field, so the cached prefix stays unchanged. This feature is not available on Claude Sonnet 5. Use the top-level `system` field instead. See [Mid-conversation system messages](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages).
668675</Note>
669676 
670677### Tracking cache performance
from line 685
678685<Note>
679686 **Understanding the token breakdown**
680687 
681 The `input_tokens` field represents only the tokens that come **after the last cache breakpoint** in your request - not all the input tokens you sent.
688 The `input_tokens` field represents only the tokens that come **after the last cache breakpoint** in your request, not all the input tokens you sent.
682689 
683690 To calculate total input tokens:
684691 
from line 782
775782Tailor your prompt caching strategy to your scenario:
776783 
777784* Conversational agents: Reduce cost and latency for extended conversations, especially those with long instructions or uploaded documents.
778* Coding assistants: Improve autocomplete and codebase Q\&A by keeping relevant sections or a summarized version of the codebase in the prompt.
785* Coding assistants: Improve autocomplete and code base Q\&A by keeping relevant sections or a summarized version of the code base in the prompt.
779786* Large document processing: Incorporate complete long-form material including images in your prompt without increasing response latency.
780787* Detailed instruction sets: Share extensive lists of instructions, procedures, and examples to fine-tune Claude's responses. Developers often include an example or two in the prompt, but with prompt caching you can get even better performance by including 20+ diverse examples of high quality answers.
781788* Agentic tool use: Enhance performance for scenarios involving multiple tool calls and iterative code changes, where each step typically requires a new API call.
from line 856
849856The 1-hour cache is best used in the following scenarios:
850857 
851858* When you have prompts that are likely used less frequently than 5 minutes, but more frequently than every hour. For example, when an agentic side-agent will take longer than 5 minutes, or when storing a long chat conversation with a user and you generally expect that user may not respond in the next 5 minutes.
852* When latency is important and your follow up prompts may be sent beyond 5 minutes.
859* When latency is important and your follow-up prompts may be sent beyond 5 minutes.
853860* When you want to improve your rate limit utilization, because cache hits are not deducted against your rate limit.
854861 
855862<Note>
from line 908
901908 -H "x-api-key: $ANTHROPIC_API_KEY" \
902909 -H "anthropic-version: 2023-06-01" \
903910 -d '{
904 "model": "claude-opus-5",
911 "model": "claude-opus-5-5",
905912 "max_tokens": 0,
906913 "system": [
907914 {
from line 924
917924 ```bash CLI
918925 ant messages create \
919926 --transform '{stop_reason,content,usage}' --format yaml <<'YAML'
920 model: claude-opus-5
927 model: claude-opus-5-5
921928 max_tokens: 0
922929 system:
923930 - type: text
from line 944
937944 
938945 # Fire this before users arrive to warm the shared system-prompt cache.
939946 prewarm = client.messages.create(
940 model="claude-opus-5",
947 model="claude-opus-5-5",
941948 max_tokens=0,
942949 system=[
943950 {
from line 965
958965 
959966 // Fire this before users arrive to warm the shared system-prompt cache.
960967 const prewarm = await client.messages.create({
961 model: "claude-opus-5",
968 model: "claude-opus-5-5",
962969 max_tokens: 0,
963970 system: [
964971 {
from line 987
980987 var prewarm = await client.Messages.Create(
981988 new()
982989 {
983 Model = Model.ClaudeOpus5,
990 Model = Model.ClaudeOpus5_5,
984991 MaxTokens = 0,
985992 System = new(
986993 [
from line 1011
10041011 client := anthropic.NewClient()
10051012 
10061013 prewarm, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1007 Model: anthropic.ModelClaudeOpus5,
1014 Model: anthropic.ModelClaudeOpus5_5,
10081015 MaxTokens: 0,
10091016 System: []anthropic.TextBlockParam{
10101017 {
from line 1036
10291036 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
10301037 
10311038 Message prewarm = client.messages().create(MessageCreateParams.builder()
1032 .model(Model.CLAUDE_OPUS_5)
1039 .model(Model.CLAUDE_OPUS_5_5)
10331040 .maxTokens(0)
10341041 .systemOfTextBlockParams(List.of(TextBlockParam.builder()
10351042 .text("You are an expert software engineer with deep knowledge of distributed systems...")
from line 1054
10471054 $client = new Client();
10481055 
10491056 $prewarm = $client->messages->create(
1050 model: Model::CLAUDE_OPUS_5,
1057 model: Model::CLAUDE_OPUS_5_5,
10511058 maxTokens: 0,
10521059 system: [
10531060 [
from line 1075
10681075 client = Anthropic::Client.new
10691076 
10701077 prewarm = client.messages.create(
1071 model: Anthropic::Model::CLAUDE_OPUS_5,
1078 model: Anthropic::Model::CLAUDE_OPUS_5_5,
10721079 max_tokens: 0,
10731080 system_: [
10741081 {
from line 1101
10941101 "type": "message",
10951102 "role": "assistant",
10961103 "content": [],
1097 "model": "claude-opus-5",
1104 "model": "claude-opus-5-5",
10981105 "stop_reason": "max_tokens",
10991106 "stop_sequence": null,
11001107 "usage": {
from line 1144
11371144 -H "x-api-key: $ANTHROPIC_API_KEY" \
11381145 -H "anthropic-version: 2023-06-01" \
11391146 -d '{
1140 "model": "claude-opus-5",
1147 "model": "claude-opus-5-5",
11411148 "max_tokens": 0,
11421149 "system": [
11431150 {
from line 1162
11551162 -H "x-api-key: $ANTHROPIC_API_KEY" \
11561163 -H "anthropic-version: 2023-06-01" \
11571164 -d '{
1158 "model": "claude-opus-5",
1165 "model": "claude-opus-5-5",
11591166 "max_tokens": 1024,
11601167 "system": [
11611168 {
from line 1178
11711178 ```bash CLI
11721179 # Warm the cache at application startup or on a scheduled interval.
11731180 ant messages create --transform usage <<'YAML'
1174 model: claude-opus-5
1181 model: claude-opus-5-5
11751182 max_tokens: 0
11761183 system:
11771184 - type: text
from line 1194
11871194 
11881195 # Later, when the user submits a message, the system-prompt prefix is already cached.
11891196 ant messages create --transform 'content.#(type=="text").text' --raw-output <<'YAML'
1190 model: claude-opus-5
1197 model: claude-opus-5-5
11911198 max_tokens: 1024
11921199 system:
11931200 - type: text
from line 1224
12171224 def prewarm_cache() -> None:
12181225 """Call this at application startup or on a scheduled interval."""
12191226 client.messages.create(
1220 model="claude-opus-5",
1227 model="claude-opus-5-5",
12211228 max_tokens=0,
12221229 system=SYSTEM_PROMPT,
12231230 messages=[{"role": "user", "content": "warmup"}],
from line 1234
12271234 def respond(user_message: str) -> anthropic.types.Message:
12281235 """The real user request; benefits from a warm cache."""
12291236 return client.messages.create(
1230 model="claude-opus-5",
1237 model="claude-opus-5-5",
12311238 max_tokens=1024,
12321239 system=SYSTEM_PROMPT,
12331240 messages=[{"role": "user", "content": user_message}],
from line 1265
12581265 // Call this at application startup or on a scheduled interval.
12591266 async function prewarmCache(): Promise<void> {
12601267 await client.messages.create({
1261 model: "claude-opus-5",
1268 model: "claude-opus-5-5",
12621269 max_tokens: 0,
12631270 system: SYSTEM_PROMPT,
12641271 messages: [{ role: "user", content: "warmup" }]
from line 1275
12681275 // The real user request; benefits from a warm cache.
12691276 async function respond(userMessage: string): Promise<Anthropic.Message> {
12701277 return client.messages.create({
1271 model: "claude-opus-5",
1278 model: "claude-opus-5-5",
12721279 max_tokens: 1024,
12731280 system: SYSTEM_PROMPT,
12741281 messages: [{ role: "user", content: userMessage }]
from line 1310
13031310 await client.Messages.Create(
13041311 new()
13051312 {
1306 Model = Model.ClaudeOpus5,
1313 Model = Model.ClaudeOpus5_5,
13071314 MaxTokens = 0,
13081315 System = new(systemPrompt),
13091316 Messages = [new() { Role = Role.User, Content = "warmup" }],
from line 1322
13151322 await client.Messages.Create(
13161323 new()
13171324 {
1318 Model = Model.ClaudeOpus5,
1325 Model = Model.ClaudeOpus5_5,
13191326 MaxTokens = 1024,
13201327 System = new(systemPrompt),
13211328 Messages = [new() { Role = Role.User, Content = userMessage }],
from line 1356
13491356 // Call this at application startup or on a scheduled interval.
13501357 func prewarmCache() error {
13511358 _, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1352 Model: anthropic.ModelClaudeOpus5,
1359 Model: anthropic.ModelClaudeOpus5_5,
13531360 MaxTokens: 0,
13541361 System: systemPrompt,
13551362 Messages: []anthropic.MessageParam{
from line 1369
13621369 // The real user request; benefits from a warm cache.
13631370 func respond(userMessage string) (*anthropic.Message, error) {
13641371 return client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1365 Model: anthropic.ModelClaudeOpus5,
1372 Model: anthropic.ModelClaudeOpus5_5,
13661373 MaxTokens: 1024,
13671374 System: systemPrompt,
13681375 Messages: []anthropic.MessageParam{
from line 1408
14011408 // Call this at application startup or on a scheduled interval.
14021409 void prewarmCache() {
14031410 client.messages().create(MessageCreateParams.builder()
1404 .model(Model.CLAUDE_OPUS_5)
1411 .model(Model.CLAUDE_OPUS_5_5)
14051412 .maxTokens(0)
14061413 .systemOfTextBlockParams(systemPrompt)
14071414 .addUserMessage("warmup")
from line 1418
14111418 // The real user request; benefits from a warm cache.
14121419 Message respond(String userMessage) {
14131420 return client.messages().create(MessageCreateParams.builder()
1414 .model(Model.CLAUDE_OPUS_5)
1421 .model(Model.CLAUDE_OPUS_5_5)
14151422 .maxTokens(1024)
14161423 .systemOfTextBlockParams(systemPrompt)
14171424 .addUserMessage(userMessage)
from line 1450
14431450 
14441451 // Call this at application startup or on a scheduled interval.
14451452 $prewarmCache = fn () => $client->messages->create(
1446 model: Model::CLAUDE_OPUS_5,
1453 model: Model::CLAUDE_OPUS_5_5,
14471454 maxTokens: 0,
14481455 system: $systemPrompt,
14491456 messages: [['role' => 'user', 'content' => 'warmup']],
from line 1458
14511458 
14521459 // The real user request; benefits from a warm cache.
14531460 $respond = fn (string $userMessage) => $client->messages->create(
1454 model: Model::CLAUDE_OPUS_5,
1461 model: Model::CLAUDE_OPUS_5_5,
14551462 maxTokens: 1024,
14561463 system: $systemPrompt,
14571464 messages: [['role' => 'user', 'content' => $userMessage]],
from line 1490
14831490 # Call this at application startup or on a scheduled interval.
14841491 def prewarm_cache(client)
14851492 client.messages.create(
1486 model: Anthropic::Model::CLAUDE_OPUS_5,
1493 model: Anthropic::Model::CLAUDE_OPUS_5_5,
14871494 max_tokens: 0,
14881495 system_: SYSTEM_PROMPT,
14891496 messages: [{role: "user", content: "warmup"}]
from line 1500
14931500 # The real user request; benefits from a warm cache.
14941501 def respond(client, user_message)
14951502 client.messages.create(
1496 model: Anthropic::Model::CLAUDE_OPUS_5,
1503 model: Anthropic::Model::CLAUDE_OPUS_5_5,
14971504 max_tokens: 1024,
14981505 system_: SYSTEM_PROMPT,
14991506 messages: [{role: "user", content: user_message}]
from line 1552
15451552 -H "anthropic-version: 2023-06-01" \
15461553 -H "content-type: application/json" \
15471554 -d '{
1548 "model": "claude-opus-5",
1555 "model": "claude-opus-5-5",
15491556 "max_tokens": 1024,
15501557 "system": [
15511558 {
from line 1576
15691576 
15701577 ```bash CLI
15711578 ant messages create --transform usage <<'YAML'
1572 model: claude-opus-5
1579 model: claude-opus-5-5
15731580 max_tokens: 1024
15741581 system:
15751582 - type: text
from line 1597
15901597 client = anthropic.Anthropic()
15911598 
15921599 response = client.messages.create(
1593 model="claude-opus-5",
1600 model="claude-opus-5-5",
15941601 max_tokens=1024,
15951602 system=[
15961603 {
from line 1624
16171624 const client = new Anthropic();
16181625 
16191626 const response = await client.messages.create({
1620 model: "claude-opus-5",
1627 model: "claude-opus-5-5",
16211628 max_tokens: 1024,
16221629 system: [
16231630 {
from line 1655
16481655 
16491656 var parameters = new MessageCreateParams
16501657 {
1651 Model = Model.ClaudeOpus5,
1658 Model = Model.ClaudeOpus5_5,
16521659 MaxTokens = 1024,
16531660 System = new MessageCreateParamsSystem(new List<TextBlockParam>
16541661 {
from line 1687
16801687 client := anthropic.NewClient()
16811688 
16821689 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1683 Model: anthropic.ModelClaudeOpus5,
1690 Model: anthropic.ModelClaudeOpus5_5,
16841691 MaxTokens: 1024,
16851692 System: []anthropic.TextBlockParam{
16861693 {
from line 1717
17101717 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
17111718 
17121719 MessageCreateParams params = MessageCreateParams.builder()
1713 .model(Model.CLAUDE_OPUS_5)
1720 .model(Model.CLAUDE_OPUS_5_5)
17141721 .maxTokens(1024)
17151722 .systemOfTextBlockParams(
17161723 List.of(
from line 1752
17451752 'content' => 'What are the key terms and conditions in this agreement?'
17461753 ]
17471754 ],
1748 model: 'claude-opus-5',
1755 model: 'claude-opus-5-5',
17491756 system: [
17501757 [
17511758 'type' => 'text',
from line 1773
17661773 client = Anthropic::Client.new
17671774 
17681775 message = client.messages.create(
1769 model: "claude-opus-5",
1776 model: "claude-opus-5-5",
17701777 max_tokens: 1024,
17711778 system: [
17721779 {
from line 1817
18101817 
18111818 ```json
18121819 {
1813 "model": "claude-opus-5",
1820 "model": "claude-opus-5-5",
18141821 "max_tokens": 1024,
18151822 "tools": [
18161823 {
from line 1857
18501857 -H "anthropic-version: 2023-06-01" \
18511858 -H "content-type: application/json" \
18521859 -d '{
1853 "model": "claude-opus-5",
1860 "model": "claude-opus-5-5",
18541861 "max_tokens": 1024,
18551862 "system": [
18561863 {
from line 1900
18931900 
18941901 ```bash CLI
18951902 ant messages create --transform usage <<'YAML'
1896 model: claude-opus-5
1903 model: claude-opus-5-5
18971904 max_tokens: 1024
18981905 system:
18991906 - type: text
from line 1936
19291936 client = anthropic.Anthropic()
19301937 
19311938 response = client.messages.create(
1932 model="claude-opus-5",
1939 model="claude-opus-5-5",
19331940 max_tokens=1024,
19341941 system=[
19351942 {
from line 1980
19731980 const client = new Anthropic();
19741981 
19751982 const response = await client.messages.create({
1976 model: "claude-opus-5",
1983 model: "claude-opus-5-5",
19771984 max_tokens: 1024,
19781985 system: [
19791986 {
from line 2029
20222029 
20232030 var parameters = new MessageCreateParams
20242031 {
2025 Model = Model.ClaudeOpus5,
2032 Model = Model.ClaudeOpus5_5,
20262033 MaxTokens = 1024,
20272034 System = new MessageCreateParamsSystem(new List<TextBlockParam>
20282035 {
from line 2078
20712078 client := anthropic.NewClient()
20722079 
20732080 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
2074 Model: anthropic.ModelClaudeOpus5,
2081 Model: anthropic.ModelClaudeOpus5_5,
20752082 MaxTokens: 1024,
20762083 System: []anthropic.TextBlockParam{
20772084 {
from line 2123
21162123 
21172124 // Create message params
21182125 MessageCreateParams params = MessageCreateParams.builder()
2119 .model(Model.CLAUDE_OPUS_5)
2126 .model(Model.CLAUDE_OPUS_5_5)
21202127 .maxTokens(1024)
21212128 .systemOfTextBlockParams(List.of(systemPrompt))
21222129 // First user message (without cache control)
from line 2183
21762183 ]
21772184 ]
21782185 ],
2179 model: 'claude-opus-5',
2186 model: 'claude-opus-5-5',
21802187 system: [
21812188 [
21822189 'type' => 'text',
from line 2200
21932200 client = Anthropic::Client.new
21942201 
21952202 message = client.messages.create(
2196 model: "claude-opus-5",
2203 model: "claude-opus-5-5",
21972204 max_tokens: 1024,
21982205 system: [
21992206 {
from line 2263
22562263 -H "anthropic-version: 2023-06-01" \
22572264 -H "content-type: application/json" \
22582265 -d '{
2259 "model": "claude-opus-5",
2266 "model": "claude-opus-5-5",
22602267 "max_tokens": 1024,
22612268 "tools": [
22622269 {
from line 2359
23522359 
23532360 ```bash CLI
23542361 ant messages create --transform usage <<'YAML'
2355 model: claude-opus-5
2362 model: claude-opus-5-5
23562363 max_tokens: 1024
23572364 tools:
23582365 - name: search_documents
from line 2449
24422449 client = anthropic.Anthropic()
24432450 
24442451 response = client.messages.create(
2445 model="claude-opus-5",
2452 model="claude-opus-5-5",
24462453 max_tokens=1024,
24472454 tools=[
24482455 {
from line 2542
25352542 const client = new Anthropic();
25362543 
25372544 const response = await client.messages.create({
2538 model: "claude-opus-5",
2545 model: "claude-opus-5-5",
25392546 max_tokens: 1024,
25402547 tools: [
25412548 {
from line 2646
26392646 
26402647 var parameters = new MessageCreateParams
26412648 {
2642 Model = Model.ClaudeOpus5,
2649 Model = Model.ClaudeOpus5_5,
26432650 MaxTokens = 1024,
26442651 Tools =
26452652 [
from line 2750
27432750 client := anthropic.NewClient()
27442751 
27452752 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
2746 Model: anthropic.ModelClaudeOpus5,
2753 Model: anthropic.ModelClaudeOpus5_5,
27472754 MaxTokens: 1024,
27482755 Tools: []anthropic.ToolUnionParam{
27492756 {OfTool: &anthropic.ToolParam{
from line 2850
28432850 .build();
28442851 
28452852 MessageCreateParams params = MessageCreateParams.builder()
2846 .model(Model.CLAUDE_OPUS_5)
2853 .model(Model.CLAUDE_OPUS_5_5)
28472854 .maxTokens(1024)
28482855 // Tools with cache control on the last one
28492856 .addTool(
from line 2990
29832990 ]
29842991 ]
29852992 ],
2986 model: 'claude-opus-5',
2993 model: 'claude-opus-5-5',
29872994 system: [
29882995 [
29892996 'type' => 'text',
from line 3043
30363043 client = Anthropic::Client.new
30373044 
30383045 message = client.messages.create(
3039 model: "claude-opus-5",
3046 model: "claude-opus-5-5",
30403047 max_tokens: 1024,
30413048 tools: [
30423049 {
from line 3209
32023209 * Reading from cache (a fraction of the base input token price, see [Pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing))
32033210 * Regular input tokens for uncached content
32043211 
3205 The number of breakpoints doesn't affect pricing - only the amount of content cached and read matters.
3212 The number of breakpoints doesn't affect pricing; only the amount of content cached and read matters.
32063213 </Accordion>
32073214 
32083215 <Accordion title="How do I calculate total input tokens from the usage fields?">
from line 3223
32163223 * `cache_creation_input_tokens`: New tokens being written to cache (at cache breakpoints)
32173224 * `input_tokens`: Tokens **after the last cache breakpoint** that aren't cached
32183225 
3219 **Important:** `input_tokens` does NOT represent all input tokens - only the portion after your last cache breakpoint. If you have cached content, `input_tokens` will typically be much smaller than your total input.
3226 **Important:** `input_tokens` does NOT represent all input tokens, only the portion after your last cache breakpoint. If you have cached content, `input_tokens` will typically be much smaller than your total input.
32203227 
32213228 **Example:** With a 200k token document cached and a 50 token user question:
32223229 
from line 3340
33333340 client.beta.promptCaching.messages.create(/* ... */);
33343341 ```
33353342 
3336 Simply use:
3343 Use:
33373344 
33383345 ```typescript
33393346 client.messages.create(/* ... */);