使用本迁移指南从较早的 Opus 模型或 Claude Sonnet 5 迁移到 Claude Opus 5.5。启用 Claude Opus 5.5 时要注意会返回错误的请求设置、每个响应中的思考块,以及针对不同起始模型的检查清单。
本指南介绍迁移使用消息 API的代码。如果你使用 Claude 托管智能体,除了更新模型名称外,无需做其他改动。
Claude Code
让 Claude Code 为你迁移代码
/claude-api migrate this project to claude-opus-5-5
本页列出从 Claude Opus 5、Claude Opus 4.8、Claude Opus 4.7、Claude Opus 4.6 及更早的 Opus 模型或 Claude Sonnet 5迁移到 Claude Opus 5.5 时需要进行的代码变更。所有读者都需要查看每个 Claude Opus 5.5 请求必须满足的要求和处理每个响应中的思考。然后转到与你当前模型对应的章节:该章节的第一句话会指出还适用于你的其他章节。迁移检查清单按起始模型列出了所有变更。
Claude Opus 5.5 的费用低于 Claude Opus 5(每百万输入 / 输出词元分别为 $4 / $20 USD,而 Claude Opus 5 为 $5 / $25 USD;参见 定价)。有关功能支持,请参阅 Claude Opus 5.5 的新增功能。有关行为差异和针对该模型的提示词模式,请参阅Claude Opus 5.5 提示词指南。
Claude Opus 5.5 的每个请求都必须满足的要求
无论你从哪个模型迁移,发给 claude-opus-5-5 的请求都必须满足以下要求。凡是注明某个设置会被拒绝的情况,API 都会返回 400 错误。
- 模型 ID: 使用固定模型 ID
claude-opus-5-5,不带日期后缀。在 Amazon Bedrock、Claude Platform on AWS、Claude Models on Google Cloud(Anthropic 托管)、Claude Models on Google Cloud(Google 托管)和 Microsoft Foundry 上,使用各平台的模型 ID;参阅可用性。 - 思考: 不发送
thinking字段,或发送thinking: {"type": "adaptive"},两者等效:自适应思考始终开启。thinking: {"type": "disabled"}和手动设置的思考预算(thinking: {"type": "enabled", "budget_tokens": N})都会被拒绝。参见思考设置的前后对比。 - Effort: 使用effort 参数控制思考深度;这是唯一能控制思考深度的请求参数。五个档位(
low、medium、high、xhigh、max)都受支持,默认值为medium。参见 Claude Opus 5.5 的推荐 effort 档位。 - 工具选择: 将
tool_choice设为{"type": "auto"}(默认值)或{"type": "none"}。强制调用工具时使用{"type": "any"}或{"type": "tool", "name": "..."}会被拒绝。参见工具选择的前后对比。 - 采样参数: 不要提供
temperature、top_p和top_k。通过提示词引导模型行为。 - 预填充: 不要让
messages以预填充的 assistant 轮次结束,否则请求会被拒绝。改用结构化输出或系统提示词指令。 - 计算机使用: 将计算机使用声明为
computer_toolset_20260801工具集。在 Amazon Bedrock 上,computer_20251124也可使用。参阅计算机使用的破坏性变更。 - 上下文窗口: 默认使用1M 词元上下文窗口。为旧模型发送的上下文窗口 beta 请求头不会产生效果。
以下请求满足列表中的所有要求:设置了 effort,且没有 thinking 字段。示例会按类型查找文本块来输出文本,因为 thinking 块会排在前面。
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 4096,
"messages": [{
"role": "user",
"content": "Analyze the trade-offs between microservices and monolithic architectures"
}],
"output_config": {
"effort": "medium"
}
}'
ant messages create \
--model claude-opus-5-5 \
--max-tokens 4096 \
--output-config '{effort: medium}' \
--message '{role: user, content: "Analyze the trade-offs between microservices and monolithic architectures"}'
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=4096,
messages=[
{
"role": "user",
"content": "Analyze the trade-offs between microservices and monolithic architectures",
}
],
output_config={"effort": "medium"},
)
for block in response.content:
if block.type == "text":
print(block.text)
const client = new Anthropic();
const response = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 4096,
messages: [
{
role: "user",
content: "Analyze the trade-offs between microservices and monolithic architectures"
}
],
output_config: {
effort: "medium"
}
});
const textBlock = response.content.find((block) => block.type === "text");
console.log(textBlock?.text);
AnthropicClient client = new();
var parameters = new MessageCreateParams
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 4096,
Messages = [
new UserMessageParam
{
Content = "Analyze the trade-offs between microservices and monolithic architectures"
}
],
OutputConfig = new OutputConfig
{
Effort = Effort.Medium
}
};
var message = await client.Messages.Create(parameters);
foreach (var block in message.Content)
{
if (block.TryPickText(out var textBlock))
{
Console.WriteLine(textBlock.Text);
}
}
client := anthropic.NewClient()
response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 4096,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("Analyze the trade-offs between microservices and monolithic architectures")),
},
OutputConfig: anthropic.OutputConfigParam{
Effort: anthropic.OutputConfigEffortMedium,
},
})
if err != nil {
log.Fatal(err)
}
for _, block := range response.Content {
if textBlock, ok := block.AsAny().(anthropic.TextBlock); ok {
fmt.Println(textBlock.Text)
}
}
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(4096L)
.addUserMessage("Analyze the trade-offs between microservices and monolithic architectures")
.outputConfig(OutputConfig.builder()
.effort(OutputConfig.Effort.MEDIUM)
.build())
.build();
Message response = client.messages().create(params);
response.content().stream()
.flatMap(block -> block.text().stream())
.forEach(textBlock -> IO.println(textBlock.text()));
$client = new Client();
$message = $client->messages->create(
maxTokens: 4096,
messages: [
['role' => 'user', 'content' => 'Analyze the trade-offs between microservices and monolithic architectures']
],
model: Model::CLAUDE_OPUS_5_5,
outputConfig: ['effort' => 'medium'],
);
foreach ($message->content as $block) {
if ($block instanceof \Anthropic\Messages\TextBlock) {
echo $block->text, PHP_EOL;
}
}
client = Anthropic::Client.new
message = client.messages.create(
model: Anthropic::Model::CLAUDE_OPUS_5_5,
max_tokens: 4096,
messages: [
{ role: "user", content: "Analyze the trade-offs between microservices and monolithic architectures" }
],
output_config: {
effort: "medium"
}
)
message.content.each do |block|
puts block.text if block.is_a?(Anthropic::Models::TextBlock)
end
处理每个响应中的思考
Claude Opus 5.5 的每个请求都会进行思考,因此每个响应都可能以 thinking 块开头;max_tokens 限制涵盖思考和文本。如果你的代码已经开启思考,第 1 至 3 项可能已经满足:检查第 4 和第 5 项。如果代码在任何更早的模型上运行时未开启思考,则每一项都是需要进行的变更。
-
max_tokens限制涵盖思考和文本: 在 Claude Opus 4.8 及更早的 Opus 模型上,没有thinking字段的请求不会进行思考。Claude Opus 5 和 Claude Sonnet 5 接受thinking: {"type": "disabled"}。Claude Opus 5.5 的每个请求都会进行自适应思考。max_tokens仍是总输出的硬上限,涵盖思考和响应文本,因此对于之前不进行思考的工作负载,请重新检查这个值。即使思考文本不会返回给你,思考词元仍按输出词元计费,因此这类工作负载每个请求可能会产生更多输出词元。参见费用控制。若要减少思考所用的词元,请调低 effort 档位。如果使用xhigh或maxeffort,请将max_tokens设大,为模型思考和执行留出空间;可以从 64k 词元开始,再逐步调整。如果你的提示词是为关闭思考而设计的,请参阅为关闭思考而编写的提示词。 -
响应会以思考块开头: 第一个
text块之前,响应可能包含一个或多个thinking块。按位置读取回复的代码(例如content[0].text,或把第一个content_block_start事件当作文本处理的流处理器)会在此类响应上失效。应改为根据块的type字段选择内容:从type为"text"的块中读取text,处理流事件时则根据块类型分支。 -
在工具调用循环中原样返回思考块: 如果你运行工具调用循环,将工具结果返回给 API 时,要把每个 assistant 响应中的
thinking块完整、原样地传回,包括thinking字段为空的块。应按接收时的内容回传 assistant 消息,不要按类型过滤内容块或重新组装:API 会以 400 错误拒绝经过编辑、重排或部分丢弃的思考块。参见保留思考块。 -
默认不返回思考文本:
thinking.display的默认值是"omitted",因此收到的thinking块中,thinking字段为空,但会带有signature。请只将thinking字段视为用于显示的文本。若要接收可读摘要,请将thinking.display设为"summarized":thinking = { "type": "adaptive", "display": "summarized", }const thinking = { type: "adaptive", display: "summarized" };var thinking = new ThinkingConfigAdaptive { Display = Display.Summarized };thinking := anthropic.ThinkingConfigParamUnion{ OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{ Display: anthropic.ThinkingConfigAdaptiveDisplaySummarized, }, }ThinkingConfigAdaptive thinking = ThinkingConfigAdaptive.builder() .display(ThinkingConfigAdaptive.Display.SUMMARIZED) .build();$thinking = ['type' => 'adaptive', 'display' => 'summarized'];thinking = { type: "adaptive", display: "summarized" }如果你的产品会向用户流式展示推理内容,默认行为会让输出开始前出现一段长时间停顿;请将
display: "summarized"设为摘要模式,以恢复思考期间可见的进度。参见控制思考内容的显示方式。 -
工具调用之间的文本会出现在思考块中: 模型在工具调用之间写下的简短说明会作为
thinking块返回;默认显示方式下,这些块为空。参见工具调用之间的文本会作为思考块返回。
按起始模型划分的迁移清单
依次处理各组,并在遇到与你当前模型对应的组后停止:此前的每一项都适用于你。如果你当前使用 Claude Opus 5,第一组就是完整清单。如果你使用 Claude Sonnet 5,则应用第一组和最后一组。
所有起始模型
- 将模型 ID 更新为
claude-opus-5-5。 - 移除
thinking: {"type": "disabled"}和thinking: {"type": "enabled", ...};改用 effort 档位。 - 明确设置
effort:默认值为medium;Claude Opus 5 的默认值则是high。 - 将
tool_choice类型any和tool替换为auto,并采用严格工具调用或结构化输出。 - 如果使用较早版本的计算机使用工具,改为声明
computer_toolset_20260801,移除该版本的 beta 请求头,并更新智能体循环以使用工具集。在 Amazon Bedrock 上,computer_20251124也可使用。参阅计算机使用的破坏性变更。 - 如果路由器或回退可能让对话离开 Claude Opus 5.5,应预期新模型会在没有 Claude Opus 5.5 思考块的情况下运行。Claude Fable 5.1 和 Claude Mythos 5.1 在 Claude API 上会保留这些块。Claude Fable 5.2 和 Claude Mythos 5.2 在 Claude API 和 Claude Models on Google Cloud(Google 托管)上会保留这些块。Claude Opus 5.5 自身可以读取 Claude Opus 5 以及更早的 Claude Opus、Claude Sonnet、Claude Haiku 模型的思考。在 Claude API 和 Claude Models on Google Cloud(Google 托管)上,它还可以读取 Claude Sonnet 5.5 和 Claude Haiku 5.5 的思考,但不能读取 Claude Fable 或 Claude Mythos 模型的思考。
- 按
type读取内容块,并在工具调用循环中原样回传thinking块。 - 如果你的界面会显示工具调用之间的文本,请将
display设为"updates"(beta)或"summarized",并显示非空的thinking块。 - 如果你的代码会在对话过程中修改更早的轮次、
system提示词或tools,请遵循保留思考中的说明。 - 处理
stop_reason: "refusal"并配置回退。 - 在所选 effort 档位下重新确定成本和延迟基线。
- 如果你的代码关闭了思考,请重新检查
max_tokens,它涵盖思考和响应文本;使用xhigh或maxeffort 时,可以从 64k 开始。参见处理每个响应中的思考。
Claude Opus 4.8 或更早版本
- 检查此前没有
thinking字段时运行的工作负载:在 Claude Opus 5.5 上,这些请求会进行思考,而且无法关闭思考。重新检查max_tokens,它仍是总输出(思考加响应文本)的硬上限;若要减少思考,请调低effort。思考词元按输出词元计费,因此这些工作负载每个请求可能产生更多输出词元。 - 确认任何解析
thinking字段的代码都只把它视为用于显示的文本。设置display: "summarized"以接收可读摘要。 - 检查接近提示缓存最低长度的提示词:512 个词元及以上的提示词可以创建缓存条目。
- 如果你的组织有 Priority Tier 容量承诺,请单独规划容量:Claude Opus 5.5 不支持 Priority Tier。
- 如果使用
xhigh或maxeffort,请先将max_tokens至少提高到 64k。 - 对于智能体工作负载,可考虑使用任务预算和对话中途的工具变更。两者都处于 beta 阶段。
Claude Opus 4.7 或更早版本
- 在自己的评估上重新测试一轮 effort 档位,不要沿用为早期模型调好的设置。
- 移除上下文窗口 beta 请求头。
- 如果你会重建对话历史以更新指令,请改用对话中途的 system 消息。重建后,请求可能返回 400 错误,提示缓存命中也会丢失。
- 确认停止原因处理代码会在拒答时读取
stop_details。 - 如果需要快速模式(Claude Opus 4.7 不支持该模式),请检查快速模式的可用性是否列出你的平台,然后启用它:
- Microsoft Foundry: 向快速模式模型的部署发送请求。
- 其他平台: 设置
speed: "fast"。
Claude Opus 4.6 或更早版本
- 从请求参数中移除
temperature、top_p和top_k。 - 将
thinking: {"type": "enabled", "budget_tokens": N}替换为thinking: {"type": "adaptive"}并设置effort 参数,或者完全移除thinking字段;自适应思考始终开启。 - 如果你的界面会显示思考内容,请明确选择启用思考摘要。
- 在端到端的成本和延迟测试中,使用更新后的分词方式重新建立基准。
- 重新调整
max_tokens,以适应更新后的分词方式,包括压缩触发条件。 - 重新测试任何客户端词元计数估算。
- 如果应用会发送图像,请针对高分辨率图像支持重新规划预算(每张全分辨率图像最多可能多消耗约 3 倍的图像词元)。如果不需要额外的保真度,请在发送前缩小图像。
- 如果你会使用模型返回的指向坐标或边界框坐标,请移除任何比例因子换算;Claude Opus 4.7 及后续模型返回的坐标与实际图像像素为 1:1 对应。
- 查看从 Claude Opus 4.7 开始的行为变化。
- 如果你的产品用于合法的网络安全工作,请申请加入 Cyber Verification Program,以请求降低网络安全内容限制。
Claude Opus 4.5 或更早版本
- 移除 assistant 消息预填充;Claude Opus 4.6 已经会拒绝这类内容。
- 确认工具调用的 JSON 解析使用标准 JSON 解析器。
- 将
client.beta.messages.create()改为client.messages.create():自适应思考和 effort 不需要 beta 命名空间。 - 移除
effort-2025-11-24beta 请求头(effort 参数不需要该请求头)。 - 移除
fine-grained-tool-streaming-2025-05-14beta 请求头。 - 移除
interleaved-thinking-2025-05-14beta 请求头(自适应思考会自动启用交错思考)。 - 将
output_format迁移到output_config.format(如果适用)。
Claude 4.1 或更早版本
- 更新工具版本(
text_editor_20250728、code_execution_20260521)。 - 处理
refusal停止原因。 - 处理
model_context_window_exceeded停止原因。 - 确认工具字符串参数处理逻辑能处理末尾换行。
- 移除
token-efficient-tools-2025-02-19和output-128k-2025-02-19beta 请求头。 - 参照提示词最佳实践检查并更新提示词。
仅限 Claude Sonnet 5
- 如果你会重建对话历史以更新指令,请改用对话中途的 system 消息。重建后,请求可能返回 400 错误,提示缓存命中也会丢失。
- 检查接近提示缓存最低长度的提示词:512 个词元及以上的提示词可以创建缓存条目。
将 Claude Opus 5 迁移到 Claude Opus 5.5
先完成Claude Opus 5.5 的每个请求都必须满足的条件和每个响应中处理思考。无论起始模型是什么,都需要应用本节列出的变更。这些变更涉及 Claude Opus 5.5 会拒绝的请求设置,以及随之而来的响应变化。本节的检查清单对应迁移检查清单中的第一组。
更新模型名称
model = "claude-opus-5" # Before
model = "claude-opus-5-5" # After
claude-opus-5-5 是固定模型 ID,不带日期后缀,与 claude-opus-5 的命名方式相同。在 Amazon Bedrock、Claude Platform on AWS、Claude Models on Google Cloud(Anthropic 托管)、Claude Models on Google Cloud(Google 托管)和 Microsoft Foundry 上,使用各平台的模型 ID;参阅可用性。
破坏性变更
每项变更都在《Claude Opus 5.5 的新增功能》的破坏性变更一节中作了解释;本节说明每项变更对应的代码修改。
无法关闭思考
thinking: {"type": "disabled"} 和 thinking: {"type": "enabled", "budget_tokens": N} 都会返回 400 错误("thinking.type.disabled" is not supported for this model. 或 "thinking.type.enabled" is not supported for this model.)。移除 thinking 字段并选择一个 effort 档位;如果你此前为了节省词元而关闭思考,请改用较低档位。响应随后会以 thinking 块开头,因此请按 type 选择内容块,并将 thinking 块与工具结果一起原样传回。参阅无法关闭思考。
之前。在 Claude Opus 5 上,此请求可以成功,但 Claude Opus 5.5 会以 400 错误拒绝:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5",
"max_tokens": 16000,
"thinking": {"type": "disabled"},
"messages": [{"role": "user", "content": "..."}]
}'
ant messages create \
--model claude-opus-5 \
--max-tokens 16000 \
--thinking '{type: disabled}' \
--message '{role: user, content: "..."}'
client.messages.create(
model="claude-opus-5",
max_tokens=16000,
thinking={"type": "disabled"},
messages=[{"role": "user", "content": "..."}],
)
await client.messages.create({
model: "claude-opus-5",
max_tokens: 16000,
thinking: { type: "disabled" },
messages: [{ role: "user", content: "..." }]
});
await client.Messages.Create(new MessageCreateParams
{
Model = Model.ClaudeOpus5,
MaxTokens = 16000,
Thinking = new ThinkingConfigDisabled(),
Messages = [new UserMessageParam { Content = "..." }],
});
client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5,
MaxTokens: 16000,
Thinking: anthropic.ThinkingConfigParamUnion{
OfDisabled: &anthropic.ThinkingConfigDisabledParam{},
},
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("...")),
},
})
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5)
.maxTokens(16000L)
.thinking(ThinkingConfigDisabled.builder().build())
.addUserMessage("...")
.build();
client.messages().create(params);
$client->messages->create(
model: Model::CLAUDE_OPUS_5,
maxTokens: 16000,
thinking: ThinkingConfigDisabled::with(),
messages: [['role' => 'user', 'content' => '...']],
);
client.messages.create(
model: Anthropic::Model::CLAUDE_OPUS_5,
max_tokens: 16000,
thinking: Anthropic::ThinkingConfigDisabled.new,
messages: [{ role: "user", content: "..." }]
)
之后:
# thinking is always on; effort is the control
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 16000,
"output_config": {"effort": "low"},
"messages": [{"role": "user", "content": "..."}]
}'
# thinking is always on; effort is the control
ant messages create \
--model claude-opus-5-5 \
--max-tokens 16000 \
--output-config '{effort: low}' \
--message '{role: user, content: "..."}'
client.messages.create(
model="claude-opus-5-5",
max_tokens=16000,
output_config={"effort": "low"}, # thinking is always on; effort is the control
messages=[{"role": "user", "content": "..."}],
)
await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 16000,
output_config: { effort: "low" }, // thinking is always on; effort is the control
messages: [{ role: "user", content: "..." }]
});
await client.Messages.Create(new MessageCreateParams
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 16000,
OutputConfig = new() { Effort = Effort.Low }, // thinking is always on; effort is the control
Messages = [new UserMessageParam { Content = "..." }],
});
client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 16000,
OutputConfig: anthropic.OutputConfigParam{
Effort: anthropic.OutputConfigEffortLow, // thinking is always on; effort is the control
},
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("...")),
},
})
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(16000L)
// thinking is always on; effort is the control
.outputConfig(OutputConfig.builder()
.effort(OutputConfig.Effort.LOW)
.build())
.addUserMessage("...")
.build();
client.messages().create(params);
$client->messages->create(
model: Model::CLAUDE_OPUS_5_5,
maxTokens: 16000,
// thinking is always on; effort is the control
outputConfig: OutputConfig::with(effort: Effort::LOW),
messages: [['role' => 'user', 'content' => '...']],
);
client.messages.create(
model: Anthropic::Model::CLAUDE_OPUS_5_5,
max_tokens: 16000,
# thinking is always on; effort is the control
output_config: { effort: Anthropic::OutputConfig::Effort::LOW },
messages: [{ role: "user", content: "..." }]
)
不支持强制工具调用
tool_choice 的 any 和 tool 类型会返回 400 错误(tool_choice: type "tool" and "any" are not supported for this model.),包括在词元计数端点上也是如此。请将其改为 auto,并使用严格工具调用或结构化输出,同时在提示词中说明何时应调用该工具。严格工具调用支持 JSON Schema 的一个子集,因此在添加 strict: true 之前,请检查每个工具的 input_schema。架构中的每个对象都必须设置 additionalProperties: false;参阅JSON Schema 限制。参阅不支持强制工具调用。
之前。在 Claude Opus 5 上,此请求可以成功,但 Claude Opus 5.5 会以 400 错误拒绝:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5",
"max_tokens": 1024,
"tools": [{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": ["location"],
"additionalProperties": false
}
}],
"tool_choice": {"type": "tool", "name": "get_weather"},
"messages": [{"role": "user", "content": "What is the weather in Paris?"}]
}'
ant messages create <<'YAML'
model: claude-opus-5
max_tokens: 1024
tools:
- name: get_weather
description: Get the current weather in a given location
input_schema:
type: object
properties:
location:
type: string
description: The city and state, e.g. San Francisco, CA
required: [location]
additionalProperties: false
tool_choice:
type: tool
name: get_weather
messages:
- role: user
content: What is the weather in Paris?
YAML
client.messages.create(
model="claude-opus-5",
max_tokens=1024,
tools=tools,
tool_choice={"type": "tool", "name": "get_weather"},
messages=[{"role": "user", "content": "What is the weather in Paris?"}],
)
await client.messages.create({
model: "claude-opus-5",
max_tokens: 1024,
tools,
tool_choice: { type: "tool", name: "get_weather" },
messages: [{ role: "user", content: "What is the weather in Paris?" }]
});
await client.Messages.Create(new MessageCreateParams
{
Model = Model.ClaudeOpus5,
MaxTokens = 1024,
Tools = [.. tools],
ToolChoice = new ToolChoiceTool { Name = "get_weather" },
Messages = [new UserMessageParam { Content = "What is the weather in Paris?" }],
});
client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5,
MaxTokens: 1024,
Tools: tools,
ToolChoice: anthropic.ToolChoiceParamOfTool("get_weather"),
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in Paris?")),
},
})
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5)
.maxTokens(1024L)
.tools(tools)
.toolChoice(ToolChoiceTool.of("get_weather"))
.addUserMessage("What is the weather in Paris?")
.build();
client.messages().create(params);
$client->messages->create(
model: Model::CLAUDE_OPUS_5,
maxTokens: 1024,
tools: $tools,
toolChoice: ToolChoiceTool::with(name: 'get_weather'),
messages: [['role' => 'user', 'content' => 'What is the weather in Paris?']],
);
client.messages.create(
model: Anthropic::Model::CLAUDE_OPUS_5,
max_tokens: 1024,
tools: tools,
tool_choice: Anthropic::ToolChoiceTool.new(name: "get_weather"),
messages: [{ role: "user", content: "What is the weather in Paris?" }]
)
之后:
# strict tool use: every call matches the tool's input_schema
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"tools": [{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": ["location"],
"additionalProperties": false
},
"strict": true
}],
"tool_choice": {"type": "auto"},
"messages": [{
"role": "user",
"content": "What is the weather in Paris? Use the get_weather tool."
}]
}'
ant messages create <<'YAML'
model: claude-opus-5-5
max_tokens: 1024
tools:
- name: get_weather
description: Get the current weather in a given location
input_schema:
type: object
properties:
location:
type: string
description: The city and state, e.g. San Francisco, CA
required: [location]
additionalProperties: false
# strict tool use: every call matches the tool's input_schema
strict: true
tool_choice:
type: auto
messages:
- role: user
content: What is the weather in Paris? Use the get_weather tool.
YAML
client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
# strict tool use: every call matches the tool's input_schema
tools=[{**tool, "strict": True} for tool in tools],
tool_choice={"type": "auto"},
messages=[
{
"role": "user",
"content": "What is the weather in Paris? Use the get_weather tool.",
}
],
)
await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1024,
// strict tool use: every call matches the tool's input_schema
tools: tools.map((tool) => ({ ...tool, strict: true })),
tool_choice: { type: "auto" },
messages: [
{
role: "user",
content: "What is the weather in Paris? Use the get_weather tool."
}
]
});
await client.Messages.Create(new MessageCreateParams
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 1024,
// strict tool use: every call matches the tool's input_schema
Tools = [.. tools.Select(tool => tool with { Strict = true })],
ToolChoice = new ToolChoiceAuto(),
Messages =
[
new UserMessageParam { Content = "What is the weather in Paris? Use the get_weather tool." },
],
});
// strict tool use: every call matches the tool's input_schema
var strictTools []anthropic.ToolUnionParam
for _, tool := range tools {
strictTool := *tool.OfTool
strictTool.Strict = anthropic.Bool(true)
strictTools = append(strictTools, anthropic.ToolUnionParam{OfTool: &strictTool})
}
client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 1024,
Tools: strictTools,
ToolChoice: anthropic.ToolChoiceUnionParam{OfAuto: &anthropic.ToolChoiceAutoParam{}},
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.NewTextBlock("What is the weather in Paris? Use the get_weather tool."),
),
},
})
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(1024L)
// strict tool use: every call matches the tool's input_schema
.tools(tools.stream()
.map(tool -> tool.tool()
.map(customTool -> customTool.toBuilder()
.strict(true)
.build())
.map(ToolUnion::ofTool)
.orElse(tool))
.toList())
.toolChoice(ToolChoiceAuto.builder().build())
.addUserMessage("What is the weather in Paris? Use the get_weather tool.")
.build();
client.messages().create(params);
$client->messages->create(
model: Model::CLAUDE_OPUS_5_5,
maxTokens: 1024,
// strict tool use: every call matches the tool's input_schema
tools: array_map(fn (Tool $tool) => $tool->withStrict(true), $tools),
toolChoice: ToolChoiceAuto::with(),
messages: [
[
'role' => 'user',
'content' => 'What is the weather in Paris? Use the get_weather tool.',
],
],
);
client.messages.create(
model: Anthropic::Model::CLAUDE_OPUS_5_5,
max_tokens: 1024,
# strict tool use: every call matches the tool's input_schema
tools: tools.map { |tool| tool.merge(strict: true) },
tool_choice: Anthropic::ToolChoiceAuto.new,
messages: [
{ role: "user", content: "What is the weather in Paris? Use the get_weather tool." }
]
)
思考块与模型和对话绑定
请保持对话只追加(不要在对话中途编辑 system 提示词、tools 或更早的消息),使思考块通过前缀检查。Claude Code、claude.ai、Claude Managed Agents 和 Claude Agent SDK 都这样处理。对于只追加的集成,无需更改代码。
未通过前缀检查可能会,也可能不会导致 400 错误。要识别并处理这两种情况,请参阅思考块的前缀检查。
保留思考的可用性列出了适用的平台。
每个思考块还会记录生成它的模型。路由器或回退可能将对话从 Claude Opus 5.5 切换到不能读取 Claude Opus 5.5 思考块的模型。API 会在该模型看到这些块之前将其丢弃,请求仍会成功。有关哪些模型可以读取哪些块,请参阅《Claude Opus 5.5 的新增功能》中的思考块与模型和对话绑定。另请参阅保留思考。
不支持某些计算机使用工具版本
Claude Opus 5.5 通过 computer_toolset_20260801 工具集支持计算机使用。在 Amazon Bedrock 上,Claude Opus 5.5 也接受 computer_20251124 工具和 computer-use-2025-11-24 beta 请求头。对于不接受的计算机使用工具版本,例如 Claude API 上的 computer_20251124,Claude Opus 5.5 会返回 400 错误。它在任何平台上都不接受 computer_20250124。在 Claude API 上,错误消息以 'claude-opus-5-5' does not support tool types: computer_20251124. 开头,随后列出模型接受的工具类型。
使用工具集的集成无需更改。要将 computer_20251124 集成迁移到工具集,移除 beta 请求头,发送不含 name 或显示尺寸的 computer_toolset_20260801 条目。在智能体循环中,处理一个轮次中的每个成员 tool_use 块,并在每个结果中原样回传 toolset_name。从各块的 name 读取动作,而不是 input.action。从 computer_20251124 迁移列出了智能体循环的更改。
更改前。Claude Opus 5 接受此请求,Claude Opus 5.5 在 Claude API 上会以 400 错误拒绝:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "anthropic-beta: computer-use-2025-11-24" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5",
"max_tokens": 4096,
"tools": [{
"type": "computer_20251124",
"name": "computer",
"display_width_px": 1024,
"display_height_px": 768
}],
"messages": [{"role": "user", "content": "Open the display settings."}]
}'
ant beta:messages create --beta computer-use-2025-11-24 <<'YAML'
model: claude-opus-5
max_tokens: 4096
tools:
- type: computer_20251124
name: computer
display_width_px: 1024
display_height_px: 768
messages:
- role: user
content: Open the display settings.
YAML
client.beta.messages.create(
model="claude-opus-5",
max_tokens=4096,
betas=["computer-use-2025-11-24"],
tools=[
{
"type": "computer_20251124",
"name": "computer",
"display_width_px": 1024,
"display_height_px": 768,
}
],
messages=[{"role": "user", "content": "Open the display settings."}],
)
await client.beta.messages.create({
model: "claude-opus-5",
max_tokens: 4096,
betas: ["computer-use-2025-11-24"],
tools: [
{
type: "computer_20251124",
name: "computer",
display_width_px: 1024,
display_height_px: 768
}
],
messages: [{ role: "user", content: "Open the display settings." }]
});
await client.Beta.Messages.Create(new MessageCreateParams
{
Model = Model.ClaudeOpus5,
MaxTokens = 4096,
Betas = [AnthropicBeta.ComputerUse2025_11_24],
Tools =
[
new BetaToolComputerUse20251124
{
DisplayWidthPx = 1024,
DisplayHeightPx = 768,
},
],
Messages = [new BetaUserMessageParam { Content = "Open the display settings." }],
});
client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
Model: anthropic.ModelClaudeOpus5,
MaxTokens: 4096,
Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaComputerUse2025_11_24},
Tools: []anthropic.BetaToolUnionParam{
{OfComputerUseTool20251124: &anthropic.BetaToolComputerUse20251124Param{
DisplayWidthPx: 1024,
DisplayHeightPx: 768,
}},
},
Messages: []anthropic.BetaMessageParam{
anthropic.NewBetaUserMessage(anthropic.NewBetaTextBlock("Open the display settings.")),
},
})
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5)
.maxTokens(4096L)
.addBeta(AnthropicBeta.COMPUTER_USE_2025_11_24)
.addTool(BetaToolComputerUse20251124.builder()
.displayWidthPx(1024L)
.displayHeightPx(768L)
.build())
.addUserMessage("Open the display settings.")
.build();
client.beta().messages().create(params);
$client->beta->messages->create(
model: Model::CLAUDE_OPUS_5,
maxTokens: 4096,
betas: [AnthropicBeta::COMPUTER_USE_2025_11_24],
tools: [
BetaToolComputerUse20251124::with(
displayWidthPx: 1024,
displayHeightPx: 768,
),
],
messages: [['role' => 'user', 'content' => 'Open the display settings.']],
);
client.beta.messages.create(
model: Anthropic::Model::CLAUDE_OPUS_5,
max_tokens: 4096,
betas: [Anthropic::AnthropicBeta::COMPUTER_USE_2025_11_24],
tools: [
Anthropic::Beta::BetaToolComputerUse20251124.new(
name: :computer,
display_width_px: 1024,
display_height_px: 768
)
],
messages: [{ role: "user", content: "Open the display settings." }]
)
之后:
# no beta header; the toolset entry takes no name or display size
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 4096,
"tools": [{"type": "computer_toolset_20260801"}],
"messages": [{"role": "user", "content": "Open the display settings."}]
}'
# no beta header; the toolset entry takes no name or display size
ant messages create \
--model claude-opus-5-5 \
--max-tokens 4096 \
--tool '{type: computer_toolset_20260801}' \
--message '{role: user, content: "Open the display settings."}'
client.messages.create(
model="claude-opus-5-5",
max_tokens=4096,
# no beta header; the toolset entry takes no name or display size
tools=[{"type": "computer_toolset_20260801"}],
messages=[{"role": "user", "content": "Open the display settings."}],
)
await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 4096,
// no beta header; the toolset entry takes no name or display size
tools: [{ type: "computer_toolset_20260801" }],
messages: [{ role: "user", content: "Open the display settings." }]
});
await client.Messages.Create(new MessageCreateParams
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 4096,
// no beta header; the toolset entry takes no name or display size
Tools = [new ComputerToolset20260801()],
Messages = [new UserMessageParam { Content = "Open the display settings." }],
});
client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 4096,
// no beta header; the toolset entry takes no name or display size
Tools: []anthropic.ToolUnionParam{
{OfComputerToolset20260801: &anthropic.ComputerToolset20260801Param{}},
},
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("Open the display settings.")),
},
})
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(4096L)
// no beta header; the toolset entry takes no name or display size
.addTool(ComputerToolset20260801.builder().build())
.addUserMessage("Open the display settings.")
.build();
client.messages().create(params);
$client->messages->create(
model: Model::CLAUDE_OPUS_5_5,
maxTokens: 4096,
// no beta header; the toolset entry takes no name or display size
tools: [ComputerToolset20260801::with()],
messages: [['role' => 'user', 'content' => 'Open the display settings.']],
);
client.messages.create(
model: Anthropic::Model::CLAUDE_OPUS_5_5,
max_tokens: 4096,
# no beta header; the toolset entry takes no name or display size
tools: [Anthropic::ComputerToolset20260801.new],
messages: [{ role: "user", content: "Open the display settings." }]
)
工具调用之间的文本会以思考块形式返回
在 Claude Opus 5 上,模型在工具调用之间写出的文本会作为 text 块返回。在 Claude Opus 5.5 上,与 Claude Fable 5.1 一样,这些旁白会作为进度更新 thinking 块返回,每次工具调用前最多一个。当 thinking.display 保持默认值 "omitted" 时,这些块的 thinking 字段为空。请求不会失败,但如果应用程序把这些文本流式发送给用户作为进度更新,工具调用之间的进度就会中断。要恢复这些更新,请从 thinking 块中读取,并设置能够返回其文本的 display 值:"updates"(beta,使用 thinking-display-updates-2026-08-18 请求头)会返回进度更新,同时隐藏推理内容;"summarized" 则会同时返回两者,并将它们混合在一起。然后,在每个非空的 thinking 块之后、其对应的 tool_use 块之前渲染该文本,并与助手轮次的其余块一起原样传回。参阅面向用户的进度更新。
安全分类器和回退
Claude Opus 5.5 可以通过 stop_reason: "refusal" 返回拒绝响应,并附带一个 stop_details 类别。它的分类器覆盖范围比 Claude Opus 5 更广,因此除了 "cyber" 和 "reasoning_extraction" 外,还可能出现 "bio" 等 stop_details.category 值;参阅拒绝类别表。请处理拒绝响应,并配置服务端回退或自行重试(服务端回退不会重试因 "reasoning_extraction" 而被拒绝的请求;该拒绝响应会直接返回给你);参阅拒绝和回退以及防护措施拒绝。
建议的变更
- 重新测试 effort 档位。 Effort 是 Claude Opus 5.5 中唯一能控制思考深度的请求参数。默认值为
medium。Claude Opus 5 的默认值为high,因此省略effort的请求会比在 Claude Opus 5 上低一个档位运行。在质量保持不变的情况下调低档位,并对要求最高的工作调高档位。参阅Effort。 - 重新评估针对模型的提示词指令。 为 Claude Opus 5 的行为调整过的指令,可能已经不再需要;参阅Claude Opus 5.5 提示词指南。如果你之前关闭了思考,也请参阅为关闭思考而编写的提示词。
- 先在开发环境中测试,再切换生产流量。
将 Claude Opus 4.8 迁移到 Claude Opus 5.5
先完成Claude Opus 5.5 的每个请求都必须满足的条件、每个响应中处理思考,以及将 Claude Opus 5 迁移到 Claude Opus 5.5,将 claude-opus-4-8 用作要替换的模型 ID。Claude Opus 5 一节中的所有内容也适用于你,因为 Claude Opus 4.8 与 Claude Opus 5 一样:
- 接受
thinking: {"type": "disabled"}、强制工具调用和computer_20251124工具。 - 在工具调用之间以
text块返回文本。 - 默认使用
higheffort。
然后阅读发生了哪些变化,其中列出了 Claude Opus 4.8 与 Claude Opus 5 之间生效的变化。检查清单请参阅迁移检查清单中的前两组。
变化内容
- **省略思考设置的请求也会运行思考:**在 Claude Opus 4.8 上,除非你要求思考,否则思考处于关闭状态。在 Claude Opus 5.5 上,如果请求没有
thinking字段,就会运行思考,因此每个响应中处理思考中的每项内容对这段代码来说都是一项变更。如果你的代码从未发送thinking字段,那么在思考设置的变更前后示例中无需移除任何内容。 - **提示缓存的最小长度降低:**Claude Opus 5.5 的可缓存提示词最小长度为 512 个词元,而 Claude Opus 4.8 为 1,024 个词元。在 Claude Opus 4.8 上太短而无法缓存的提示词,现在可以创建缓存条目,无需更改代码。参阅提示缓存了解各模型的最小长度。
- **不支持 Priority Tier:**Claude Opus 5.5 不支持Priority Tier,而 Claude Opus 4.8 仍支持。如果你的组织承诺使用 Priority Tier,请单独规划容量。
建议的变更
以下变更是可选的,可以改善使用体验:
- **考虑使用任务预算(beta):**对于智能体工作负载,任务预算会告知模型,整个智能体循环可使用多少词元。它需要
task-budgets-2026-03-13beta 请求头。 - 考虑在对话中途更改工具(beta): 这让你可以使用
role: "system"消息在对话轮次之间添加或移除工具,并保留较早轮次的提示词缓存命中。更改tools数组会丢失这些命中。有两个 beta 请求头可以启用对话中途的工具变更。如果你的平台同时支持两者,请发送inline-tools-2026-09-15:inline-tools-2026-09-15适用于 Claude API、Claude Platform on AWS、Claude Models on Google Cloud(Anthropic 托管)和 Microsoft Foundry。mid-conversation-tool-changes-2026-07-01适用于 Claude Models on Google Cloud(Google 托管)和 Amazon Bedrock,以及inline-tools-2026-09-15所列的四个平台。它不支持在tool_addition块中定义工具。
从 Claude Opus 4.7 迁移到 Claude Opus 5.5
先完成Claude Opus 5.5 的每个请求都必须满足的要求、处理每个响应中的思考、从 Claude Opus 5 迁移到 Claude Opus 5.5,以及从 Claude Opus 4.8 迁移到 Claude Opus 5.5,将 claude-opus-4-7 用作要替换的模型 ID。这些内容也全都适用于你:与 Claude Opus 4.8 一样,Claude Opus 4.7 接受 thinking: {"type": "disabled"}、强制工具选择以及 computer_20251124 工具。它默认使用 high effort,除非你要求思考,否则不会进行思考。
然后检查以下项目。如果你的代码使用 Claude Opus 4.6 或更早版本,请继续阅读从 Claude Opus 4.6 及更早的 Opus 模型迁移到 Claude Opus 5.5。该节包含在 Claude Opus 4.7 中生效的破坏性变更。检查清单请参阅迁移检查清单的前三组。
发生了哪些变化
这些项目不会在前面章节的变更之外增加破坏性变更。替换模型 ID 后请检查这些项目。
- Effort 档位重新校准: Claude Opus 5.5 各 effort 档位分配词元的方式与 Claude Opus 4.7 不同。默认值为
medium;Claude Opus 4.7 的默认值则为high。请在自己的评估上重新测试一轮 effort 档位,不要沿用为 Claude Opus 4.7 调好的设置。参见 Effort。 - 默认使用 1M 上下文窗口: Claude Opus 5.5 默认提供完整的 1M 词元上下文窗口。如果客户端为了兼容旧模型而发送上下文窗口 beta 请求头,请将其移除。
- 对话中途的系统消息: 在支持的平台上,Claude Opus 5.5 接受紧接用户轮次之后、位于
messages数组中的role: "system"消息,但须遵守放置规则。从一开始就适用的指令使用顶层system字段。Claude Opus 4.7 会以 400 错误拒绝messages中的role: "system"。如果代码为了更新指令而重建完整消息历史,请改用系统消息。重建后,请求可能返回 400 错误,较早轮次的提示词缓存命中也会丢失。 - 拒答停止详情: 模型拒绝请求时,Claude Opus 5.5 会在
refusal停止原因之外,返回一个指出拒答类别的stop_details对象。你无法关闭它。Claude Opus 4.7 也会返回同一个对象,因此如果你的停止原因处理代码已经读取它,就无需更改。如果还没有,请参阅停止原因与回退。Claude Opus 5.5 会拒绝更多类别的请求;参见安全分类器和回退。 - 快速模式: Claude Opus 5.5 支持快速模式,可用于 Claude API 和某些云平台。Claude Opus 4.7 不支持快速模式,向其发送
speed: "fast"会导致错误。要使用快速模式,请在请求中设置speed: "fast"。在 Microsoft Foundry 上,则向快速模式模型的部署发送请求。 - 计算机使用工具集与浏览器使用工具: Claude Opus 5.5 支持以
computer_toolset_20260801工具集进行计算机使用,并支持用于网页内任务的浏览器使用工具。Claude Opus 4.7 两者都不支持。要将computer_20251124集成迁移到工具集,参阅计算机使用的破坏性变更。
从 Claude Opus 4.6 及更早的 Opus 模型迁移到 Claude Opus 5.5
先按页面顺序完成所有更早章节:Claude Opus 5.5 的每个请求都必须满足的要求、处理每个响应中的思考,以及Claude Opus 5、Claude Opus 4.8和Claude Opus 4.7对应的章节。这些内容也全都适用于你,因为 Claude Opus 4.6 及更早的 Opus 模型接受 thinking: {"type": "disabled"} 和强制工具选择,并且除非你要求思考,否则不会进行思考。Claude Opus 4.6 还接受 computer_20251124 工具,默认使用 high effort。
然后应用以下在 Claude Opus 4.7 中生效的变更。要替换的模型 ID 是 claude-opus-4-6。本节中的两个小节进一步补充了此前发生的变化,分别适用于Claude Opus 4.5 或更早版本和Claude 4.1 或更早版本。检查清单请参阅迁移检查清单,在完成与你模型对应的组后停止。
破坏性变更
-
移除扩展思考: Claude Opus 4.7 及后续模型不再支持
thinking: {"type": "enabled", "budget_tokens": N},并会返回 400 错误。请改用自适应思考(thinking: {"type": "adaptive"}),并通过 effort 参数控制思考深度。在 Claude Opus 5.5 上,自适应思考始终开启:thinking: {"type": "adaptive"}有效,且等同于完全省略thinking字段。之前(Claude Opus 4.6):curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2026-10-21" \ -H "content-type: application/json" \ -d '{ "model": "claude-opus-4-6", "max_tokens": 16000, "thinking": { "type": "enabled", "budget_tokens": 10000 }, "messages": [ { "role": "user", "content": "..." } ] }'ant messages create <<'YAML' model: claude-opus-4-6 max_tokens: 16000 thinking: type: enabled budget_tokens: 10000 messages: - role: user content: "..." YAMLclient.messages.create( model="claude-opus-4-6", max_tokens=16000, thinking={"type": "enabled", "budget_tokens": 10000}, messages=[{"role": "user", "content": "..."}], )await client.messages.create({ model: "claude-opus-4-6", max_tokens: 16000, thinking: { type: "enabled", budget_tokens: 10000 }, messages: [{ role: "user", content: "..." }] });AnthropicClient client = new(); var parameters = new MessageCreateParams { Model = Model.ClaudeOpus4_6, MaxTokens = 16000, Thinking = new ThinkingConfigEnabled(budgetTokens: 10000), Messages = [new UserMessageParam { Content = "..." }] }; var response = await client.Messages.Create(parameters); Console.WriteLine(response);client := anthropic.NewClient() response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{ Model: anthropic.ModelClaudeOpus4_6, MaxTokens: 16000, Thinking: anthropic.ThinkingConfigParamOfEnabled(10000), Messages: []anthropic.MessageParam{ anthropic.NewUserMessage(anthropic.NewTextBlock("...")), }, }) if err != nil { log.Fatal(err) } fmt.Println(response)AnthropicClient client = AnthropicOkHttpClient.fromEnv(); MessageCreateParams params = MessageCreateParams.builder() .model(Model.CLAUDE_OPUS_4_6) .maxTokens(16000L) .enabledThinking(10000L) .addUserMessage("...") .build(); Message response = client.messages().create(params); IO.println(response);$client = new Client(); $message = $client->messages->create( maxTokens: 16000, messages: [['role' => 'user', 'content' => '...']], model: Model::CLAUDE_OPUS_4_6, thinking: ['type' => 'enabled', 'budgetTokens' => 10000], );client = Anthropic::Client.new message = client.messages.create( model: Anthropic::Model::CLAUDE_OPUS_4_6, max_tokens: 16000, thinking: { type: "enabled", budget_tokens: 10000 }, messages: [ { role: "user", content: "..." } ] )之后(Claude Opus 5.5),模型 ID、
thinking和output_config行有所不同:curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2026-10-21" \ -H "content-type: application/json" \ -d '{ "model": "claude-opus-5-5", "max_tokens": 16000, "thinking": { "type": "adaptive" }, "output_config": { "effort": "high" }, "messages": [ { "role": "user", "content": "..." } ] }'ant messages create <<'YAML' model: claude-opus-5-5 max_tokens: 16000 thinking: type: adaptive output_config: effort: high messages: - role: user content: "..." YAMLclient.messages.create( model="claude-opus-5-5", max_tokens=16000, thinking={"type": "adaptive"}, output_config={"effort": "high"}, # or "max", "xhigh", "medium", "low" messages=[{"role": "user", "content": "..."}], )await client.messages.create({ model: "claude-opus-5-5", max_tokens: 16000, thinking: { type: "adaptive" }, output_config: { effort: "high" }, // or "max", "xhigh", "medium", "low" messages: [{ role: "user", content: "..." }] });AnthropicClient client = new(); var parameters = new MessageCreateParams { Model = Model.ClaudeOpus5_5, MaxTokens = 16000, Thinking = new ThinkingConfigAdaptive(), OutputConfig = new OutputConfig { Effort = Effort.High }, // or Max, Xhigh, Medium, Low Messages = [new UserMessageParam { Content = "..." }] }; var response = await client.Messages.Create(parameters); Console.WriteLine(response);client := anthropic.NewClient() response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{ Model: anthropic.ModelClaudeOpus5_5, MaxTokens: 16000, Thinking: anthropic.ThinkingConfigParamUnion{ OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{}, }, OutputConfig: anthropic.OutputConfigParam{ Effort: anthropic.OutputConfigEffortHigh, // or Max, Xhigh, Medium, Low }, Messages: []anthropic.MessageParam{ anthropic.NewUserMessage(anthropic.NewTextBlock("...")), }, }) if err != nil { log.Fatal(err) } fmt.Println(response)AnthropicClient client = AnthropicOkHttpClient.fromEnv(); MessageCreateParams params = MessageCreateParams.builder() .model(Model.CLAUDE_OPUS_5_5) .maxTokens(16000L) .thinking(ThinkingConfigAdaptive.builder().build()) .outputConfig(OutputConfig.builder() .effort(OutputConfig.Effort.HIGH) // or MAX, XHIGH, MEDIUM, LOW .build()) .addUserMessage("...") .build(); Message response = client.messages().create(params); IO.println(response);$client = new Client(); $message = $client->messages->create( maxTokens: 16000, messages: [['role' => 'user', 'content' => '...']], model: Model::CLAUDE_OPUS_5_5, thinking: ['type' => 'adaptive'], outputConfig: ['effort' => 'high'], // or 'max', 'xhigh', 'medium', 'low' );client = Anthropic::Client.new message = client.messages.create( model: Anthropic::Model::CLAUDE_OPUS_5_5, max_tokens: 16000, thinking: { type: "adaptive" }, output_config: { effort: "high" # or "max", "xhigh", "medium", "low" }, messages: [ { role: "user", content: "..." } ] )可以通过提示词和 effort 参数引导自适应思考;effort 参数取代思考预算,用于控制模型推理的程度。请在自己的评估上重新测试 effort 档位,不要把
budget_tokens的值直接换算成 effort 档位。Effort 档位表说明了各档位的适用场景,Claude Opus 5.5 的推荐 effort 档位则介绍了此模型的建议。 -
移除采样参数: 不要提供
temperature、top_p和top_k。对于 Claude Opus 5.5,推荐通过提示词引导模型行为。如果你使用temperature = 0来确保确定性,请注意它在此前的模型上也从未保证输出完全一致。 -
默认省略思考内容: Claude Opus 4.7 及后续模型仍会在响应流中返回思考块,但除非你明确选择启用,否则
thinking字段为空。这与 Claude Opus 4.6 不同:它默认会返回摘要形式的思考文本。这项变更不会显式提示。若要恢复该行为,请参阅处理每个响应中的思考中的第 4 项。 -
更新词元计数方式: Claude Opus 4.7 引入了新的分词器,后续 Opus 模型(包括 Claude Opus 5.5)也使用该分词器。它有助于提升模型在多种任务上的表现;与 Claude Opus 4.7 之前的模型相比,处理文本时可能大约会使用 1 到 1.35 倍的词元(最多约多 35%,具体取决于内容)。对 Claude Opus 5.5 调用
/v1/messages/count_tokens,返回的词元数量会不同于 Claude Opus 4.6 的结果。词元效率会因工作负载形态而异。请提高max_tokens参数,为额外用量留出余量,包括压缩触发条件;并重新测试任何在客户端估算词元或假定词元与字符比例固定的代码路径。请使用词元计数端点进行核验。提示词干预、task_budget和effort可帮助控制费用;这些控制也可能以模型智能为代价。 -
移除预填充(Claude Opus 4.6 已开始生效): 在 Claude Opus 4.6 及后续 Opus 模型(包括 Claude Opus 5.5)上,预填充 assistant 消息会返回 400 错误,因此只有从 Claude Opus 4.5 或更早版本迁移时才需要做这项变更。请改用结构化输出或系统提示词指令。
行为变化
Claude Opus 4.7 引入了不同于 Claude Opus 4.6 的行为变化,这些变化不会造成 API 破坏性变更。其中三项会影响代码或支架:
- 智能体执行轨迹中内置的进度更新: Claude Opus 4.7 会在较长的智能体执行轨迹中,定期向用户提供质量更高的进度更新。如果你添加了支架来强制生成中途状态消息(例如“每调用 3 次工具后,汇总进度”),请尝试移除它。在 Claude Opus 5.5 上,这些更新会作为
thinking块返回;使用默认的thinking.display时,这些块为空。若要接收这些更新,请参阅工具调用之间的文本会作为思考块返回。若要控制它们的长度和内容,请参阅面向用户的进度更新。 - 实时网络安全防护措施: 这些防护措施是 Claude Opus 4.7 新增的:涉及禁止或高风险主题的请求可能会被拒绝。若要开展渗透测试、漏洞研究或红队测试等合法安全工作,请申请加入 Cyber Verification Program,以请求降低对网络安全内容的限制。申请路径取决于你访问 Claude 的方式。
- 高分辨率图像支持: Claude Opus 4.7 是首个支持高分辨率图像的 Claude 模型。图像长边的最大分辨率为 2,576 像素,高于此前模型的 1,568 像素。这会提升视觉密集型工作负载的效果,在电脑操作、截图理解和文档分析中尤其有用。高分辨率支持会自动启用。需要规划两项内容:
- 全分辨率图像最多可能比此前模型多消耗约 3 倍的图像词元(每张图最多 4,784 个词元,而此前上限约为 1,600 个词元)。对于图像密集型工作负载,请重新规划
max_tokens和费用预期;如果不需要额外的保真度,也可以在发送前缩小图像。 - Claude Opus 4.7 返回的指向坐标和边界框坐标与实际图像像素为 1:1 对应,因此无需进行比例换算。 详情请参阅 Claude Opus 4.7 的高分辨率图像支持。
- 全分辨率图像最多可能比此前模型多消耗约 3 倍的图像词元(每张图最多 4,784 个词元,而此前上限约为 1,600 个词元)。对于图像密集型工作负载,请重新规划
提示词方面的差异请参阅Claude Opus 5.5 提示词指南和提示词最佳实践。
从 Claude Opus 4.5 或更早版本迁移
要从 Claude Opus 4.5、Claude Opus 4.1 或更早的模型直接迁移到 Claude Opus 5.5:
- 从本页顶部开始,按页面顺序完成各节,直到本小节。其中包括从 Claude Opus 4.6 迁移时的破坏性变更。
- 应用本小节中的变更;这些变更在 Claude Opus 4.5 到 Claude Opus 4.7 之间生效。
- 如果你使用 Claude Opus 4.1 或更早版本,请继续阅读从 Claude 4.1 或更早版本迁移。
破坏性变更
- 移除预填充已包含在从 Claude Opus 4.6 迁移时的破坏性变更中。
- 工具参数的引号处理: Claude Opus 4.6 及后续模型在工具调用参数中生成 JSON 字符串时,转义方式可能略有不同(例如对 Unicode 转义或正斜杠转义的处理不同)。如果你把工具调用的
input当作原始字符串解析,而没有使用 JSON 解析器,请检查解析逻辑。标准 JSON 解析器(例如json.loads()或JSON.parse())会自动处理这些差异。
建议的变更
第一项是 Claude Opus 5.5 的必需变更,其余为建议项。
- 迁移到自适应思考(必需): 在 Claude Opus 4.7 及后续模型上,
thinking: {"type": "enabled", "budget_tokens": N}会返回 400 错误。迁移前后的对比见从 Claude Opus 4.6 迁移时的破坏性变更中的第 1 项。此次迁移还需要将client.beta.messages.create()改为client.messages.create():自适应思考和 effort 不需要 beta SDK 命名空间或任何 beta 请求头。 - 移除 effort beta 请求头: effort 参数不需要 beta 请求头。请从请求中移除
effort-2025-11-24beta。 - 移除细粒度工具流式传输 beta 请求头: 细粒度工具流式传输不需要 beta 请求头。请从请求中移除
fine-grained-tool-streaming-2025-05-14beta。 - 移除交错思考 beta 请求头: 对于支持自适应思考的模型,该功能会自动启用交错思考。请从请求中移除
interleaved-thinking-2025-05-14beta。 - 迁移到
output_config.format: 如果你使用结构化输出,请将output_format={...}更新为output_config={"format": {...}}。output_format参数已弃用,今后会移除。如果仍要使用它,请添加structured-outputs-2025-11-13beta 请求头。否则 API 会返回 400 错误。在 Python SDK(v1.0 及更高版本)中,将 schema 字典作为output_format={...}传入会引发TypeError,因此应使用output_config。将 Pydantic 模型作为output_format=Model传给parse()或stream(),无需更改,也无需 beta 请求头,因为 SDK 会将它作为output_config发送。
从 Claude 4.1 或更早版本迁移
要从 Claude Opus 4.1 或更早的模型直接迁移到 Claude Opus 5.5:
- 从本页顶部开始,按照页面顺序完成各节,直到并包括从 Claude Opus 4.5 或更早版本迁移。
- 应用本小节中的额外变更。
额外的破坏性变更
-
移除采样参数: 参见采样参数已移除。
-
更新工具版本。 从 Claude 3.x 模型迁移时,这是一项破坏性变更。请更新到当前工具版本,并移除任何使用
undo_edit命令的代码。# Before tools = [{"type": "text_editor_20250124", "name": "str_replace_editor"}] # After tools = [{"type": "text_editor_20250728", "name": "str_replace_based_edit_tool"}]// Before const legacyTools = [{ type: "text_editor_20250124", name: "str_replace_editor" }]; // After const tools = [{ type: "text_editor_20250728", name: "str_replace_based_edit_tool" }];var parameters = new MessageCreateParams { // Before: {"type": "text_editor_20250124", "name": "str_replace_editor"} // After: Tools = [new ToolTextEditor20250728()], // ... };params := anthropic.MessageNewParams{ // Before: {"type": "text_editor_20250124", "name": "str_replace_editor"} // After: Tools: []anthropic.ToolUnionParam{ {OfTextEditor20250728: &anthropic.ToolTextEditor20250728Param{}}, }, // ... }MessageCreateParams params = MessageCreateParams.builder() // Before: {"type": "text_editor_20250124", "name": "str_replace_editor"} // After: .addTool(ToolTextEditor20250728.builder().build()) // ... .build();$message = $client->messages->create( // Before: ['type' => 'text_editor_20250124', 'name' => 'str_replace_editor'] // After: tools: [new ToolTextEditor20250728()], // ... );# Before legacy_tools = [{ type: "text_editor_20250124", name: "str_replace_editor" }] # After tools = [{ type: "text_editor_20250728", name: "str_replace_based_edit_tool" }]- 文本编辑器: 使用
text_editor_20250728和str_replace_based_edit_tool。详情请参阅文本编辑器工具文档。 - 代码执行: 升级到
code_execution_20260521。迁移说明请参阅代码执行工具。 - 计算机使用: 使用
computer_toolset_20260801工具集替换 Claude Opus 5.5 不接受的computer_20250124。在 Amazon Bedrock 上,computer_20251124也可使用。参阅计算机使用的破坏性变更。
- 文本编辑器: 使用
-
处理
refusal停止原因。 更新应用以处理refusal停止原因:response = client.messages.create(...) if response.stop_reason == "refusal": # Handle refusal appropriately passconst response = await client.messages.create(/* ... */); if (response.stop_reason === "refusal") { // Handle refusal appropriately }var response = await client.Messages.Create(...); if (response.StopReason?.Value() == StopReason.Refusal) { // Handle refusal appropriately }response, _ := client.Messages.New(ctx, params) // your existing request if response.StopReason == anthropic.StopReasonRefusal { // Handle refusal appropriately }Message response = client.messages().create(...); StopReason reason = response.stopReason().orElse(StopReason.END_TURN); if (reason.equals(StopReason.REFUSAL)) { // Handle refusal appropriately }$response = $client->messages->create(...); if ($response->stopReason === 'refusal') { // Handle refusal appropriately }response = client.messages.create(...) if response.stop_reason == :refusal # Handle refusal appropriately end -
处理
model_context_window_exceeded停止原因。 Claude 4.5 及后续模型在生成因达到上下文窗口上限而非请求的max_tokens上限而停止时,会返回model_context_window_exceeded停止原因。请更新应用以处理这个停止原因:response = client.messages.create(...) if response.stop_reason == "model_context_window_exceeded": # Handle context window limit appropriately passconst response = await client.messages.create(/* ... */); if (response.stop_reason === "model_context_window_exceeded") { // Handle context window limit appropriately }var response = await client.Messages.Create(...); if (response.StopReason?.Raw() == "model_context_window_exceeded") { // Handle context window limit appropriately }response, _ := client.Messages.New(ctx, params) // your existing request if response.StopReason == "model_context_window_exceeded" { // Handle context window limit appropriately }Message response = client.messages().create(...); StopReason reason = response.stopReason().orElse(StopReason.END_TURN); if (reason.equals(StopReason.of("model_context_window_exceeded"))) { // Handle context window limit appropriately }$response = $client->messages->create(...); if ($response->stopReason === 'model_context_window_exceeded') { // Handle context window limit appropriately }response = client.messages.create(...) if response.stop_reason == :model_context_window_exceeded # Handle context window limit appropriately end -
确认工具参数处理方式(末尾换行): Claude 4.5 及后续模型会保留工具调用字符串参数末尾的换行,而较早模型会将其去掉。如果你的工具依赖对工具调用参数进行精确字符串匹配,请确认逻辑能正确处理末尾换行。
-
根据行为变化更新提示词: Claude 4 及后续模型的沟通风格更加简洁、直接,需要明确指引。请参阅提示词最佳实践以了解优化指导。
额外的建议变更
- Beta 请求头: 移除
token-efficient-tools-2025-02-19和output-128k-2025-02-19。所有 Claude 4 及更新模型均内置高效词元工具使用,这些请求头不起作用。
从 Claude Sonnet 5 迁移到 Claude Opus 5.5
依次完成Claude Opus 5.5 的每个请求都必须满足的要求、处理每个响应中的思考,以及从 Claude Opus 5 迁移到 Claude Opus 5.5,将 claude-sonnet-5 用作要替换的模型 ID。Claude Opus 5 一节中的所有内容也适用于你,因为 Claude Sonnet 5 与 Claude Opus 5 一样:
- 默认开启思考,并且接受
thinking: {"type": "disabled"}。与 Claude Opus 5 不同,它在任意 effort 档位下都接受这个设置。 - 接受强制工具选择和
computer_20251124工具。 - 将工具调用之间的文本作为
text块返回。 - 默认使用
higheffort。
手动扩展思考、采样参数和助手预填充在 Claude Sonnet 5 和 Claude Opus 5.5 上均返回 400 错误,因此这些方面没有变化。Claude Opus 4.8、Claude Opus 4.7 和 Claude Opus 4.6 章节中的必需更改均不适用于你。
发生了哪些变化
- 对话中途的系统消息: 在支持的平台上,Claude Opus 5.5 接受紧接用户轮次之后、位于
messages数组中的role: "system"消息,但须遵守放置规则。Claude Sonnet 5 不提供此功能。如果代码为了更新指令而重建完整消息历史,请改用系统消息。重建后,请求可能返回 400 错误,较早轮次的提示词缓存命中也会丢失。 - 降低提示缓存最低长度: Claude Opus 5.5 可缓存的提示词最小长度为 512 个词元,低于 Claude Sonnet 5 的 1,024 个词元。此前因长度不足而无法在 Claude Sonnet 5 上缓存的提示词,现在无需修改代码即可创建缓存条目。各模型的最小长度请参阅提示缓存。