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 1
11---
2title: Migrating to Claude Sonnet 5
3url: https://platform.claude.com/docs/en/models/sonnet-5/migration-guide
4description: "Migrate to Claude Sonnet 5 from earlier Claude models: model IDs, breaking changes, and migration checklists."
2title: Migrating to Claude Sonnet 5.5
3url: https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide
4description: "Move code to Claude Sonnet 5.5 from Claude Sonnet 5, Claude Sonnet 4.6, Claude Sonnet 4.5, Claude Sonnet 4, Claude 3.7 Sonnet, or Claude Haiku 4.5: settings that return errors, thinking changes, and a checklist for each starting model."
55---
6
7This guide lists the code changes for moving to Claude Sonnet 5.5 from Claude Sonnet 5, Claude Sonnet 4.6, Claude Sonnet 4.5, Claude Sonnet 4, Claude 3.7 Sonnet, or Claude Haiku 4.5. Read the first two sections, then read down to the section for your current model. The [migration checklist](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#migration-checklist) lists every change by starting model.
68
79<Note>
810 This guide covers migrating [Messages API](https://platform.claude.com/docs/en/build-with-claude/working-with-messages) code. If you use [Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview), no changes beyond updating the model name are required.
from line 14
1214 **Automate your migration with the Claude API skill.** In Claude Code, run `/claude-api migrate` to invoke the bundled [Claude API skill](https://platform.claude.com/docs/en/agents-and-tools/agent-skills/claude-api-skill#migrating-to-a-newer-claude-model). It works for any current Claude model as the target:
1315
1416 ```text wrap
15 /claude-api migrate this project to claude-sonnet-5
17 /claude-api migrate this project to claude-sonnet-5-5
1618 ```
1719
1820 The skill applies the model ID swap and, as needed, breaking parameter changes, prefill replacement, and effort calibration for your target model across your code base, then produces a checklist of items to verify manually. It asks you to confirm the migration scope (entire working directory, a subdirectory, or a specific file list) before editing any files. The skill also detects Amazon Bedrock and Claude Platform on AWS clients and adjusts model ID formats and feature changes for those platforms.
1921</Tip>
2022
21Claude Sonnet 5 offers the best combination of speed and intelligence in the Claude model family. It builds on Claude Sonnet 4.6.
22
23Claude Sonnet 5 is a drop-in upgrade for Claude Sonnet 4.6, priced at $2/$10 USD per million input/output tokens; see [Pricing](https://platform.claude.com/docs/en/about-claude/pricing) for details. There are two breaking API changes for code already running on Claude Sonnet 4.6. First, [adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking) is on by default and manual extended thinking (`thinking: {type: "enabled", budget_tokens: N}`) returns a 400 error, so requests that ran without thinking can now return `thinking` blocks before the first `text` block and code that reads content by position must select content blocks by `type`. Second, sampling parameters (`temperature`, `top_p`, `top_k`) set to non-default values return a 400 error. Use adaptive thinking with the [effort parameter](https://platform.claude.com/docs/en/build-with-claude/effort) to control thinking depth. Claude Sonnet 5 supports the same set of features as Claude Sonnet 4.6, including the [1M token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows), [adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking), [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching), [batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing), the [Files API](https://platform.claude.com/docs/en/build-with-claude/files), [PDF support](https://platform.claude.com/docs/en/build-with-claude/pdf-support), [vision](https://platform.claude.com/docs/en/build-with-claude/vision), and the full set of server-side and client-side [tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). On the Claude API and Google Cloud, Claude Sonnet 5 also supports [computer use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool) as the stable `computer_toolset_20260801` toolset and the [browser use tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/browser-use-tool) for tasks inside webpages, neither of which Claude Sonnet 4.6 supports; existing integrations on the earlier `computer_20251124` version continue to work unchanged on both models. To upgrade an existing integration, see [Migrate from `computer_20251124`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool#migrate-from-computer-20251124). [Priority Tier](https://platform.claude.com/docs/en/api/service-tiers#supported-models) is not available on Claude Sonnet 5. Claude Sonnet 5 also uses a new tokenizer.
24
25## Migrating to Claude Sonnet 5 from Claude Sonnet 4.6
26
27<Note>
28 If your code is on Claude Sonnet 4.5 or earlier, also apply [Migrating to Claude Sonnet 5 from Claude Sonnet 4.5 and earlier Sonnet models](https://platform.claude.com/docs/en/models/sonnet-5/migration-guide#migrating-from-sonnet-45). Those steps include breaking changes (assistant message prefilling rejected, tool parameter JSON escaping differences) that this section alone does not cover.
29</Note>
30
31### Update your model name
32
33```python
34# Sonnet migration
35model = "claude-sonnet-4-6" # Before
36model = "claude-sonnet-5" # After
23Claude Sonnet 5.5 has the same prices as Claude Sonnet 5. See [Claude pricing](https://platform.claude.com/docs/en/about-claude/pricing). For its context window and output limits, see the [Claude Sonnet 5.5 model page](https://platform.claude.com/docs/en/models/sonnet-5-5/overview). For features and prompting, see [What's new in Claude Sonnet 5.5](https://platform.claude.com/docs/en/models/sonnet-5-5/whats-new-sonnet-5-5#feature-support) and [Prompting Claude Sonnet 5.5](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5).
24
25## Send a request to Claude Sonnet 5.5
26
27This request works on Claude Sonnet 5.5 as written. It sets an effort level, and the SDK tabs read the reply by block type. It leaves out five settings that return a 400 error: [thinking budgets](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#sonnet-46-breaking-changes), [sampling parameters](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#sonnet-46-breaking-changes), [assistant prefill](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#migrating-from-sonnet-45), [forced tool choice](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#forced-tool-use), and [`thinking: {"type": "disabled"}`](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#turn-off-up-front-thinking).
28
29<CodeGroup>
30 ```bash cURL
31 curl https://api.anthropic.com/v1/messages \
32 -H "x-api-key: $ANTHROPIC_API_KEY" \
33 -H "anthropic-version: 2023-06-01" \
34 -H "content-type: application/json" \
35 -d '{
36 "model": "claude-sonnet-5-5",
37 "max_tokens": 4096,
38 "messages": [{
39 "role": "user",
40 "content": "Analyze the trade-offs between microservices and monolithic architectures"
41 }],
42 "output_config": {
43 "effort": "medium"
44 }
45 }'
46 ```
47
48 ```bash CLI
49 ant messages create \
50 --model claude-sonnet-5-5 \
51 --max-tokens 4096 \
52 --output-config '{effort: medium}' \
53 --message '{role: user, content: "Analyze the trade-offs between microservices and monolithic architectures"}'
54 ```
55
56 ```python Python
57 client = anthropic.Anthropic()
58
59 response = client.messages.create(
60 model="claude-sonnet-5-5",
61 max_tokens=4096,
62 messages=[
63 {
64 "role": "user",
65 "content": "Analyze the trade-offs between microservices and monolithic architectures",
66 }
67 ],
68 output_config={"effort": "medium"},
69 )
70
71 print(f"Stop reason: {response.stop_reason}")
72 for block in response.content:
73 if block.type == "text":
74 print(block.text)
75 ```
76
77 ```typescript TypeScript
78 const client = new Anthropic();
79
80 const response = await client.messages.create({
81 model: "claude-sonnet-5-5",
82 max_tokens: 4096,
83 messages: [
84 {
85 role: "user",
86 content: "Analyze the trade-offs between microservices and monolithic architectures"
87 }
88 ],
89 output_config: {
90 effort: "medium"
91 }
92 });
93
94 console.log(`Stop reason: ${response.stop_reason}`);
95 const textBlock = response.content.find(
96 (block): block is Anthropic.TextBlock => block.type === "text"
97 );
98 console.log(textBlock?.text);
99 ```
100
101 ```csharp C#
102 AnthropicClient client = new();
103
104 var parameters = new MessageCreateParams
105 {
106 Model = Model.ClaudeSonnet5_5,
107 MaxTokens = 4096,
108 Messages = [
109 new() {
110 Role = Role.User,
111 Content = "Analyze the trade-offs between microservices and monolithic architectures"
112 }
113 ],
114 OutputConfig = new OutputConfig
115 {
116 Effort = Effort.Medium
117 }
118 };
119
120 var message = await client.Messages.Create(parameters);
121 Console.WriteLine($"Stop reason: {message.StopReason?.Raw()}");
122 foreach (var block in message.Content)
123 {
124 if (block.TryPickText(out var textBlock))
125 {
126 Console.WriteLine(textBlock.Text);
127 }
128 }
129 ```
130
131 ```go Go
132 client := anthropic.NewClient()
133
134 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
135 Model: anthropic.ModelClaudeSonnet5_5,
136 MaxTokens: 4096,
137 Messages: []anthropic.MessageParam{
138 anthropic.NewUserMessage(anthropic.NewTextBlock("Analyze the trade-offs between microservices and monolithic architectures")),
139 },
140 OutputConfig: anthropic.OutputConfigParam{
141 Effort: anthropic.OutputConfigEffortMedium,
142 },
143 })
144 if err != nil {
145 log.Fatal(err)
146 }
147 fmt.Println("Stop reason:", response.StopReason)
148 for _, block := range response.Content {
149 if textBlock, ok := block.AsAny().(anthropic.TextBlock); ok {
150 fmt.Println(textBlock.Text)
151 }
152 }
153 ```
154
155 ```java Java
156 import com.anthropic.models.messages.OutputConfig;
157
158 void main() {
159 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
160
161 MessageCreateParams params = MessageCreateParams.builder()
162 .model(Model.CLAUDE_SONNET_5_5)
163 .maxTokens(4096L)
164 .addUserMessage("Analyze the trade-offs between microservices and monolithic architectures")
165 .outputConfig(OutputConfig.builder()
166 .effort(OutputConfig.Effort.MEDIUM)
167 .build())
168 .build();
169
170 Message response = client.messages().create(params);
171 response.stopReason().ifPresent(reason -> IO.println("Stop reason: " + reason));
172 response.content().stream()
173 .flatMap(block -> block.text().stream())
174 .forEach(textBlock -> IO.println(textBlock.text()));
175 }
176 ```
177
178 ```php PHP
179 $client = new Client();
180
181 $message = $client->messages->create(
182 maxTokens: 4096,
183 messages: [
184 ['role' => 'user', 'content' => 'Analyze the trade-offs between microservices and monolithic architectures']
185 ],
186 model: 'claude-sonnet-5-5',
187 outputConfig: ['effort' => 'medium'],
188 );
189
190 echo "Stop reason: {$message->stopReason}", PHP_EOL;
191 foreach ($message->content as $block) {
192 if ($block->type === 'text') {
193 echo $block->text, PHP_EOL;
194 }
195 }
196 ```
197
198 ```ruby Ruby
199 client = Anthropic::Client.new
200
201 message = client.messages.create(
202 model: "claude-sonnet-5-5",
203 max_tokens: 4096,
204 messages: [
205 { role: "user", content: "Analyze the trade-offs between microservices and monolithic architectures" }
206 ],
207 output_config: {
208 effort: "medium"
209 }
210 )
211
212 puts "Stop reason: #{message.stop_reason}"
213 message.content.each do |block|
214 puts block.text if block.type == :text
215 end
216 ```
217</CodeGroup>
218
219## Thinking runs by default
220
221On Claude Sonnet 5.5, a request with no `thinking` field runs with [adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking), as does `thinking: {"type": "adaptive"}`. On Claude Sonnet 4.6 and earlier models and on Claude Haiku 4.5, that request ran without thinking. To keep running without up-front thinking, see [Turn off up-front thinking](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#turn-off-up-front-thinking).
222
223| Model | Thinking without a `thinking` field | `thinking.type` values accepted | Default `display` |
224| -------------------------------------- | ----------------------------------- | ---------------------------------------------------- | ----------------- |
225| Claude Sonnet 5.5 | On | `"adaptive"`, `"between_tools"` | `"omitted"` |
226| Claude Sonnet 5 | On | `"adaptive"`, `"disabled"` | `"omitted"` |
227| Claude Sonnet 4.6 | Off | `"adaptive"`, `"disabled"`, `"enabled"` (deprecated) | `"summarized"` |
228| Claude Sonnet 4.5 and Claude Haiku 4.5 | Off | `"disabled"`, `"enabled"` | `"summarized"` |
229
230### Handle thinking in responses
231
232Code that ran without thinking needs all three items. Code from Claude Sonnet 5 likely has the first two.
233
234* **Read content blocks by `type`.** A response can begin with `thinking` blocks, so code that reads `content[0].text` breaks.
235* **Pass `thinking` blocks back unchanged** in tool-use loops, including empty ones. See [Preserving thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#preserving-thinking-blocks).
236* **Revisit `max_tokens`.** It covers thinking plus text, and thinking tokens are billed as output tokens. See [Cost control](https://platform.claude.com/docs/en/build-with-claude/thinking-steering-and-cost#cost-control).
237
238Thinking text is omitted by default. `thinking` blocks arrive with an empty `thinking` field and a `signature`. To get readable summaries, set `display: "summarized"`, the default on Claude Sonnet 4.6 and earlier models and on Claude Haiku 4.5. See [Controlling thinking display](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display).
239
240### Turn off up-front thinking
241
242To turn off up-front thinking on Claude Sonnet 5.5, send `thinking: {"type": "between_tools"}`. It's the lowest thinking setting. Its progress updates between tool calls still come back as `thinking` blocks with their summary text. Without tools, the response contains only text. Claude Sonnet 5 turns thinking off with `thinking: {"type": "disabled"}` instead, and earlier models run without thinking by default. On Claude Sonnet 5.5, `disabled` returns a 400 `invalid_request_error`:
243
244```text wrap
245"thinking.type.disabled" is not supported for this model. Use "thinking.type.between_tools" for the lowest thinking setting, or "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.
37246```
38247
39### What changed
40
41Items 4 and 5 in the following list are breaking changes. `max_tokens` remains a hard limit on total output (thinking plus response text), so revisit it for workloads that ran without thinking on Claude Sonnet 4.6.
42
431. **New tokenizer:** Claude Sonnet 5 uses a new tokenizer. The same input text produces approximately 30% more tokens than on Claude Sonnet 4.6. The exact increase depends on the content. Requests, responses, and streaming events keep the same shape, and no code changes are required, but anything you measure or budget in tokens shifts: `usage` fields and [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) results for the same text are higher, the 1M token context window holds less text, and a `max_tokens` limit tuned for Claude Sonnet 4.6 may truncate equivalent output. Per-token pricing is lower ($2/$10 USD versus Claude Sonnet 4.6's $3/$15 USD per million input/output tokens), but the cost of an equivalent request does not drop in direct proportion. Re-run token counting against Claude Sonnet 5 rather than reusing counts measured against earlier models.
44
452. **128k max output tokens (unchanged):** Claude Sonnet 5 supports up to 128k output tokens, the same as Claude Sonnet 4.6. Existing `max_tokens` values remain valid. Account for the new tokenizer when sizing them.
46
473. **Assistant message prefilling (unchanged):** Prefilling the assistant message returns a `400` error on Claude Sonnet 5, the same as on Claude Sonnet 4.6. If you removed prefill when migrating to Claude Sonnet 4.6, no further changes are needed. Use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs), system prompt instructions, or `output_config.format` instead.
48
494. **Adaptive thinking on by default:** On Claude Sonnet 4.6, requests without a `thinking` field run without thinking; on Claude Sonnet 5, the same requests run with [adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking). To turn thinking off, pass `thinking: {type: "disabled"}`. Manual extended thinking (`thinking: {type: "enabled", budget_tokens: N}`) is not supported and returns a 400 error. Use the [effort parameter](https://platform.claude.com/docs/en/build-with-claude/effort) (default `high`) to control thinking depth.
50
51 With thinking on, a response can begin with one or more `thinking` blocks before the first `text` block, returned with an empty `thinking` field at the default `display: "omitted"`. Code that reads the reply by position, such as `content[0].text` or a stream handler that treats the first content block as text, must select content blocks by their `type` field instead, and tool-use loops must pass `thinking` blocks back complete and unmodified with their tool results (see [Preserving thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#preserving-thinking-blocks)). Thinking tokens are billed as output tokens even when the thinking text is not returned. If you used thinking on Claude Sonnet 4.6 and display the returned thinking text, note that `thinking.display` defaulted to `"summarized"` there and defaults to `"omitted"` on Claude Sonnet 5; set `display: "summarized"`, as the following example does, to keep receiving readable summaries (see [Controlling thinking display](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display)).
52
53 <Tabs>
54 <Tab title="Claude Sonnet 5">
55 <Note>
56 Adaptive thinking is on by default for Claude Sonnet 5. The `thinking` field is shown explicitly here to set `display: "summarized"`; if you omit `thinking`, Claude Sonnet 5 omits thinking content from the response by default. For per-model defaults, see [Configurations each model rejects](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#rejected-configurations).
57 </Note>
58
59 <CodeGroup>
60 ```bash cURL
61 curl https://api.anthropic.com/v1/messages \
62 -H "x-api-key: $ANTHROPIC_API_KEY" \
63 -H "anthropic-version: 2023-06-01" \
64 -H "content-type: application/json" \
65 -d '{
66 "model": "claude-sonnet-5",
67 "max_tokens": 16000,
68 "thinking": {
69 "type": "adaptive",
70 "display": "summarized"
71 },
72 "output_config": {
73 "effort": "high"
74 },
75 "messages": [
76 {
77 "role": "user",
78 "content": "Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024."
79 }
80 ]
81 }'
82 ```
83
84 ```bash CLI
85 ant messages create --transform content --format yaml <<'YAML'
86 model: claude-sonnet-5
87 max_tokens: 16000
88 thinking:
89 type: adaptive
90 display: summarized
91 output_config:
92 effort: high
93 messages:
94 - role: user
95 content: Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024.
96 YAML
97 ```
98
99 ```python Python
100 client = anthropic.Anthropic()
101
102 response = client.messages.create(
103 model="claude-sonnet-5",
104 max_tokens=16000,
105 thinking={"type": "adaptive", "display": "summarized"},
106 output_config={"effort": "high"},
107 messages=[
108 {
109 "role": "user",
110 "content": "Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024.",
111 }
112 ],
113 )
114
115 # The response contains summarized thinking blocks and text blocks
116 for block in response.content:
117 match block.type:
118 case "thinking":
119 print(f"\nThinking summary: {block.thinking}")
120 case "text":
121 print(f"\nResponse: {block.text}")
122 ```
123
124 ```typescript TypeScript
125 const client = new Anthropic();
126
127 const response = await client.messages.create({
128 model: "claude-sonnet-5",
129 max_tokens: 16000,
130 thinking: {
131 type: "adaptive",
132 display: "summarized"
133 },
134 output_config: {
135 effort: "high"
136 },
137 messages: [
138 {
139 role: "user",
140 content: "Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024."
141 }
142 ]
143 });
144
145 // The response contains summarized thinking blocks and text blocks
146 for (const block of response.content) {
147 switch (block.type) {
148 case "thinking":
149 console.log(`\nThinking summary: ${block.thinking}`);
150 break;
151 case "text":
152 console.log(`\nResponse: ${block.text}`);
153 break;
154 }
155 }
156 ```
157
158 ```csharp C#
159 AnthropicClient client = new();
160
161 var response = await client.Messages.Create(new()
162 {
163 Model = Model.ClaudeSonnet5,
164 MaxTokens = 16000,
165 Thinking = new ThinkingConfigAdaptive { Display = Display.Summarized },
166 OutputConfig = new OutputConfig { Effort = Effort.High },
167 Messages =
168 [
169 new()
170 {
171 Role = Role.User,
172 Content = "Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024.",
173 },
174 ],
175 });
176
177 // The response contains summarized thinking blocks and text blocks
178 foreach (var block in response.Content)
179 {
180 if (block.TryPickThinking(out var thinking))
181 {
182 Console.WriteLine($"\nThinking summary: {thinking.Thinking}");
183 }
184 else if (block.TryPickText(out var text))
185 {
186 Console.WriteLine($"\nResponse: {text.Text}");
187 }
188 }
189 ```
190
191 ```go Go
192 client := anthropic.NewClient()
193
194 response, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
195 Model: anthropic.ModelClaudeSonnet5,
196 MaxTokens: 16000,
197 Thinking: anthropic.ThinkingConfigParamUnion{
198 OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{
199 Display: anthropic.ThinkingConfigAdaptiveDisplaySummarized,
200 },
201 },
202 OutputConfig: anthropic.OutputConfigParam{
203 Effort: anthropic.OutputConfigEffortHigh,
204 },
205 Messages: []anthropic.MessageParam{
206 anthropic.NewUserMessage(anthropic.NewTextBlock("Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024.")),
207 },
208 })
209 if err != nil {
210 log.Fatal(err)
211 }
212
213 // The response contains summarized thinking blocks and text blocks
214 for _, block := range response.Content {
215 switch block := block.AsAny().(type) {
216 case anthropic.ThinkingBlock:
217 fmt.Printf("\nThinking summary: %s", block.Thinking)
218 case anthropic.TextBlock:
219 fmt.Printf("\nResponse: %s", block.Text)
220 }
221 }
222 ```
223
224 ```java Java
225 import com.anthropic.client.okhttp.AnthropicOkHttpClient;
226 import com.anthropic.models.messages.MessageCreateParams;
227 import com.anthropic.models.messages.Model;
228 import com.anthropic.models.messages.OutputConfig;
229 import com.anthropic.models.messages.ThinkingConfigAdaptive;
230
231 void main() {
232 var client = AnthropicOkHttpClient.fromEnv();
233
234 var params = MessageCreateParams.builder()
235 .model(Model.CLAUDE_SONNET_5)
236 .maxTokens(16_000)
237 .thinking(ThinkingConfigAdaptive.builder()
238 .display(ThinkingConfigAdaptive.Display.SUMMARIZED)
239 .build())
240 .outputConfig(OutputConfig.builder()
241 .effort(OutputConfig.Effort.HIGH)
242 .build())
243 .addUserMessage("Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024.")
244 .build();
245
246 var response = client.messages().create(params);
247
248 // The response contains summarized thinking blocks and text blocks
249 for (var block : response.content()) {
250 block.thinking().ifPresent(thinkingBlock ->
251 IO.println("\nThinking summary: " + thinkingBlock.thinking())
252 );
253 block.text().ifPresent(textBlock ->
254 IO.println("\nResponse: " + textBlock.text())
255 );
256 }
257 }
258 ```
259
260 ```php PHP
261 use Anthropic\Messages\TextBlock;
262 use Anthropic\Messages\ThinkingBlock;
263
264 $client = new Client();
265
266 $response = $client->messages->create(
267 model: 'claude-sonnet-5',
268 maxTokens: 16000,
269 thinking: ['type' => 'adaptive', 'display' => 'summarized'],
270 outputConfig: ['effort' => 'high'],
271 messages: [
272 [
273 'role' => 'user',
274 'content' => 'Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024.',
275 ],
276 ],
277 );
278
279 // The response contains summarized thinking blocks and text blocks
280 foreach ($response->content as $block) {
281 echo match (true) {
282 $block instanceof ThinkingBlock => "\nThinking summary: {$block->thinking}",
283 $block instanceof TextBlock => "\nResponse: {$block->text}",
284 default => '',
285 };
286 }
287 ```
288
289 ```ruby Ruby
290 client = Anthropic::Client.new
291
292 response = client.messages.create(
293 model: "claude-sonnet-5",
294 max_tokens: 16_000,
295 thinking: {type: :adaptive, display: :summarized},
296 output_config: {effort: :high},
297 messages: [
298 {
299 role: :user,
300 content: "Find all pairs of positive integers (x, y) such that x^2 - y^2 = 2024."
301 }
302 ]
303 )
304
305 # The response contains summarized thinking blocks and text blocks
306 response.content.each do |block|
307 case block
308 when Anthropic::Models::ThinkingBlock
309 puts "\nThinking summary: #{block.thinking}"
310 when Anthropic::Models::TextBlock
311 puts "\nResponse: #{block.text}"
312 end
313 end
314 ```
315 </CodeGroup>
316 </Tab>
317
318 <Tab title="Claude Sonnet 4.6">
319 <CodeGroup>
320 ```bash cURL
321 curl https://api.anthropic.com/v1/messages \
322 -H "x-api-key: $ANTHROPIC_API_KEY" \
323 -H "anthropic-version: 2023-06-01" \
324 -H "content-type: application/json" \
325 -d '{
326 "model": "claude-sonnet-4-6",
327 "max_tokens": 16000,
328 "thinking": {
329 "type": "enabled",
330 "budget_tokens": 10000
331 },
332 "messages": [
333 {
334 "role": "user",
335 "content": "Are there an infinite number of prime numbers such that n mod 4 == 3?"
336 }
337 ]
338 }'
339 ```
340
341 ```bash CLI
342 ant messages create \
343 --format yaml <<'YAML'
344 model: claude-sonnet-4-6
345 max_tokens: 16000
346 thinking:
347 type: enabled
348 budget_tokens: 10000
349 messages:
350 - role: user
351 content: Are there an infinite number of prime numbers such that n mod 4 == 3?
352 YAML
353 ```
354
355 ```python Python
356 client = anthropic.Anthropic()
357
358 response = client.messages.create(
359 model="claude-sonnet-4-6",
360 max_tokens=16000,
361 thinking={"type": "enabled", "budget_tokens": 10000},
362 messages=[
363 {
364 "role": "user",
365 "content": "Are there an infinite number of prime numbers such that n mod 4 == 3?",
366 }
367 ],
368 )
369
370 # The response contains summarized thinking blocks and text blocks
371 for block in response.content:
372 match block.type:
373 case "thinking":
374 print(f"\nThinking summary: {block.thinking}")
375 case "text":
376 print(f"\nResponse: {block.text}")
377 ```
378
379 ```typescript TypeScript
380 const client = new Anthropic();
381
382 const response = await client.messages.create({
383 model: "claude-sonnet-4-6",
384 max_tokens: 16000,
385 thinking: {
386 type: "enabled",
387 budget_tokens: 10000,
388 },
389 messages: [
390 {
391 role: "user",
392 content: "Are there an infinite number of prime numbers such that n mod 4 == 3?",
393 },
394 ],
395 });
396
397 // The response contains summarized thinking blocks and text blocks
398 for (const block of response.content) {
399 switch (block.type) {
400 case "thinking":
401 console.log(`\nThinking summary: ${block.thinking}`);
402 break;
403 case "text":
404 console.log(`\nResponse: ${block.text}`);
405 break;
406 }
407 }
408 ```
409
410 ```csharp C#
411 AnthropicClient client = new();
412
413 var response = await client.Messages.Create(new()
414 {
415 Model = Model.ClaudeSonnet4_6,
416 MaxTokens = 16000,
417 Thinking = new ThinkingConfigEnabled(budgetTokens: 10000),
418 Messages =
419 [
420 new()
421 {
422 Role = Role.User,
423 Content = "Are there an infinite number of prime numbers such that n mod 4 == 3?",
424 },
425 ],
426 });
427
428 // The response contains summarized thinking blocks and text blocks
429 foreach (var block in response.Content)
430 {
431 if (block.TryPickThinking(out var thinking))
432 {
433 Console.WriteLine($"\nThinking summary: {thinking.Thinking}");
434 }
435 else if (block.TryPickText(out var text))
436 {
437 Console.WriteLine($"\nResponse: {text.Text}");
438 }
439 }
440 ```
441
442 ```go Go
443 client := anthropic.NewClient()
444
445 response, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
446 Model: anthropic.ModelClaudeSonnet4_6,
447 MaxTokens: 16000,
448 Thinking: anthropic.ThinkingConfigParamOfEnabled(10000),
449 Messages: []anthropic.MessageParam{
450 anthropic.NewUserMessage(anthropic.NewTextBlock("Are there an infinite number of prime numbers such that n mod 4 == 3?")),
451 },
452 })
453 if err != nil {
454 log.Fatal(err)
455 }
456
457 // The response contains summarized thinking blocks and text blocks
458 for _, block := range response.Content {
459 switch block := block.AsAny().(type) {
460 case anthropic.ThinkingBlock:
461 fmt.Printf("\nThinking summary: %s", block.Thinking)
462 case anthropic.TextBlock:
463 fmt.Printf("\nResponse: %s", block.Text)
464 }
465 }
466 ```
467
468 ```java Java
469 import com.anthropic.client.okhttp.AnthropicOkHttpClient;
470 import com.anthropic.models.messages.MessageCreateParams;
471 import com.anthropic.models.messages.Model;
472
473 void main() {
474 var client = AnthropicOkHttpClient.fromEnv();
475
476 var params = MessageCreateParams.builder()
477 .model(Model.CLAUDE_SONNET_4_6)
478 .maxTokens(16_000)
479 .enabledThinking(10_000)
480 .addUserMessage("Are there an infinite number of prime numbers such that n mod 4 == 3?")
481 .build();
482
483 var response = client.messages().create(params);
484
485 // The response contains summarized thinking blocks and text blocks
486 for (var block : response.content()) {
487 block.thinking().ifPresent(thinkingBlock ->
488 IO.println("\nThinking summary: " + thinkingBlock.thinking())
489 );
490 block.text().ifPresent(textBlock ->
491 IO.println("\nResponse: " + textBlock.text())
492 );
493 }
494 }
495 ```
496
497 ```php PHP
498 $client = new Client();
499
500 $response = $client->messages->create(
501 model: 'claude-sonnet-4-6',
502 maxTokens: 16000,
503 thinking: ['type' => 'enabled', 'budget_tokens' => 10000],
504 messages: [
505 [
506 'role' => 'user',
507 'content' => 'Are there an infinite number of prime numbers such that n mod 4 == 3?',
508 ],
509 ],
510 );
511
512 // The response contains summarized thinking blocks and text blocks
513 foreach ($response->content as $block) {
514 echo match (true) {
515 $block instanceof \Anthropic\Messages\ThinkingBlock => "\nThinking summary: {$block->thinking}",
516 $block instanceof \Anthropic\Messages\TextBlock => "\nResponse: {$block->text}",
517 default => '',
518 };
519 }
520 ```
521
522 ```ruby Ruby
523 client = Anthropic::Client.new
524
525 response = client.messages.create(
526 model: "claude-sonnet-4-6",
527 max_tokens: 16_000,
528 thinking: {
529 type: :enabled,
530 budget_tokens: 10_000
531 },
532 messages: [
533 {
534 role: :user,
535 content: "Are there an infinite number of prime numbers such that n mod 4 == 3?"
536 }
537 ]
538 )
539
540 # The response contains summarized thinking blocks and text blocks
541 response.content.each do |block|
542 case block
543 when Anthropic::Models::ThinkingBlock
544 puts "\nThinking summary: #{block.thinking}"
545 when Anthropic::Models::TextBlock
546 puts "\nResponse: #{block.text}"
547 end
548 end
549 ```
550 </CodeGroup>
551 </Tab>
552 </Tabs>
553
5545. **Sampling parameters removed:** Sampling parameters (`temperature`, `top_p`, `top_k`) set to a non-default value are not accepted and return a 400 error.
555
5566. **Cybersecurity safeguards:** Claude Sonnet 5 is the first Sonnet-tier model with real-time cybersecurity safeguards. Requests that involve prohibited or high-risk cybersecurity topics may be refused. Refusals return as a successful HTTP 200 response with `stop_reason: "refusal"`, not an error. See [Real-time cyber safeguards on Claude Opus and Sonnet](https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude-opus-and-sonnet) for what the safeguards block and how legitimate security work can apply to the Cyber Verification Program.
557
558### Migration checklist
559
560* Update model name from `claude-sonnet-4-6` to `claude-sonnet-5`.
561* Re-run [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) against Claude Sonnet 5. The new tokenizer produces approximately 30% more tokens for the same text, which can change per-request cost even though per-token pricing is lower. The exact increase depends on the content and workload shape.
562* Revisit `max_tokens` limits sized close to your expected output length, and raise them up to the 128k maximum (unchanged from Claude Sonnet 4.6) where useful.
563* Remove `thinking: {type: "enabled", budget_tokens: N}` configuration (returns a 400 error). Adaptive thinking is on by default; pass `{type: "disabled"}` to turn it off, or use the [effort parameter](https://platform.claude.com/docs/en/build-with-claude/effort) to control depth.
564* Update response parsing that reads content by position, such as `content[0].text`: with thinking on, `thinking` blocks arrive before `text` blocks. Select content blocks by `type` instead, and pass `thinking` blocks back unmodified in tool-use loops; modified blocks return a 400 error.
565* Verify any code that parses the `thinking` field treats it as display text only. `thinking.display` defaults to `"omitted"` on Claude Sonnet 5 (it defaulted to `"summarized"` on Claude Sonnet 4.6), so thinking blocks arrive with an empty `thinking` field; set `display: "summarized"` to receive readable summaries. See [Controlling thinking display](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display).
566* Remove `temperature`, `top_p`, and `top_k` parameters set to non-default values (they return a 400 error on Claude Sonnet 5).
567* Add handling for `stop_reason: "refusal"` if your workload may touch cybersecurity topics.
568* Re-baseline cost on your typical workload before production deployment.
569* Review `max_tokens` for workloads that previously ran without thinking.
570
571## Migrating to Claude Sonnet 5 from Claude Sonnet 4.5 and earlier Sonnet models
572
573If you are migrating from Claude Sonnet 4.5 or an earlier Sonnet model directly to Claude Sonnet 5, apply the [Migrating to Claude Sonnet 5 from Claude Sonnet 4.6](https://platform.claude.com/docs/en/models/sonnet-5/migration-guide#migrating-from-claude-sonnet-4-6-to-claude-sonnet-5) changes plus the changes in this section.
574
575<Warning>
576 Claude Sonnet 5 defaults to an effort level of `high`, in contrast to Sonnet 4.5 which had no effort parameter. Consider adjusting the [effort parameter](https://platform.claude.com/docs/en/build-with-claude/effort) as you migrate. If not explicitly set, you may experience higher latency with the default effort level.
577</Warning>
248`between_tools` works on every platform that offers Claude Sonnet 5.5, with no beta header. It's accepted at `low`, `medium`, and `high` effort. At `xhigh` or `max`, it returns a 400 error. To run at those levels, use adaptive thinking: omit the `thinking` field or send `thinking: {"type": "adaptive"}`. `between_tools` takes no other field: `display`, `budget_tokens`, or `block_binding` sent with it returns a 400 error. With [server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback), a `between_tools` request that falls back to Claude Sonnet 5 runs there with `thinking: {"type": "disabled"}`.
249
250With `between_tools`, effort can't change mid-conversation: a per-message `output_config.effort` that differs from the level in effect returns a 400 error. To vary effort per turn, use adaptive thinking. For prompting guidance, see [Running without up-front thinking](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#running-without-up-front-thinking).
251
252Before (Claude Sonnet 5):
253
254<CodeGroup>
255 ```bash cURL
256 curl https://api.anthropic.com/v1/messages \
257 -H "x-api-key: $ANTHROPIC_API_KEY" \
258 -H "anthropic-version: 2023-06-01" \
259 -H "content-type: application/json" \
260 -d '{
261 "model": "claude-sonnet-5",
262 "max_tokens": 16000,
263 "thinking": {"type": "disabled"},
264 "output_config": {"effort": "xhigh"},
265 "messages": [{"role": "user", "content": "..."}]
266 }'
267 ```
268
269 ```bash CLI
270 ant messages create \
271 --model claude-sonnet-5 \
272 --max-tokens 16000 \
273 --thinking '{type: disabled}' \
274 --output-config '{effort: xhigh}' \
275 --message '{role: user, content: "..."}'
276 ```
277
278 ```python Python
279 client.messages.create(
280 model="claude-sonnet-5",
281 max_tokens=16000,
282 thinking={"type": "disabled"},
283 output_config={"effort": "xhigh"},
284 messages=[{"role": "user", "content": "..."}],
285 )
286 ```
287
288 ```typescript TypeScript
289 await client.messages.create({
290 model: "claude-sonnet-5",
291 max_tokens: 16000,
292 thinking: { type: "disabled" },
293 output_config: { effort: "xhigh" },
294 messages: [{ role: "user", content: "..." }]
295 });
296 ```
297
298 ```csharp C#
299 await client.Messages.Create(new MessageCreateParams
300 {
301 Model = Model.ClaudeSonnet5,
302 MaxTokens = 16000,
303 Thinking = new ThinkingConfigDisabled(),
304 OutputConfig = new() { Effort = Effort.Xhigh },
305 Messages = [new() { Role = Role.User, Content = "..." }],
306 });
307 ```
308
309 ```go Go
310 client.Messages.New(context.TODO(), anthropic.MessageNewParams{
311 Model: anthropic.ModelClaudeSonnet5,
312 MaxTokens: 16000,
313 Thinking: anthropic.ThinkingConfigParamUnion{
314 OfDisabled: &anthropic.ThinkingConfigDisabledParam{},
315 },
316 OutputConfig: anthropic.OutputConfigParam{
317 Effort: anthropic.OutputConfigEffortXhigh,
318 },
319 Messages: []anthropic.MessageParam{
320 anthropic.NewUserMessage(anthropic.NewTextBlock("...")),
321 },
322 })
323 ```
324
325 ```java Java
326 MessageCreateParams params = MessageCreateParams.builder()
327 .model(Model.CLAUDE_SONNET_5)
328 .maxTokens(16000L)
329 .thinking(ThinkingConfigDisabled.builder().build())
330 .outputConfig(OutputConfig.builder()
331 .effort(OutputConfig.Effort.XHIGH)
332 .build())
333 .addUserMessage("...")
334 .build();
335
336 client.messages().create(params);
337 ```
338
339 ```php PHP
340 $client->messages->create(
341 model: Model::CLAUDE_SONNET_5,
342 maxTokens: 16000,
343 thinking: ThinkingConfigDisabled::with(),
344 outputConfig: OutputConfig::with(effort: Effort::XHIGH),
345 messages: [['role' => 'user', 'content' => '...']],
346 );
347 ```
348
349 ```ruby Ruby
350 client.messages.create(
351 model: Anthropic::Model::CLAUDE_SONNET_5,
352 max_tokens: 16000,
353 thinking: Anthropic::ThinkingConfigDisabled.new,
354 output_config: { effort: Anthropic::OutputConfig::Effort::XHIGH },
355 messages: [{ role: "user", content: "..." }]
356 )
357 ```
358</CodeGroup>
359
360After (Claude Sonnet 5.5):
361
362<CodeGroup>
363 ```bash cURL
364 curl https://api.anthropic.com/v1/messages \
365 -H "x-api-key: $ANTHROPIC_API_KEY" \
366 -H "anthropic-version: 2023-06-01" \
367 -H "content-type: application/json" \
368 -d '{
369 "model": "claude-sonnet-5-5",
370 "max_tokens": 16000,
371 "thinking": {"type": "between_tools"},
372 "output_config": {"effort": "high"},
373 "messages": [{"role": "user", "content": "..."}]
374 }'
375 ```
376
377 ```bash CLI
378 ant messages create \
379 --model claude-sonnet-5-5 \
380 --max-tokens 16000 \
381 --thinking '{type: between_tools}' \
382 --output-config '{effort: high}' \
383 --message '{role: user, content: "..."}'
384 ```
385
386 ```python Python
387 client.messages.create(
388 model="claude-sonnet-5-5",
389 max_tokens=16000,
390 thinking={"type": "between_tools"},
391 output_config={"effort": "high"},
392 messages=[{"role": "user", "content": "..."}],
393 )
394 ```
395
396 ```typescript TypeScript
397 await client.messages.create({
398 model: "claude-sonnet-5-5",
399 max_tokens: 16000,
400 thinking: { type: "between_tools" },
401 output_config: { effort: "high" },
402 messages: [{ role: "user", content: "..." }]
403 });
404 ```
405
406 ```csharp C#
407 await client.Messages.Create(new MessageCreateParams
408 {
409 Model = Model.ClaudeSonnet5_5,
410 MaxTokens = 16000,
411 Thinking = new ThinkingConfigBetweenTools(),
412 OutputConfig = new() { Effort = Effort.High },
413 Messages = [new() { Role = Role.User, Content = "..." }],
414 });
415 ```
416
417 ```go Go
418 client.Messages.New(context.TODO(), anthropic.MessageNewParams{
419 Model: anthropic.ModelClaudeSonnet5_5,
420 MaxTokens: 16000,
421 Thinking: anthropic.ThinkingConfigParamUnion{
422 OfBetweenTools: &anthropic.ThinkingConfigBetweenToolsParam{},
423 },
424 OutputConfig: anthropic.OutputConfigParam{
425 Effort: anthropic.OutputConfigEffortHigh,
426 },
427 Messages: []anthropic.MessageParam{
428 anthropic.NewUserMessage(anthropic.NewTextBlock("...")),
429 },
430 })
431 ```
432
433 ```java Java
434 MessageCreateParams params = MessageCreateParams.builder()
435 .model(Model.CLAUDE_SONNET_5_5)
436 .maxTokens(16000L)
437 .thinking(ThinkingConfigBetweenTools.builder().build())
438 .outputConfig(OutputConfig.builder()
439 .effort(OutputConfig.Effort.HIGH)
440 .build())
441 .addUserMessage("...")
442 .build();
443
444 client.messages().create(params);
445 ```
446
447 ```php PHP
448 $client->messages->create(
449 model: Model::CLAUDE_SONNET_5_5,
450 maxTokens: 16000,
451 thinking: ThinkingConfigBetweenTools::with(),
452 outputConfig: OutputConfig::with(effort: Effort::HIGH),
453 messages: [['role' => 'user', 'content' => '...']],
454 );
455 ```
456
457 ```ruby Ruby
458 client.messages.create(
459 model: Anthropic::Model::CLAUDE_SONNET_5_5,
460 max_tokens: 16000,
461 thinking: Anthropic::ThinkingConfigBetweenTools.new,
462 output_config: { effort: Anthropic::OutputConfig::Effort::HIGH },
463 messages: [{ role: "user", content: "..." }]
464 )
465 ```
466</CodeGroup>
467
468## Migration checklist by starting model
469
470Work down the groups and stop after the one that names your model. On Claude Haiku 4.5, apply every group except "Claude Sonnet 4 or earlier", ending with "Claude Haiku 4.5 only".
471
472### Every starting model
473
474* Change the model ID to `claude-sonnet-5-5`.
475* [Read content blocks by `type`](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#thinking-in-responses), and pass `thinking` blocks back unchanged.
476* To keep running without up-front thinking, send [the lowest thinking setting](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#turn-off-up-front-thinking) at `high` effort or below.
477* Replace [forced tool use](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#forced-tool-use) with `auto` and strict tools, or with `auto` alone on Amazon Bedrock.
478* Keep conversations [append-only](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#thinking-blocks).
479* On the Claude API and Google Cloud, move computer use to the [toolset](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#computer-use-toolset), without the `fine-grained-tool-streaming-2025-05-14` beta header.
480* Pair the [advisor tool](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#advisor-tool) with a supported advisor, and expect encrypted advice.
481* Read [text between tool calls](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#text-between-tool-calls) from `thinking` blocks.
482* [Handle refusals](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#safety-classifiers-and-fallback), and configure fallback.
483* [Re-run your effort sweep](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#recommended-changes), and re-baseline cost.
484
485### Claude Sonnet 4.6 or earlier
486
487* Expect [thinking on requests with no `thinking` field](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#thinking-on-by-default), and revisit `max_tokens`.
488* Replace [thinking budgets](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#sonnet-46-breaking-changes) with an effort level.
489* Remove non-default `temperature`, `top_p`, and `top_k` values.
490* If you [show thinking text](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#thinking-in-responses), set `display: "summarized"`.
491* [Recount tokens](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#other-changes-from-claude-sonnet-4-6), and re-budget image tokens.
492
493### Claude Sonnet 4.5 or earlier
494
495* Replace [assistant prefills](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#migrating-from-sonnet-45).
496* Parse tool call input with a standard JSON parser.
497* On Amazon Bedrock, move computer use from `computer_20250124` to [`computer_20251124`](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#computer-use-toolset).
498* Set `output_config.effort` explicitly.
499* Remove any context-window beta header.
500* Remove `interleaved-thinking-2025-05-14`, and replace `fine-grained-tool-streaming-2025-05-14` with `eager_input_streaming`.
501* Move `output_format` to `output_config.format`.
502
503### Claude Sonnet 4 or earlier
504
505* Update [tool versions](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#migrating-from-claude-sonnet-4-or-earlier) to `text_editor_20250728` and `code_execution_20260521`.
506* Handle the `refusal` and `model_context_window_exceeded` stop reasons.
507* Check tool string parameters for trailing newlines.
508* Remove `token-efficient-tools-2025-02-19` and `output-128k-2025-02-19`.
509* Review your prompts.
510
511### Claude Haiku 4.5 only
512
513* Replace [`claude-haiku-4-5-20251001`](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#migrating-from-claude-haiku-4-5) or its alias.
514* Re-baseline cost at the higher price per token.
515* Review prompts that were too short to cache on Claude Haiku 4.5.
516
517## Migrating to Claude Sonnet 5.5 from Claude Sonnet 5
518
519Every starting model needs the changes in this section. Replace your model ID with `claude-sonnet-5-5`, which has no date suffix. On other platforms, use the ID listed under [Availability](https://platform.claude.com/docs/en/models/sonnet-5-5/whats-new-sonnet-5-5#availability).
520
521### Forced tool use is not supported
522
523Every earlier model on this page accepts a `tool_choice` of type `any` or `tool`. Claude Sonnet 5.5 rejects both with a 400 error, including on the [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) endpoint:
524
525```text wrap
526tool_choice: type "tool" and "any" are not supported for this model.
527```
528
529Send `tool_choice: {"type": "auto"}`, and mark the tool `strict: true` so its input matches the schema. The model can then answer without calling the tool, so say in the prompt when to use it. [Strict tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use) supports a subset of JSON Schema and needs `additionalProperties: false` on every object. See [JSON Schema limitations](https://platform.claude.com/docs/en/build-with-claude/structured-outputs#json-schema-limitations). On Amazon Bedrock, [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs), which include strict tool use, aren't available for Claude Sonnet 5.5. There, send `auto` without `strict`, say in the prompt when to call the tool, and validate the tool input in your code.
530
531Before (Claude Sonnet 5):
532
533<CodeGroup>
534 ```bash cURL
535 curl https://api.anthropic.com/v1/messages \
536 -H "x-api-key: $ANTHROPIC_API_KEY" \
537 -H "anthropic-version: 2023-06-01" \
538 -H "content-type: application/json" \
539 -d '{
540 "model": "claude-sonnet-5",
541 "max_tokens": 1024,
542 "tools": [{
543 "name": "get_weather",
544 "description": "Get the current weather in a given location",
545 "input_schema": {
546 "type": "object",
547 "properties": {
548 "location": {
549 "type": "string",
550 "description": "The city and state, e.g. San Francisco, CA"
551 }
552 },
553 "required": ["location"],
554 "additionalProperties": false
555 }
556 }],
557 "tool_choice": {"type": "tool", "name": "get_weather"},
558 "messages": [{"role": "user", "content": "What'\''s the weather in Paris?"}]
559 }'
560 ```
561
562 ```bash CLI
563 ant messages create <<'YAML'
564 model: claude-sonnet-5
565 max_tokens: 1024
566 tools:
567 - name: get_weather
568 description: Get the current weather in a given location
569 input_schema:
570 type: object
571 properties:
572 location:
573 type: string
574 description: The city and state, e.g. San Francisco, CA
575 required: [location]
576 additionalProperties: false
577 tool_choice:
578 type: tool
579 name: get_weather
580 messages:
581 - role: user
582 content: What's the weather in Paris?
583 YAML
584 ```
585
586 ```python Python
587 client.messages.create(
588 model="claude-sonnet-5",
589 max_tokens=1024,
590 tools=tools,
591 tool_choice={"type": "tool", "name": "get_weather"},
592 messages=[{"role": "user", "content": "What's the weather in Paris?"}],
593 )
594 ```
595
596 ```typescript TypeScript
597 await client.messages.create({
598 model: "claude-sonnet-5",
599 max_tokens: 1024,
600 tools,
601 tool_choice: { type: "tool", name: "get_weather" },
602 messages: [{ role: "user", content: "What's the weather in Paris?" }]
603 });
604 ```
605
606 ```csharp C#
607 await client.Messages.Create(new MessageCreateParams
608 {
609 Model = Model.ClaudeSonnet5,
610 MaxTokens = 1024,
611 Tools = [.. tools],
612 ToolChoice = new ToolChoiceTool { Name = "get_weather" },
613 Messages = [new() { Role = Role.User, Content = "What's the weather in Paris?" }],
614 });
615 ```
616
617 ```go Go
618 client.Messages.New(context.TODO(), anthropic.MessageNewParams{
619 Model: anthropic.ModelClaudeSonnet5,
620 MaxTokens: 1024,
621 Tools: tools,
622 ToolChoice: anthropic.ToolChoiceParamOfTool("get_weather"),
623 Messages: []anthropic.MessageParam{
624 anthropic.NewUserMessage(anthropic.NewTextBlock("What's the weather in Paris?")),
625 },
626 })
627 ```
628
629 ```java Java
630 MessageCreateParams params = MessageCreateParams.builder()
631 .model(Model.CLAUDE_SONNET_5)
632 .maxTokens(1024L)
633 .tools(tools)
634 .toolChoice(ToolChoiceTool.of("get_weather"))
635 .addUserMessage("What's the weather in Paris?")
636 .build();
637
638 client.messages().create(params);
639 ```
640
641 ```php PHP
642 $client->messages->create(
643 model: Model::CLAUDE_SONNET_5,
644 maxTokens: 1024,
645 tools: $tools,
646 toolChoice: ToolChoiceTool::with(name: 'get_weather'),
647 messages: [['role' => 'user', 'content' => "What's the weather in Paris?"]],
648 );
649 ```
650
651 ```ruby Ruby
652 client.messages.create(
653 model: Anthropic::Model::CLAUDE_SONNET_5,
654 max_tokens: 1024,
655 tools: tools,
656 tool_choice: Anthropic::ToolChoiceTool.new(name: "get_weather"),
657 messages: [{ role: "user", content: "What's the weather in Paris?" }]
658 )
659 ```
660</CodeGroup>
661
662After (Claude Sonnet 5.5):
663
664<CodeGroup>
665 ```bash cURL
666 # strict tool use: every call matches the tool's input_schema
667 curl https://api.anthropic.com/v1/messages \
668 -H "x-api-key: $ANTHROPIC_API_KEY" \
669 -H "anthropic-version: 2023-06-01" \
670 -H "content-type: application/json" \
671 -d '{
672 "model": "claude-sonnet-5-5",
673 "max_tokens": 1024,
674 "tools": [{
675 "name": "get_weather",
676 "description": "Get the current weather in a given location",
677 "input_schema": {
678 "type": "object",
679 "properties": {
680 "location": {
681 "type": "string",
682 "description": "The city and state, e.g. San Francisco, CA"
683 }
684 },
685 "required": ["location"],
686 "additionalProperties": false
687 },
688 "strict": true
689 }],
690 "tool_choice": {"type": "auto"},
691 "messages": [{
692 "role": "user",
693 "content": "What'\''s the weather in Paris? Use the get_weather tool."
694 }]
695 }'
696 ```
697
698 ```bash CLI
699 ant messages create <<'YAML'
700 model: claude-sonnet-5-5
701 max_tokens: 1024
702 tools:
703 - name: get_weather
704 description: Get the current weather in a given location
705 input_schema:
706 type: object
707 properties:
708 location:
709 type: string
710 description: The city and state, e.g. San Francisco, CA
711 required: [location]
712 additionalProperties: false
713 # strict tool use: every call matches the tool's input_schema
714 strict: true
715 tool_choice:
716 type: auto
717 messages:
718 - role: user
719 content: What's the weather in Paris? Use the get_weather tool.
720 YAML
721 ```
722
723 ```python Python
724 client.messages.create(
725 model="claude-sonnet-5-5",
726 max_tokens=1024,
727 # strict tool use: every call matches the tool's input_schema
728 tools=[{**tool, "strict": True} for tool in tools],
729 tool_choice={"type": "auto"},
730 messages=[
731 {
732 "role": "user",
733 "content": "What's the weather in Paris? Use the get_weather tool.",
734 }
735 ],
736 )
737 ```
738
739 ```typescript TypeScript
740 await client.messages.create({
741 model: "claude-sonnet-5-5",
742 max_tokens: 1024,
743 // strict tool use: every call matches the tool's input_schema
744 tools: tools.map((tool) => ({ ...tool, strict: true })),
745 tool_choice: { type: "auto" },
746 messages: [
747 {
748 role: "user",
749 content: "What's the weather in Paris? Use the get_weather tool."
750 }
751 ]
752 });
753 ```
754
755 ```csharp C#
756 await client.Messages.Create(new MessageCreateParams
757 {
758 Model = Model.ClaudeSonnet5_5,
759 MaxTokens = 1024,
760 // strict tool use: every call matches the tool's input_schema
761 Tools = [.. tools.Select(tool => tool with { Strict = true })],
762 ToolChoice = new ToolChoiceAuto(),
763 Messages =
764 [
765 new()
766 {
767 Role = Role.User,
768 Content = "What's the weather in Paris? Use the get_weather tool.",
769 },
770 ],
771 });
772 ```
773
774 ```go Go
775 // strict tool use: every call matches the tool's input_schema
776 var strictTools []anthropic.ToolUnionParam
777 for _, tool := range tools {
778 strictTool := *tool.OfTool
779 strictTool.Strict = anthropic.Bool(true)
780 strictTools = append(strictTools, anthropic.ToolUnionParam{OfTool: &strictTool})
781 }
782 client.Messages.New(context.TODO(), anthropic.MessageNewParams{
783 Model: anthropic.ModelClaudeSonnet5_5,
784 MaxTokens: 1024,
785 Tools: strictTools,
786 ToolChoice: anthropic.ToolChoiceUnionParam{OfAuto: &anthropic.ToolChoiceAutoParam{}},
787 Messages: []anthropic.MessageParam{
788 anthropic.NewUserMessage(
789 anthropic.NewTextBlock("What's the weather in Paris? Use the get_weather tool."),
790 ),
791 },
792 })
793 ```
794
795 ```java Java
796 MessageCreateParams params = MessageCreateParams.builder()
797 .model(Model.CLAUDE_SONNET_5_5)
798 .maxTokens(1024L)
799 // strict tool use: every call matches the tool's input_schema
800 .tools(tools.stream()
801 .map(tool -> tool.tool()
802 .map(customTool -> customTool.toBuilder().strict(true).build())
803 .map(ToolUnion::ofTool)
804 .orElse(tool))
805 .toList())
806 .toolChoice(ToolChoiceAuto.builder().build())
807 .addUserMessage("What's the weather in Paris? Use the get_weather tool.")
808 .build();
809
810 client.messages().create(params);
811 ```
812
813 ```php PHP
814 $client->messages->create(
815 model: Model::CLAUDE_SONNET_5_5,
816 maxTokens: 1024,
817 // strict tool use: every call matches the tool's input_schema
818 tools: array_map(fn (Tool $tool) => $tool->withStrict(true), $tools),
819 toolChoice: ToolChoiceAuto::with(),
820 messages: [
821 [
822 'role' => 'user',
823 'content' => "What's the weather in Paris? Use the get_weather tool.",
824 ],
825 ],
826 );
827 ```
828
829 ```ruby Ruby
830 client.messages.create(
831 model: Anthropic::Model::CLAUDE_SONNET_5_5,
832 max_tokens: 1024,
833 # strict tool use: every call matches the tool's input_schema
834 tools: tools.map { |tool| tool.merge(strict: true) },
835 tool_choice: Anthropic::ToolChoiceAuto.new,
836 messages: [
837 { role: "user", content: "What's the weather in Paris? Use the get_weather tool." }
838 ]
839 )
840 ```
841</CodeGroup>
842
843The example marks every tool in the list strict. A request can have at most 20 strict tools, and the MCP, computer use, and browser use toolset entries don't accept `strict`. In a longer tools list, mark only the tools that need it.
844
845### Thinking blocks are tied to the model and the conversation
846
847Claude Sonnet 5.5 reads thinking blocks from Claude Sonnet 5, Claude Opus 4.8, Claude Haiku 4.5, and earlier models. It doesn't read blocks from Claude Opus 5, Claude Opus 5.5, or any Claude Fable or Claude Mythos model. The API drops blocks the model can't read. The request still returns 200, and dropped blocks aren't billed. See [Switching models mid-conversation](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#switching-models).
848
849Each Claude Sonnet 5.5 thinking block is also signed over the conversation before it. For accounts created on or after August 31, 2026, 00:00 UTC, the API enforces this by default, on the Claude API, Amazon Bedrock, and Google Cloud. On those accounts, a request that replays a block after an edit to earlier history returns a 400 error. Keep conversations append-only, and change instructions or tools with [mid-conversation system messages](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages). Thinking blocks that Claude Sonnet 5.5 produces work only in the account that produced them, or in an account linked to it. See [Preserved thinking](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#account-bound-thinking).
850
851### Computer use needs the toolset on the Claude API and Google Cloud
852
853On the Claude API and Google Cloud, Claude Sonnet 5.5 supports computer use only through the `computer_toolset_20260801` toolset. There, `computer_20251124` returns a 400 error. Claude Sonnet 5.5 doesn't accept `computer_20250124` on any platform. Find the version you send today:
854
855| Version you send today | Starting models that send it | Send on the Claude API and Google Cloud | Send on Amazon Bedrock |
856| ---------------------- | ---------------------------------------------------- | --------------------------------------- | ---------------------- |
857| `computer_20251124` | Claude Sonnet 5, Claude Sonnet 4.6 | `computer_toolset_20260801` | `computer_20251124` |
858| `computer_20250124` | Claude Sonnet 4.5, Claude Haiku 4.5, Claude Sonnet 4 | `computer_toolset_20260801` | `computer_20251124` |
859
860If you send the `fine-grained-tool-streaming-2025-05-14` beta header, remove it when you move to the toolset. Alongside a toolset entry, it returns a 400 error. Set `eager_input_streaming: true` on each tool that needs it instead.
861
862Code that already sends the toolset needs no change. [Migrate from `computer_20251124`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool#migrate-from-computer-20251124) lists the request and agent-loop changes. For other platforms, see [Compatibility](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool#compatibility).
863
864### The advisor tool accepts fewer advisors
865
866With the [advisor tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/advisor-tool), a Claude Sonnet 5.5 executor needs one of these advisors: Claude Opus 5, Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5, Claude Fable 5.1, Claude Mythos 5, or Claude Mythos 5.1. Claude Opus 4.8, Claude Opus 4.7, Claude Opus 4.6, Claude Sonnet 5, and Claude Sonnet 4.6 advisors return a 400 error. The advice comes back encrypted as an `advisor_redacted_result` block, so its text isn't readable in the response. See [Model compatibility](https://platform.claude.com/docs/en/agents-and-tools/tool-use/advisor-tool#model-compatibility).
867
868### Text between tool calls is returned in thinking blocks
869
870On Claude Sonnet 5.5, notes longer than a sentence or two that the model writes between tool calls come back as [progress-update `thinking` blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#progress-updates), empty at the default `display`. Shorter remarks stay `text`. On Claude Sonnet 5 and earlier models, all text between tool calls comes back as `text` blocks. No request fails, but an interface that shows those notes goes quiet.
871
872With adaptive thinking, set `display` to `"updates"` (beta, `thinking-display-updates-2026-08-18` header) to get the updates alone, or to `"summarized"` to get them mixed with reasoning. Render each non-empty `thinking` block before the `tool_use` block that follows it. With [`between_tools`](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#turn-off-up-front-thinking), the text comes back without `display`. See [User-facing progress updates](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5#user-facing-progress-updates).
873
874### Safety classifiers and fallback
875
876Claude Sonnet 5.5 declines in more categories than Claude Sonnet 5. A decline returns `stop_reason: "refusal"`, and its `stop_details` can name one of these [categories](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response):
877
878* **`"cyber"`:** The request could enable cyber harm, such as malware or exploit development.
879* **`"bio"`:** The request could enable biological harm, such as dangerous lab methods.
880* **`"frontier_llm"`:** The request could assist the development of competing AI models.
881* **`"reasoning_extraction"`:** The request asks the model to reproduce its internal reasoning in the response text.
882* **`"general_harms"`:** The request falls under another usage-policy area. Benign work can also trigger this category.
883
884[Server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback) (`fallbacks: "default"`, beta, Claude API only) retries `"cyber"` and `"frontier_llm"` declines on Claude Sonnet 5. It doesn't retry `"bio"`, `"reasoning_extraction"`, or `"general_harms"` declines. See [Refusals and fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback) and [How refusals are billed](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#how-refusals-are-billed).
885
886Real-time cyber safeguards are new for code from Claude Sonnet 4.6, Claude Sonnet 4.5, and Claude Haiku 4.5. For legitimate security work, apply to the [Cyber Verification Program](https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude-opus-and-sonnet).
887
888### Other changes
889
890* **Prompt caching:** The minimum cacheable prompt is 512 tokens, down from 1,024 on Claude Sonnet 5, Claude Sonnet 4.6, and Claude Sonnet 4.5. See [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-limitations).
891* **New features:** For mid-conversation system messages, mid-conversation tool changes, and per-message effort, see [What's new in Claude Sonnet 5.5](https://platform.claude.com/docs/en/models/sonnet-5-5/whats-new-sonnet-5-5#feature-support). With [`between_tools`](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#turn-off-up-front-thinking), effort can't change mid-conversation.
892
893### Recommended changes
894
895Re-run your effort sweep. Claude Sonnet 5.5 has five effort levels: `low`, `medium`, `high`, `xhigh`, and `max`. The default on the Claude API is `high`. The levels are recalibrated, so a level doesn't produce the same amount of thinking as on Claude Sonnet 5. Start at `high` unless your workload is agentic or latency-sensitive. For agentic coding and multistep tool use, start at `medium` for well-specified tasks and move to `high` for harder or longer ones. For chat and other latency-sensitive work, start at `medium` or `low`. Set the level in `output_config.effort`. See [Recommended effort levels for Claude Sonnet 5.5](https://platform.claude.com/docs/en/build-with-claude/effort#recommended-effort-levels-for-claude-sonnet-5-5). Then re-evaluate model-specific prompt instructions against [Prompting Claude Sonnet 5.5](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-sonnet-5-5).
896
897## Migrating to Claude Sonnet 5.5 from Claude Sonnet 4.6 and earlier Sonnet models
898
899First apply every preceding section, replacing `claude-sonnet-4-6`. Then make these changes. On Claude Sonnet 4.5 or earlier, continue with the subsections that follow.
578900
579901### Breaking changes
580902
581#### When migrating from Sonnet 4.5
582
5831. **Prefilling assistant messages is no longer supported**
584
585 <Warning>
586 This is a breaking change when migrating from Sonnet 4.5 or earlier.
587 </Warning>
588
589 Prefilling assistant messages returns a `400` error on Claude Sonnet 4.6 and later models, including Claude Sonnet 5. Use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs), system prompt instructions, or `output_config.format` instead.
590
591 **Common prefill use cases and migrations:**
592
593 * **Controlling output formatting** (forcing JSON/YAML output): Use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) or tools with enum fields for classification tasks.
594
595 * **Eliminating preambles** (removing "Here is..." phrases): Add direct instructions in the system prompt: "Respond directly without preamble. Do not start with phrases like 'Here is...', 'Based on...', etc."
596
597 * **Avoiding bad refusals:** Claude is much better at appropriate refusals now. Clear prompting in the user message without prefill should be sufficient.
598
599 * **Continuations** (resuming interrupted responses): Move the continuation to the user message: "Your previous response was interrupted and ended with `[previous_response]`. Continue from where you left off."
600
601 * **Context hydration / role consistency** (refreshing context in long conversations): Inject what were previously prefilled-assistant reminders into the user turn instead.
602
6032. **Tool parameter JSON escaping may differ**
604
605 <Warning>
606 This is a breaking change when migrating from Sonnet 4.5 or earlier.
607 </Warning>
608
609 JSON string escaping in tool parameters may differ from previous models. Standard JSON parsers handle this automatically, but custom string-based parsing may need updates.
610
611**Extended thinking changes:** `budget_tokens` configurations from Claude Sonnet 4.5 (`thinking: {type: "enabled", budget_tokens: N}`) are not supported on Claude Sonnet 5 and return a 400 error. Adaptive thinking is on by default, so most workloads need no `thinking` configuration at all; use the [effort parameter](https://platform.claude.com/docs/en/build-with-claude/effort) to control thinking depth. If you ran Claude Sonnet 4.5 without extended thinking, pass `thinking: {type: "disabled"}` to preserve that behavior.
612
613#### When migrating from Claude 3.x
614
6153. **Remove sampling parameters**
616
617 <Warning>
618 This is a breaking change when migrating from Claude 3.x models.
619 </Warning>
620
621 Sampling parameters (`temperature`, `top_p`, `top_k`) set to a non-default value return a 400 error on Claude Sonnet 5. Remove them from requests, and use prompting to guide the model's behavior instead.
622
6234. **Update tool versions**
624
625 <Warning>
626 This is a breaking change when migrating from Claude 3.x models.
627 </Warning>
628
629 Update to the latest tool versions (`text_editor_20250728`, `code_execution_20260521`). Remove any code using the `undo_edit` command.
630
6315. **Handle the `refusal` stop reason**
632
633 Update your application to [handle `refusal` stop reasons](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/handle-streaming-refusals).
634
6356. **Update your prompts for behavioral changes**
636
637 Claude 4 models have a more concise, direct communication style. Review [prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices) for optimization guidance.
638
639## Migrating to Claude Sonnet 5 from Claude Haiku 4.5
640
641Claude Haiku 4.5 and Claude Sonnet 5 differ more at the API level than adjacent models within one class: Claude Haiku 4.5 uses manual [extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking) (off by default), a 200k token context window, and up to 64k output tokens, while Claude Sonnet 5 runs with [adaptive thinking](https://platform.claude.com/docs/en/build-with-claude/thinking) on by default, serves a [1M token context window](https://platform.claude.com/docs/en/build-with-claude/context-windows) by default, and supports up to [128k output tokens](https://platform.claude.com/docs/en/models/overview).
642
643### Update your model name
644
645```python
646model = "claude-haiku-4-5-20251001" # Before
647model = "claude-sonnet-5" # After
903**Thinking runs on requests that omitted it.** See [Thinking runs by default](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#thinking-on-by-default) and [Turn off up-front thinking](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#turn-off-up-front-thinking).
904
905**Thinking budgets return an error.** Claude Sonnet 4.6 accepts `thinking: {"type": "enabled", "budget_tokens": N}` as a deprecated setting. Claude Sonnet 4.5 and Claude Haiku 4.5 use it for all thinking. Claude Sonnet 5.5 returns a 400 error:
906
907```text wrap
908"thinking.type.enabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.
648909```
649910
650### What changed
651
6521. **Thinking configuration:** Claude Haiku 4.5 supports manual extended thinking (`thinking: {type: "enabled", budget_tokens: N}`) and rejects `thinking: {type: "adaptive"}`. On Claude Sonnet 5, the support is reversed: adaptive thinking is on by default, and manual extended thinking returns a 400 error. Remove `thinking: {type: "enabled", budget_tokens: N}` configurations and rely on the default, or pass `thinking: {type: "disabled"}` to turn thinking off. `budget_tokens` has no direct replacement; use the [effort parameter](https://platform.claude.com/docs/en/build-with-claude/effort) to control thinking depth. Effort is not available on Claude Haiku 4.5 and defaults to `high` on Claude Sonnet 5.
653
654 The response shape changes for both kinds of Claude Haiku 4.5 request. Requests that ran without extended thinking can now return one or more `thinking` blocks before the first `text` block, so code that reads the reply by position, such as `content[0].text`, must select content blocks by their `type` field instead, and tool-use loops must pass `thinking` blocks back complete and unmodified with their tool results (see [Preserving thinking blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#preserving-thinking-blocks)). Requests that used extended thinking keep receiving `thinking` blocks, but `thinking.display` defaults to `"omitted"` on Claude Sonnet 5 rather than `"summarized"`, so those blocks arrive with an empty `thinking` field; set `display: "summarized"` to keep receiving readable summaries (see [Controlling thinking display](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display)). Thinking tokens are billed as output tokens even when the thinking text is not returned.
655
6562. **Sampling parameters removed:** `temperature` and `top_p` work on Claude Haiku 4.5 (one at a time, not both). On Claude Sonnet 5, setting `temperature`, `top_p`, or `top_k` to a non-default value returns a 400 error. Remove these parameters and use prompting to guide the model's behavior.
657
6583. **Assistant prefill removed:** Prefilling the assistant message works on Claude Haiku 4.5 but returns a 400 error on Claude Sonnet 5. Use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs), system prompt instructions, or `output_config.format` instead.
659
6604. **Larger context window and output:** Claude Sonnet 5 serves a 1M token context window by default, up from 200k tokens on Claude Haiku 4.5, and supports up to 128k output tokens, up from 64k. Claude Sonnet 5 also uses a different tokenizer, so re-run [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) rather than reusing counts measured against Claude Haiku 4.5.
661
6625. **Pricing:** Claude Haiku 4.5 is priced at $1/$5 USD per million input/output tokens. Claude Sonnet 5 is priced at $2/$10 USD per million input/output tokens. See [Claude pricing](https://platform.claude.com/docs/en/about-claude/pricing).
663
6646. **Cybersecurity safeguards:** Claude Sonnet 5 has real-time cybersecurity safeguards. Requests that involve prohibited or high-risk cybersecurity topics may be refused, returned as a successful HTTP 200 response with `stop_reason: "refusal"`. See [Real-time cyber safeguards on Claude Opus and Sonnet](https://support.claude.com/en/articles/14604842-real-time-cyber-safeguards-on-claude-opus-and-sonnet) for what the safeguards block and how legitimate security work can apply to the Cyber Verification Program.
665
666### Migration checklist
667
668* Update the model name from `claude-haiku-4-5-20251001` (or the `claude-haiku-4-5` alias) to `claude-sonnet-5`.
669* Remove `thinking: {type: "enabled", budget_tokens: N}` configuration (returns a 400 error). Adaptive thinking is on by default; pass `thinking: {type: "disabled"}` to preserve no-thinking behavior, and revisit `max_tokens` for workloads that ran without thinking.
670* Update response parsing that reads content by position, such as `content[0].text`: with thinking on, `thinking` blocks arrive before `text` blocks. Select content blocks by `type` instead, and pass `thinking` blocks back unmodified in tool-use loops; modified blocks return a 400 error.
671* If your UI displays thinking content, set `display: "summarized"`. `thinking.display` defaults to `"omitted"` on Claude Sonnet 5, so thinking blocks otherwise arrive with an empty `thinking` field. See [Controlling thinking display](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display).
672* Use the [effort parameter](https://platform.claude.com/docs/en/build-with-claude/effort) (default `high`) to control thinking depth and token spend; it is not available on Claude Haiku 4.5, so no existing setting carries over.
673* Remove `temperature` and `top_p` settings (non-default values return a 400 error on Claude Sonnet 5).
674* Remove any assistant-message prefills (they return a 400 error on Claude Sonnet 5).
675* Re-run [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) against Claude Sonnet 5, and revisit `max_tokens` limits, which you can raise up to the 128k maximum.
676* Add handling for `stop_reason: "refusal"` if your workload may touch cybersecurity topics.
677* Re-baseline cost on your typical workload before production deployment; per-token pricing differs.
911Remove the budget and set an [effort](https://platform.claude.com/docs/en/build-with-claude/effort) level. There's no fixed mapping from a budget to an effort level, so run your evaluations at two or three levels.
912
913Before (Claude Sonnet 4.6):
914
915<CodeGroup>
916 ```bash cURL
917 curl https://api.anthropic.com/v1/messages \
918 -H "x-api-key: $ANTHROPIC_API_KEY" \
919 -H "anthropic-version: 2023-06-01" \
920 -H "content-type: application/json" \
921 -d '{
922 "model": "claude-sonnet-4-6",
923 "max_tokens": 16000,
924 "thinking": {
925 "type": "enabled",
926 "budget_tokens": 10000
927 },
928 "messages": [
929 {
930 "role": "user",
931 "content": "..."
932 }
933 ]
934 }'
935 ```
936
937 ```bash CLI
938 ant messages create <<'YAML'
939 model: claude-sonnet-4-6
940 max_tokens: 16000
941 thinking:
942 type: enabled
943 budget_tokens: 10000
944 messages:
945 - role: user
946 content: "..."
947 YAML
948 ```
949
950 ```python Python
951 client.messages.create(
952 model="claude-sonnet-4-6",
953 max_tokens=16000,
954 thinking={"type": "enabled", "budget_tokens": 10000},
955 messages=[{"role": "user", "content": "..."}],
956 )
957 ```
958
959 ```typescript TypeScript
960 await client.messages.create({
961 model: "claude-sonnet-4-6",
962 max_tokens: 16000,
963 thinking: { type: "enabled", budget_tokens: 10000 },
964 messages: [{ role: "user", content: "..." }]
965 });
966 ```
967
968 ```csharp C#
969 using Anthropic;
970 using Anthropic.Models.Messages;
971
972 AnthropicClient client = new();
973
974 var parameters = new MessageCreateParams
975 {
976 Model = "claude-sonnet-4-6",
977 MaxTokens = 16000,
978 Thinking = new ThinkingConfigEnabled(budgetTokens: 10000),
979 Messages = [new() { Role = Role.User, Content = "..." }]
980 };
981
982 var response = await client.Messages.Create(parameters);
983 Console.WriteLine(response);
984 ```
985
986 ```go Go
987 client := anthropic.NewClient()
988
989 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
990 Model: "claude-sonnet-4-6",
991 MaxTokens: 16000,
992 Thinking: anthropic.ThinkingConfigParamOfEnabled(10000),
993 Messages: []anthropic.MessageParam{
994 anthropic.NewUserMessage(anthropic.NewTextBlock("...")),
995 },
996 })
997 if err != nil {
998 log.Fatal(err)
999 }
1000 fmt.Println(response)
1001 ```
1002
1003 ```java Java
1004 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
1005
1006 MessageCreateParams params = MessageCreateParams.builder()
1007 .model("claude-sonnet-4-6")
1008 .maxTokens(16000L)
1009 .enabledThinking(10000L)
1010 .addUserMessage("...")
1011 .build();
1012
1013 Message response = client.messages().create(params);
1014 IO.println(response);
1015 ```
1016
1017 ```php PHP
1018 $client = new Client();
1019
1020 $message = $client->messages->create(
1021 maxTokens: 16000,
1022 messages: [['role' => 'user', 'content' => '...']],
1023 model: 'claude-sonnet-4-6',
1024 thinking: ['type' => 'enabled', 'budget_tokens' => 10000],
1025 );
1026 ```
1027
1028 ```ruby Ruby
1029 client = Anthropic::Client.new
1030
1031 message = client.messages.create(
1032 model: "claude-sonnet-4-6",
1033 max_tokens: 16000,
1034 thinking: {
1035 type: "enabled",
1036 budget_tokens: 10000
1037 },
1038 messages: [
1039 { role: "user", content: "..." }
1040 ]
1041 )
1042 ```
1043</CodeGroup>
1044
1045After (Claude Sonnet 5.5):
1046
1047<CodeGroup>
1048 ```bash cURL
1049 curl https://api.anthropic.com/v1/messages \
1050 -H "x-api-key: $ANTHROPIC_API_KEY" \
1051 -H "anthropic-version: 2023-06-01" \
1052 -H "content-type: application/json" \
1053 -d '{
1054 "model": "claude-sonnet-5-5",
1055 "max_tokens": 16000,
1056 "thinking": {
1057 "type": "adaptive"
1058 },
1059 "output_config": {
1060 "effort": "high"
1061 },
1062 "messages": [
1063 {
1064 "role": "user",
1065 "content": "..."
1066 }
1067 ]
1068 }'
1069 ```
1070
1071 ```bash CLI
1072 ant messages create <<'YAML'
1073 model: claude-sonnet-5-5
1074 max_tokens: 16000
1075 thinking:
1076 type: adaptive
1077 output_config:
1078 effort: high
1079 messages:
1080 - role: user
1081 content: "..."
1082 YAML
1083 ```
1084
1085 ```python Python
1086 client.messages.create(
1087 model="claude-sonnet-5-5",
1088 max_tokens=16000,
1089 thinking={"type": "adaptive"},
1090 output_config={"effort": "high"}, # or "max", "xhigh", "medium", "low"
1091 messages=[{"role": "user", "content": "..."}],
1092 )
1093 ```
1094
1095 ```typescript TypeScript
1096 await client.messages.create({
1097 model: "claude-sonnet-5-5",
1098 max_tokens: 16000,
1099 thinking: { type: "adaptive" },
1100 output_config: { effort: "high" }, // or "max", "xhigh", "medium", "low"
1101 messages: [{ role: "user", content: "..." }]
1102 });
1103 ```
1104
1105 ```csharp C#
1106 using Anthropic;
1107 using Anthropic.Models.Messages;
1108
1109 AnthropicClient client = new();
1110
1111 var parameters = new MessageCreateParams
1112 {
1113 Model = "claude-sonnet-5-5",
1114 MaxTokens = 16000,
1115 Thinking = new ThinkingConfigAdaptive(),
1116 OutputConfig = new OutputConfig { Effort = Effort.High }, // or Max, Xhigh, Medium, Low
1117 Messages = [new() { Role = Role.User, Content = "..." }]
1118 };
1119
1120 var response = await client.Messages.Create(parameters);
1121 Console.WriteLine(response);
1122 ```
1123
1124 ```go Go
1125 client := anthropic.NewClient()
1126
1127 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
1128 Model: "claude-sonnet-5-5",
1129 MaxTokens: 16000,
1130 Thinking: anthropic.ThinkingConfigParamUnion{
1131 OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{},
1132 },
1133 OutputConfig: anthropic.OutputConfigParam{
1134 Effort: anthropic.OutputConfigEffortHigh, // or Max, Xhigh, Medium, Low
1135 },
1136 Messages: []anthropic.MessageParam{
1137 anthropic.NewUserMessage(anthropic.NewTextBlock("...")),
1138 },
1139 })
1140 if err != nil {
1141 log.Fatal(err)
1142 }
1143 fmt.Println(response)
1144 ```
1145
1146 ```java Java
1147 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
1148
1149 MessageCreateParams params = MessageCreateParams.builder()
1150 .model("claude-sonnet-5-5")
1151 .maxTokens(16000L)
1152 .thinking(ThinkingConfigAdaptive.builder().build())
1153 .outputConfig(OutputConfig.builder()
1154 .effort(OutputConfig.Effort.HIGH) // or MAX, XHIGH, MEDIUM, LOW
1155 .build())
1156 .addUserMessage("...")
1157 .build();
1158
1159 Message response = client.messages().create(params);
1160 IO.println(response);
1161 ```
1162
1163 ```php PHP
1164 $client = new Client();
1165
1166 $message = $client->messages->create(
1167 maxTokens: 16000,
1168 messages: [['role' => 'user', 'content' => '...']],
1169 model: 'claude-sonnet-5-5',
1170 thinking: ['type' => 'adaptive'],
1171 outputConfig: ['effort' => 'high'], // or 'max', 'xhigh', 'medium', 'low'
1172 );
1173 ```
1174
1175 ```ruby Ruby
1176 client = Anthropic::Client.new
1177
1178 message = client.messages.create(
1179 model: "claude-sonnet-5-5",
1180 max_tokens: 16000,
1181 thinking: {
1182 type: "adaptive"
1183 },
1184 output_config: {
1185 effort: "high" # or "max", "xhigh", "medium", "low"
1186 },
1187 messages: [
1188 { role: "user", content: "..." }
1189 ]
1190 )
1191 ```
1192</CodeGroup>
1193
1194**Sampling parameters return an error.** Claude Sonnet 4.6 and earlier models and Claude Haiku 4.5 accept `temperature`, `top_p`, and `top_k`. On Claude Sonnet 5.5, a non-default value returns a 400 error. Remove them.
1195
1196**Thinking text is omitted by default.** See [Handle thinking in responses](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#thinking-in-responses).
1197
1198### Other changes
1199
1200* **About 30% more tokens:** Claude Sonnet 5.5 uses Claude Sonnet 5's tokenizer. Against Claude Sonnet 4.6, Claude Sonnet 4.5, and Claude Haiku 4.5, the same text produces about 30% more tokens, depending on the content. Recount with [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting), and revisit `max_tokens` and cost.
1201* **Effort:** `xhigh` is new, and the levels are recalibrated. See [Recommended changes](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#recommended-changes).
1202* **Images:** Claude Sonnet 5.5 uses the high-resolution image tier, up to 2576 pixels on the long edge and 4,784 visual tokens per image. Claude Sonnet 4.6, Claude Sonnet 4.5, and Claude Haiku 4.5 stop at 1568 pixels and 1,568 tokens. A 2000×1500 image costs about 2.5 times as many tokens on Claude Sonnet 5.5. See [Resolution and token cost](https://platform.claude.com/docs/en/build-with-claude/vision#evaluate-image-size).
1203
1204### Migrating from Claude Sonnet 4.5 or earlier
1205
1206On Claude Sonnet 4.5, Claude Sonnet 4, or Claude 3.7 Sonnet, first apply every preceding section, then these changes.
1207
1208**Prefill returns an error.** Claude Sonnet 5.5 rejects a prefilled last assistant turn with a 400 error, as Claude Sonnet 4.6 and Claude Sonnet 5 do. Claude Sonnet 4.5, Claude Haiku 4.5, and older models accept one. The error reads:
1209
1210```text wrap
1211This model does not support assistant message prefill. The conversation must end with a user message.
1212```
1213
1214Replace each prefill according to what it was for:
1215
1216* **Output format:** use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs), or tools with enum fields for classification.
1217* **Preambles:** ask in the system prompt for a direct answer.
1218* **Unwanted refusals:** clear instructions in the user message are usually enough.
1219* **Continuations:** move them to the user message, for example "Your previous response was interrupted and ended with `[previous_response]`. Continue from where you left off."
1220* **Context reminders:** put them in the user turn.
1221
1222**Tool input escaping.** Escaping in tool call arguments can differ. Parse `input` with a standard JSON parser.
1223
1224**Computer use.** Claude Sonnet 5.5 doesn't accept `computer_20250124`. See the [computer use table](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#computer-use-toolset).
1225
1226**Effort.** Claude Sonnet 4.5 has no effort parameter. Set an effort level explicitly, as [Recommended changes](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#recommended-changes) describes.
1227
1228**Context and output.** Claude Sonnet 5.5 has a larger context window, with no beta header, and a higher output limit. See the [model page](https://platform.claude.com/docs/en/models/sonnet-5-5/overview). Remove any context-window beta header.
1229
1230**Beta headers.** Remove `interleaved-thinking-2025-05-14`, since adaptive thinking interleaves automatically. Replace `fine-grained-tool-streaming-2025-05-14` with `eager_input_streaming: true` on each tool that needs it. That header returns a 400 error alongside a computer use or browser use toolset entry. See [Fine-grained tool streaming](https://platform.claude.com/docs/en/agents-and-tools/tool-use/fine-grained-tool-streaming).
1231
1232**Structured outputs.** The `output_format` parameter is deprecated and will be removed in the future. To use it anyway, add the `structured-outputs-2025-11-13` beta header. Without it, the API returns a 400 error. Use `output_config.format` instead.
1233
1234### Migrating from Claude Sonnet 4 or earlier
1235
1236Claude Sonnet 4 is retired on the Claude API and still available on Amazon Bedrock and Google Cloud. Claude 3.7 Sonnet is retired. From either model, first apply every preceding section, then these changes:
1237
1238* **Tool versions:** Use `text_editor_20250728`, with the tool name `str_replace_based_edit_tool` and no `undo_edit` command. Use `code_execution_20260521`. See the [text editor tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/text-editor-tool) and the [code execution tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#upgrade-to-latest-tool-version).
1239* **Stop reasons:** Handle `refusal`. Claude 4.5 and later models also stop with `model_context_window_exceeded` at the context window limit. See [Handling stop reasons](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons).
1240* **Trailing newlines:** Claude 4.5 and later models keep them in tool call string parameters.
1241* **Legacy beta headers:** Remove `token-efficient-tools-2025-02-19` and `output-128k-2025-02-19`.
1242* **Prompts:** Review them against [prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices).
1243
1244## Migrating to Claude Sonnet 5.5 from Claude Haiku 4.5
1245
1246First apply every section up to and including [Migrating from Claude Sonnet 4.5 or earlier](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#migrating-from-sonnet-45), skipping the Claude Sonnet 4 subsection. Then make these changes:
1247
1248* **Model ID:** Replace `claude-haiku-4-5-20251001`, or the alias `claude-haiku-4-5`, with `claude-sonnet-5-5`.
1249* **Cost:** The price per token is higher, and the same text produces more tokens. Recount tokens and re-baseline cost. See [Claude pricing](https://platform.claude.com/docs/en/about-claude/pricing).
1250* **Prompt caching:** The minimum cacheable prompt drops from 4,096 tokens to the [Claude Sonnet 5.5 minimum](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#other-changes-from-claude-sonnet-5).
1251* **Interleaved thinking:** Adaptive thinking runs between tool calls automatically, with no beta header.
1252* **Routing:** Claude Sonnet 5.5 reads Claude Haiku 4.5 thinking blocks. A conversation that moves up keeps its reasoning. One that moves back down to Claude Haiku 4.5 drops Claude Sonnet 5.5's blocks.
6781253