Claude Sonnet 5 offers the best combination of speed and intelligence in the Claude model family. It builds on Claude Sonnet 4.6.
Claude Sonnet 5 is a drop-in upgrade for Claude Sonnet 4.6, priced at $2/$10 USD per million input/output tokens; see Pricing for details. There are two breaking API changes for code already running on Claude Sonnet 4.6: manual extended thinking (thinking: {type: "enabled", budget_tokens: N}) and sampling parameters (temperature, top_p, top_k) set to non-default values are no longer accepted and return a 400 error. Use adaptive thinking with the effort parameter instead. Claude Sonnet 5 supports the same set of features as Claude Sonnet 4.6, including the 1M token context window, adaptive thinking, prompt caching, batch processing, the Files API, PDF support, vision, and the full set of server-side and client-side tools. On the Claude API, Claude Sonnet 5 also supports computer use as the stable computer_toolset_20260801 toolset and the 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. Priority Tier is not available on Claude Sonnet 5. Claude Sonnet 5 also uses a new tokenizer.
# Sonnet migration
model = "claude-sonnet-4-6" # Before
model = "claude-sonnet-5" # AfterItems 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.
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 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 versus Claude Sonnet 4.6's $3/$15 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.
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.
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, system prompt instructions, or output_config.format instead.
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. 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 (default high) to control thinking depth.
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=16000,
thinking={"type": "adaptive", "display": "summarized"},
output_config={"effort": "high"},
messages=[
{
"role": "user",
"content": "Are there an infinite number of prime numbers such that n mod 4 == 3?",
}
],
)
# The response contains summarized thinking blocks and text blocks
for block in response.content:
match block.type:
case "thinking":
print(f"\nThinking summary: {block.thinking}")
case "text":
print(f"\nResponse: {block.text}")Sampling parameters removed: Sampling parameters (temperature, top_p, top_k) set to a non-default value are not accepted and return a 400 error.
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 for what the safeguards block and how legitimate security work can apply to the Cyber Verification Program.
claude-sonnet-4-6 to claude-sonnet-5.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.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 to control depth.temperature, top_p, and top_k parameters set to non-default values (they return a 400 error on Claude Sonnet 5).stop_reason: "refusal" if your workload may touch cybersecurity topics.max_tokens for workloads that previously ran without thinking.If 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 changes plus the changes in this section.
Prefilling assistant messages is no longer supported
Prefilling assistant messages returns a 400 error on Claude Sonnet 4.6 and later models, including Claude Sonnet 5. Use structured outputs, system prompt instructions, or output_config.format instead.
Common prefill use cases and migrations:
Controlling output formatting (forcing JSON/YAML output): Use structured outputs or tools with enum fields for classification tasks.
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."
Avoiding bad refusals: Claude is much better at appropriate refusals now. Clear prompting in the user message without prefill should be sufficient.
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."
Context hydration / role consistency (refreshing context in long conversations): Inject what were previously prefilled-assistant reminders into the user turn instead.
Tool parameter JSON escaping may differ
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.
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 to control thinking depth. If you ran Claude Sonnet 4.5 without extended thinking, pass thinking: {type: "disabled"} to preserve that behavior.
Remove sampling parameters
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.
Update tool versions
Update to the latest tool versions (text_editor_20250728, code_execution_20260521). Remove any code using the undo_edit command.
Handle the refusal stop reason
Update your application to handle refusal stop reasons.
Update your prompts for behavioral changes
Claude 4 models have a more concise, direct communication style. Review prompting best practices for optimization guidance.
Claude 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 (off by default), a 200k token context window, and up to 64k output tokens, while Claude Sonnet 5 runs with adaptive thinking on by default, serves a 1M token context window by default, and supports up to 128k output tokens.
model = "claude-haiku-4-5-20251001" # Before
model = "claude-sonnet-5" # AfterThinking 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 to control thinking depth. Effort is not available on Claude Haiku 4.5 and defaults to high on Claude Sonnet 5.
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.
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, system prompt instructions, or output_config.format instead.
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 rather than reusing counts measured against Claude Haiku 4.5.
Pricing: Claude Haiku 4.5 is priced at $1/$5 per million input/output tokens. Claude Sonnet 5 is priced at $2/$10 per million input/output tokens. See Claude pricing.
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 for what the safeguards block and how legitimate security work can apply to the Cyber Verification Program.
claude-haiku-4-5-20251001 (or the claude-haiku-4-5 alias) to claude-sonnet-5.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.high) to control thinking depth and token spend; it is not available on Claude Haiku 4.5, so no existing setting carries over.temperature and top_p settings (non-default values return a 400 error on Claude Sonnet 5).max_tokens limits, which you can raise up to the 128k maximum.stop_reason: "refusal" if your workload may touch cybersecurity topics.Was this page helpful?