Claude Haiku 5.5 迁移指南:旧请求为什么报错,现有代码应该怎样改?
从 Haiku 4.5 或更早版本升级:对照请求改写、思考块解析、电脑操作工具集与会话回放规则,附升级核对清单。
Anthropic 发布了 Claude Haiku 5.5。这款轻量模型主要面向调用频繁、对费用和响应速度敏感的应用,也能作为子 Agent 配合旗舰模型处理具体任务。
它的主要功能特点与这次发布的配套更新包括:
- 高频任务更便宜:平均运行成本较 Haiku 4.5 降低约 75%,面向摘要、上下文压缩、数据库查询和分类等重复工作。
- 响应更快:在标准速度下是最快的 Claude 模型,适合实时客服等需要快速回应的场景。(开启 Fast Mode 的 Opus 更快。)
- 配合旗舰模型做编码子任务:可作为子 Agent 与 Sonnet 5.5、Opus 5.5 搭配,接手范围明确的工作。
- 首次支持可调推理投入:Haiku 系列加入 effort 设置,可以按任务调整思考投入,在费用与表现之间取舍。
- 多项能力提升:官方评测中,电脑操作、知识工作和编码成绩均高于 Haiku 4.5。
- Sonnet 缓存读取降价:单价减半;Anthropic 测算,多数 Sonnet 5.5 Agent 任务的总成本因此降低约 20%。
- SDK 增加操作支持:Python 与 TypeScript SDK 加入电脑操作和浏览器操作的 Beta 支持。
- 订阅用户获得 API 额度:伴随发布,Anthropic 将逐步向 Max 与 Team 用户推出月度 API 信用额度,可用于 Claude Platform 上的任意模型。
已经接入 Haiku 4.5 的应用,升级到 Claude Haiku 5.5 时,需要同时检查请求参数、响应解析和多轮会话。旧的思考配置、采样参数或助手消息预填充可能返回 HTTP 400;沿用按位置取答案的代码,也可能读不到正文。
这份官方迁移指南针对 Messages API (向 Claude 发送对话并接收响应的接口)。使用 Claude Managed Agents 的应用,文档要求只更新模型名;已有 API 集成则按下面的项目检查。Haiku 3.5 或 Haiku 3 用户,还要完成文末的跨代补充项。
模型的能力与价格变化可先看Haiku 5.5 发布解读。本篇集中说明现有代码怎样升级。
升级捷径:用命令行工具自动化排查
在手动翻改代码之前,如果你使用官方的 Claude Code 开发环境,可以直接借助内置的迁移技能辅助检查并修改代码:
/claude-api migrate this project to claude-haiku-5-5
这套自动化工具会检查代码库,替换模型 ID,并按需修改不兼容参数、替换助手消息预填充和调整 effort。在正式修改文件前,它会提示你确认改动范围(支持整个工作目录、子目录或指定文件列表);同时,它还能识别 Amazon Bedrock 以及 AWS 版 Claude 客户端,自动把模型 ID 调整为该平台对应的格式。
迁移技能还会调整 effort,并输出需要人工验证的清单。自动修改后,仍要核对请求、响应解析和会话处理是否符合下面的规则。
请求怎么改:模型 ID、思考配置与旧参数
这一层改动直接发生在向 Messages API 发送 HTTP 请求的 Request Body 中。其中几种旧写法在 Haiku 5.5 中会返回 HTTP 400,具体条件如下。
1. 模型 ID 替换:统一固定标识
Haiku 5.5 采用了无日期后缀的固定模型 ID,不再提供单独的最新别名(alias)。各云服务平台的对应关系如下:
| 平台环境 | 旧版写法 (Haiku 4.5) | 新版固定写法 (Haiku 5.5) | 说明 |
|---|---|---|---|
| Claude API (官方直连) | claude-haiku-4-5-20251001 或 claude-haiku-4-5 |
claude-haiku-5-5 |
固定 ID,无日期后缀 |
| Amazon Bedrock | anthropic.claude-haiku-4-5 |
anthropic.claude-haiku-5-5 |
需注意平台特有前缀 |
| Claude Platform on AWS | claude-haiku-4-5 |
claude-haiku-5-5 |
统一固定 ID |
| Google Cloud (Vertex AI) | claude-haiku-4-5@20251001 |
claude-haiku-5-5 |
去掉 @版本日期 后缀 |
| Microsoft Foundry | claude-haiku-4-5 |
claude-haiku-5-5 |
统一固定 ID |
2. 用 effort 调整思考投入
- 旧写法现象:在 Haiku 4.5 中,开启深度思考通常使用
thinking: {"type": "enabled", "budget_tokens": 8000}。如果在 Haiku 5.5 沿用此写法,API 会直接返回 HTTP 400 错误。 - 机制变动:Haiku 5.5 废弃了显式的数字 Token 预算,改为 自适应思考(Adaptive Thinking)。控制思考强度的杠杆转移到了
output_config.effort字段。 - 默认开启机制:自适应思考是默认开启的。即使你的请求体完全不写
thinking参数,模型返回的响应中也可能会包含思考块。如果你希望模型少思考以节省时间和 Token,可以把 effort 调低(如"low");投入较低时,模型思考更少,也可能在简单请求中跳过思考。 - 思考摘要展示:旧版 4.5 会返回带有摘要文本的思考内容;而在 5.5 中,默认返回的思考块内
thinking文本字段是空的,只保留signature签名字段。如果你的业务前端必须展示思考过程摘要,请求中必须显式声明thinking: {"type": "adaptive", "display": "summarized"}。 - 强制工具调用时的行为:如果在请求中配置了强制工具调用(例如
tool_choice: {"type": "any"}或指定具体工具名),Haiku 5.5 会直接输出工具调用指令,不会生成任何思考块。如果业务必须让模型“先想再调”,必须将工具调用设为auto模式tool_choice: {"type": "auto"},并在 Prompt 中明确说明触发工具的时机。
3. 删除旧的采样参数
- 旧写法现象:旧代码习惯性配置
temperature: 0.7、top_p: 0.9或自定义top_k。在 Haiku 5.5 中,这些全都会触发 HTTP 400 校验失败。 - 新版规范:直接从请求中完全删除
temperature、top_p和top_k,把输出风格和发散程度交由 Prompt 提示词来控制。 - 严格硬性校验规则:
- 如果请求一定要带
temperature,其数值必须且只能是1; - 如果请求一定要带
top_p,其数值必须且只能是默认值0.99(注意:即使传top_p: 1也会报 400); - 只要请求中出现任何
top_k值,立即报 400; - 如果在一个请求中同时携带了
temperature和top_p,哪怕都是上述合法值,依然直接报 400 错误。
- 如果请求一定要带
4. 替换助手消息预填充
- 旧写法现象:在旧版中,一些应用会在
messages数组最后塞一条未闭合的助手消息(如{"role": "assistant", "content": "{"}或{"role": "assistant", "content": "Sure, here is the answer:"}),以此引导模型输出纯 JSON 或跳过礼貌性废话。在 Haiku 5.5 中,用末尾assistant消息让模型续写,会返回 HTTP 400,即使关闭思考也一样。将请求的messages列表改为以user消息结尾。 - 针对性改造方案:
旧模式:依赖 Assistant 消息末尾引导
[User: "..."] -> [Assistant: "引导内容..."] -> 触发 400 错误!
新模式:依用途分别化解到系统提示、结构化接口或用户轮次
├─ 强约束格式(如 JSON) ────> 改用结构化输出(Structured Outputs)或带 Enum 的工具定义
├─ 消除开场废话(Preambles) ─> 移至 System Prompt 明确指令(如“请直接给出答案,禁止任何前置客套”)
├─ 断点续写(Continuations) ──> 移至 User 消息(“上轮回答在 [...] 处中断,请紧接此处继续输出”)
└─ 上下文强提醒 ──────────────> 直接追加在当前的 User 消息末尾
特殊平台限制注意:Amazon Bedrock 平台目前不支持原生结构化输出(Structured Outputs),如果在 Bedrock 上需要对输出做严格格式约束,推荐定义一个包含参数结构的工具(Tool),并引导模型调用该工具来承载结构化结果。
Token 和会话怎么处理:重算用量,保留思考块的上下文
这一层改动不一定会在单次简单调用中暴露,但会影响多轮对话系统、聊天记录存储服务、计费系统以及长文本处理的稳定性。
1. 重新计数:同一段输入约多 30% Token
- 机制变化:Haiku 5.5 使用了与 Claude 4.7 及后续模型相同的更新分词器。对于完全相同的一段文本,在 Haiku 5.5 下解析出的 Token 数量比在 Haiku 4.5 下 多出大约 30%,具体增幅取决于内容。
- 引发的生产问题:
- 输出截断:固定数量的 Token 能容纳的文字变少。沿用为 Haiku 4.5 调好的
max_tokens上限,可能截断同等长度的输出。 - 思考耗尽配额:思考 Token 同样占用
max_tokens配额。如果旧代码设了一个较小的max_tokens,模型可能在自适应思考阶段用完额度,最后给出的响应只有思考块,而没有任何实际的正文回复,停止原因返回stop_reason: "max_tokens"。 - 计费与预估偏差:凡是本地依赖 Token 计数器评估预算、计算单次调用成本的模块,要重新测算;调用 Token 计数接口时,显式传入
model: "claude-haiku-5-5",不能复用旧版 4.5 的测算数据。
- 输出截断:固定数量的 Token 能容纳的文字变少。沿用为 Haiku 4.5 调好的
2. 回传思考块时,前面的对话保持不变
- 需要排查的代码:应用可能会裁剪早先的对话,或调整
system和tools,再把包含历史思考块的消息回传。Haiku 4.5 不执行下面这项前缀检查。 - 新版严格检查:Haiku 5.5 的思考块在它前面的内容保持不变时才有效。如果回传思考块时修改了此前的
system、tools或早先的messages,请求会返回 400。文档列出的兼容情况是:创建于 2026 年 8 月 31 日 00:00 UTC 之前的账户,只有在请求设置thinking.block_binding.prefix_mismatch_behavior时才会触发这类错误。 - 改造原则:维护带思考块的会话必须采用纯追加模式(Append-Only)。保留思考块时,不修改它之前的系统提示、工具或消息。
3. 重放会话时使用生成思考块的账户
在多租户 SaaS 架构或大型中台网关中,有些架构会把用户历史会话存储在统一的数据库中,当不同租户或负载均衡器调度时,可能会用另一个 API 账号将历史上下文灌入重放。
- 请求成功但思考块被丢弃:Haiku 5.5 生成的思考块只在生成它的账户或关联账户中可用。如果用无关联的账户 B 重放账户 A 生成的思考块,API 不会抛出 400 报错,而是静默丢弃(drop)这些思考块。
- 后果:请求仍然成功,但模型看不到被丢弃的思考内容。跨账号存储重放时,应把每段会话派发到最初生成它的账户;关联账户的适用规则见官方说明。
电脑操作怎么迁移:请求声明和执行循环都要改
如果你的业务不仅是简单聊天,还涉及 Agent 工具链调用、代码执行或自动化操作,需要同步排查工具层的协议版本。
1. 换成电脑操作工具集
- 适用平台:Claude API 官方直连通道与 Google Cloud 平台。
- 废弃旧协议:旧版工具名
computer_20250124及对应的 Beta 协议头computer-use-2025-01-24在 5.5 下被彻底弃用,发起请求会收到 400 报错。 - 接入新版 Toolset:
- 移除请求头中的
computer-use-2025-01-24。 - 在
tools列表中不再声明单一 tool,而是声明工具集:{"type": "computer_toolset_20260801"}。 - 分发逻辑重构:代码中不能再依赖
input.action来判断鼠标键盘动作,而是必须检查每一个tool_use块的name以及toolset_name。 - 全量响应与回传:在同一轮对话中如果出现多个该工具集的调用块,必须在当前轮次处理每一个块,并在回传执行结果(
tool_result)时显式带上toolset_name。 - 屏幕缩放(Zoom)默认开启处理:新工具集默认开启了缩放功能。如果你的执行环境尚未实现 Zoom 功能,必须在配置中显式关闭:
"configs": {"zoom": {"enabled": false}}。 - 流式头冲突排除:如果旧请求带有
fine-grained-tool-streaming-2025-05-14请求头,必须移除。它不能与新的 toolset 并存,否则接口返回 400。
- 移除请求头中的
- 新增网页操作能力:在 Claude API 与 Google Cloud 上,Haiku 5.5 新增支持专门针对网页交互的
browser_toolset_20260801,这是 4.5 所不具备的新特性。
2. 重新规划 Priority Tier 容量
如果你的团队此前在 Claude Haiku 4.5 上购买了 Priority Tier(优先保障层) 算力承诺,请务必注意:Claude Haiku 5.5 目前不支持 Priority Tier。升级至 5.5 时需要单独规划容量。
收到响应后怎么处理:按类型取正文,识别停止原因
升级到 Haiku 5.5 后,客户端还要检查拿到响应后的解析代码。
1. 按 content 块的 type 取正文
很多旧版代码为了省事,直接写成:
# 旧写法:假定第一块就是正文
reply_text = response.content[0].text
在 Haiku 5.5 中,由于自适应思考是默认开启的,模型返回的 response.content 数组中,响应开头可能是 type: "thinking" 的思考块,真正的回答内容在后面的 type: "text" 块中。继续按索引 0 取文本,可能因该块没有 text 字段而出错,也可能漏掉后面的正文。
改造后解析逻辑:遍历 content 数组,按照 type 进行严格条件分支处理。遇到 type == "text" 拼接为用户正文;遇到 type == "thinking",与工具结果一同回传时保留原块,不修改它。
2. 处理 refusal 停止原因
Haiku 5.5 的安全分类器可以拒绝请求,模型没有服务端后备处理。客户端需要识别这类停止原因:
{ "stop_reason": "refusal" }
代码中必须新增对 "refusal" 的判断。如果旧代码只认 "end_turn"、"max_tokens"、"tool_use",一旦遭遇拒绝,业务流程可能会直接挂起或当作异常崩溃。
从 Haiku 3.5 或 Haiku 3 升级,还要检查哪些项目?
如果你的业务代码至今仍停留在 Claude Haiku 3.5 或 Haiku 3,文档列出的状态是:Haiku 3.5 已在 Claude API 与 Amazon Bedrock 退役,Haiku 3 已在 Claude API 退役;调用退役型号会失败。Google Cloud 将 Haiku 3.5 列为已弃用,仅向已有客户提供。此时在完成上述全部改造后,还需要追加以下改动:
- 模型 ID 与旧工具:
- 将
claude-3-5-haiku-20241022、claude-3-5-haiku-latest或claude-3-haiku-20240307改为claude-haiku-5-5;Google Cloud 的旧 IDclaude-3-5-haiku@20241022也改为它,Bedrock 则使用前表带平台前缀的 ID。 - 早期纯 Python 执行工具
code_execution_20250522必须升级为code_execution_20250825或更新版本。 - 文本编辑工具必须切换为
text_editor_20250728(对应内部工具名str_replace_based_edit_tool),注意该版本已经删除了undo_edit(撤销编辑)命令。
- 将
- 上下文超限识别:除了捕获
refusal外,还要在停止原因中额外处理model_context_window_exceeded。 - 工具参数的换行符容错:4.5 及后续模型会在工具调用的字符串参数末尾保留换行符
\n。后端解析工具参数时如果做了精确全等匹配,需要允许末尾换行符。 - 提示词重构:Claude 4 及后续模型的沟通风格更简洁直接,需要更具体、指向更明确的系统指令。
对照请求示例,并检查响应解析
以下示例为根据官方文档规范整理的迁移逻辑示意(用于展示参数结构变化,非实测 SDK 运行输出)。
1. 官方请求的前后对照
旧请求通过 budget_tokens 固定思考预算:
{
"model": "claude-haiku-4-5",
"max_tokens": 16000,
"thinking": { "type": "enabled", "budget_tokens": 8000 },
"messages": [{ "role": "user", "content": "..." }]
}
迁移后,模型 ID 改为 claude-haiku-5-5,思考模式改为 adaptive,并用 output_config.effort 控制投入:
{
"model": "claude-haiku-5-5",
"max_tokens": 16000,
"thinking": { "type": "adaptive" },
"output_config": { "effort": "medium" },
"messages": [{ "role": "user", "content": "..." }]
}
这里沿用文档示例的 max_tokens,实际应用仍需按任务重新计数和检查截断情况。需要思考摘要时,再加入 display: "summarized"。
2. Python 客户端响应处理示例
# 根据官方迁移规则整理的解析处理逻辑示例(教学参考)
from anthropic import Anthropic
client = Anthropic()
response = client.messages.create(
model="claude-haiku-5-5",
max_tokens=16000,
thinking={"type": "adaptive"},
output_config={"effort": "medium"},
messages=[
{"role": "user", "content": "请评估该方案的可行性并给出三条建议。"}
]
)
# 1. 容错检查:捕获安全拒绝
if response.stop_reason == "refusal":
print("请求被安全分类器拦截,未能生成回答。")
elif response.stop_reason == "max_tokens":
print("警告:Token 预算达到上限被截断(可能是思考占用过多或设置过小)。")
# 2. 只提取当前响应正文;工具循环回传思考时需保留原始块
thinking_process = []
final_answers = []
for block in response.content:
if block.type == "thinking":
# 默认模式下 block.thinking 为空字符串,仅包含 signature
# 若开启 display: "summarized" 则包含摘要文字
if hasattr(block, "thinking") and block.thinking:
thinking_process.append(block.thinking)
elif block.type == "text":
final_answers.append(block.text)
print("最终回答内容:")
print("\n".join(final_answers))
升级上线验证清单
按请求、响应、会话和工具四组检查。没有使用的功能可跳过对应项目;准备上线时,用现有任务核对改动后的结果。
请求配置
- 模型 ID:按所在平台更换型号,检查环境变量和网关路由。
- 采样参数:移除
temperature、top_p和top_k。 - 思考投入:不再发送
budget_tokens;使用自适应思考,通过 effort 调整投入。 - 消息结尾:替换末尾助手预填充;严格格式用结构化输出或工具,续写和提醒放入用户消息。
响应与输出额度
- 正文读取:按
type == "text"取内容,不再固定读取content[0]。 - 停止原因:处理
refusal;确认达到max_tokens时能够识别截断。 - 输出额度:重新计数,按任务调整
max_tokens或降低 effort,检查是否在正文生成前耗尽额度。 - 思考摘要:需要显示摘要时,显式设置
display: "summarized"。
多轮会话
- 前文保持不变:回传思考块时,保留它之前的系统提示、工具与历史消息。旧账户的兼容条件见前文。
- 账户保持关联:把会话交给生成思考块的账户或关联账户,避免派发到无关联账户。
工具执行
- 电脑操作:换成新工具集,移除旧 Beta 请求头,并检查 Zoom 支持。
- 执行循环:处理同一轮的全部工具块,按名称派发,结果回传时保留工具集标识。
Haiku 3.5 或 Haiku 3 用户还需完成前面的跨代补充项;已有 Priority Tier 容量承诺的团队,另行核对容量安排。
实操带走包
滚动查看原始 Markdown,复制后可按团队实际系统与政策修改。
正在载入 Markdown…
Claude Haiku 5.5 迁移指南:请求、会话和响应怎样改
Haiku 5.5 运行成本较 4.5 降低约 75%、速度更快并支持自适应思考,但接入代码不再兼容旧版思考预算、采样参数与助手预填充;会话回传与响应提取逻辑也必须同步改造。
Anthropic 正式发布了 Claude Haiku 5.5。这款轻量模型主要面向调用频繁、对费用和响应速度敏感的应用,也能作为高效子 Agent 配合 Sonnet 5.5 或 Opus 5.5 处理范围明确的代码与数据子任务。官方数据显示其平均运行成本较 Haiku 4.5 降低约 75%,并且在标准速度下是最快的 Claude 模型。
然而,已有Messages API集成升级到Haiku 5.5时,还需检查参数与处理逻辑。由于请求规范与思考机制更新,旧代码中常见的显式思考预算、采样参数微调(如自定义 temperature)或助手消息预填充,在 5.5 中均会直接触发 HTTP 400 校验错误;而在响应端,沿用按索引读取回答的旧习惯也会读不到正文。按实际使用的功能检查请求参数、Token用量、会话和响应处理。Claude Managed Agents只需更新模型名。开启Fast Mode的Opus速度更快。
核心机制变革:自适应思考取代固定 Token 预算
在 Haiku 4.5 中,开启思考必须在请求中指定显式的 Token 预算(例如 budget_tokens: 8000)。如果将该参数直接发送给 Haiku 5.5,接口会立即返回 HTTP 400 错误。
Haiku 5.5 废弃了显式的数字 Token 预算,改为自适应思考(Adaptive Thinking)。控制思考强度的杠杆转移到了 output_config.effort 字段。通过effort调整推理投入(如 "low"、"medium"、"high")。
自适应思考是默认开启的,即使请求体不声明 thinking 参数,响应也可能携带思考块。若希望缩减耗时与成本,可将 effort 调低(如 "low"),此时模型思考更少,简单请求甚至完全跳过思考。
默认返回的思考块仅保留 signature 签名,其 thinking 文本为空。若前端需要展示摘要,必须显式声明 display: "summarized";此外,强制工具调用(any 或指定工具)会直接跳过思考块,需要设为auto,并在提示词说明工具触发时机。
请求层改造:固定模型 ID、严格采样参数与预填充替代
向 Messages API 发送请求的第一步是清理不兼容参数。Haiku 5.5 对请求体的校验有明确兼容规则,不合规的遗留字段均会导致调用中断。
首先,Haiku 5.5 统一采用无日期后缀的固定模型 ID:官方API、Claude Platform on AWS与Microsoft 平台统一为 claude-haiku-5-5;Amazon Bedrock 需前缀 anthropic.claude-haiku-5-5;Google Cloud Vertex AI 则需去除旧版的 @版本日期 后缀。平台不再提供 latest 动态别名。
其次是采样参数的全面清理:直接从请求体中完全删除 temperature、top_p 和 top_k。Haiku 5.5 的硬性规则是:若传 temperature 必须且只能是 1;若传 top_p 必须且只能是 0.99(传 1 会报 400);任何 top_k 均直接报错;若两者同时传递,哪怕数值合法也会直接报 400 校验失败。
另一项改动是助手消息预填充的废弃。旧应用常在 messages 尾部追加一条未闭合的 assistant 消息来约束 JSON 格式或引导回答。在 Haiku 5.5 中,用末尾 assistant 消息让模型续写,会返回 HTTP 400,即使关闭思考也一样。将请求的 messages 列表改为以 user 消息结尾。
平台限制提醒:Amazon Bedrock 平台目前不支持原生 Structured Outputs。在 Bedrock 上若需严格格式化输出,推荐定义一个包含参数结构的 Tool 并引导模型调用该工具来承载结果。
Token 计数膨胀与会话上下文状态维护
进入多轮对话与生产调用阶段后,模型的隐性机制变化开始影响成本计算与系统稳定性。
Haiku 5.5 采用了新版分词器。对于完全相同的文本输入,Token数量约多30%,具体增幅取决于内容。这直接导致两个生产风险:其一是旧版配好的 max_tokens 上限容易被提前打满造成回答截断;其二是思考 Token 同样占用 max_tokens 配额。如果旧代码设了一个较小的 max_tokens,模型可能在自适应思考阶段用完额度,最后给出的响应只有思考块,而没有任何实际的正文回复,停止原因返回 stop_reason: "max_tokens"。
会话必须纯追加(Append-Only)与账号绑定
在多轮对话系统中,应用若回传带有历史思考块的消息,必须严格保证前缀一致性。Haiku 5.5 的思考块在它前面的内容保持不变时才有效。如果回传思考块时修改了此前的 system、tools 或早先的 messages,请求会返回 400。因此,带有思考块的对话上下文必须采用纯追加模式(Append-Only),保留思考块时,不修改它之前的指令、工具或消息。
多租户网关避坑:Haiku 5.5 的思考块与生成它的 API 账户严格绑定。若在分布式调度或重试网关中,用无关联的账户 B 重放账户 A 生成的思考块,API 不会报错,而是会静默丢弃(drop)这些思考块。重放时务必调度至原账户或关联账户。
历史账户说明:创建于 2026 年 8 月 31 日 00:00 UTC 之前的旧账户,仅在显式设置 thinking.block_binding.prefix_mismatch_behavior 时才会触发前缀报错;新账户则默认严格校验。
响应解析防御与工具集协议升级
客户端收到响应后的反序列化逻辑是另一处需要检查的逻辑。很多旧代码习惯直接编写 response.content[0].text 获取文本,但在 Haiku 5.5 中,由于自适应思考是默认开启的,模型返回的 response.content 数组中,响应开头可能是 type: "thinking" 的思考块,真正的回答内容在后面的 type: "text" 块中。如果继续按固定索引 0 取值,可能因该块没有text字段报错,或漏掉后面的正文。
正确的做法是:遍历 content 数组,按 block.type == "text" 拼接正文内容;若需在工具循环中回传上下文,则将 thinking 块原样保留并纯追加。同时,停止原因必须新增对 stop_reason == "refusal" 的捕获处理,因为 5.5 的安全拦截没有服务端后备处理,若不显式分支处理可能导致业务流程挂起或异常。
在 Agent 与自动化操作方面,旧版 computer_20250124 协议已废弃,需换用 {"type": "computer_toolset_20260801"} 并移除旧 Beta 请求头。分发时必须检查 toolset_name。同时注意:Haiku 5.5 目前不支持 Priority Tier(优先保障层)算力承诺,原先预购了该层级的团队需重新评估容量策略。
生产升级上线核对要点
- 按平台更换固定模型ID;Bedrock保留anthropic.前缀。
- 完全清理 temperature、top_p、top_k;废弃 budget_tokens 并改用 output_config.effort 调控思考深度。
- 终结 assistant 消息预填充,通过系统提示词强约束或原生 Structured Outputs / 工具定义替代。
- 重新计数(同文本约多30%,依内容变化),按任务调整max_tokens或降低effort 防止思考 Token 耗尽额度导致正文截断。
- 客户端按 type == "text" 过滤提取正文,并针对 stop_reason == "refusal" 建立兜底拦截。
Claude Haiku 5.5 migration guide
Switch to Claude Haiku 5.5 from earlier Haiku models with this migration guide. The guidance to enable Claude Haiku 5.5 includes the new model ID, each breaking change with the request before and after, and a checklist for each starting model.
This guide covers moving code that calls Claude Haiku 4.5 to Claude Haiku 5.5. For code that calls Claude Haiku 3.5 or Claude Haiku 3, also make the changes in Migrating to Claude Haiku 5.5 from Claude Haiku 3.5 and earlier Haiku models. To move up to a Sonnet or Opus model instead, see Upgrade between model versions. For how long Claude Haiku 4.5 stays available, see Model deprecations.
Migration checklist by starting model
Work down the groups and stop after the one that names your current model. If you are on Claude Haiku 4.5, the first group is the whole list. Each item is one change to make in your code.
Every starting model
- Replace the model ID with the Claude Haiku 5.5 ID for your platform. See Use the Claude Haiku 5.5 model ID.
- Recount your prompts, and revisit
max_tokenslimits and cost estimates, because the same text counts as more tokens. See Recount tokens. - If your requests send
thinking: {"type": "enabled", "budget_tokens": N}, changethinkingto{"type": "adaptive"}. See Configure thinking. - If your code reads the first content block as the answer, select blocks by
typeinstead. See Configure thinking. - Remove
temperature,top_p, andtop_kfrom your requests. See Remove sampling parameters. - If your requests end
messageswith an assistant turn for the model to continue, end them with a user turn instead. See Replace assistant prefill. - If you use computer use on the Claude API or Google Cloud, move from
computer_20250124to thecomputer_toolset_20260801toolset. See Move computer use to the toolset. - If you replay stored conversations through a different account, replay each one through the account that produced it. See Replay thinking blocks through the account that produced them.
- If your code changes
system,tools, or earliermessagesbetween requests in a conversation and sends thinking blocks back, keep the conversation append-only. See Keep earlier turns unchanged. - Handle
stop_reason: "refusal". Claude Haiku 5.5 runs safety classifiers that can decline a request, and it has no server-side fallback. See Safeguard refusals.
If your organization has a Priority Tier commitment on Claude Haiku 4.5, plan capacity separately: Priority Tier is not supported on Claude Haiku 5.5.
Claude Haiku 3.5 or earlier
- Replace the Claude Haiku 3.5 or Claude Haiku 3 model ID with the Claude Haiku 5.5 ID for your platform. See Migrating to Claude Haiku 5.5 from Claude Haiku 3.5 and earlier Haiku models.
- If you use the legacy
code_execution_20250522tool, move tocode_execution_20250825or later. - If you use the text editor tool, move to
text_editor_20250728. - Handle the
refusalandmodel_context_window_exceededstop reasons. - If your code matches tool call string parameters exactly, allow for trailing newlines.
- Review your prompts.
Use the Claude Haiku 5.5 model ID
Replace the Claude Haiku 4.5 model ID with the Claude Haiku 5.5 ID for your platform.
| Platform | Claude Haiku 4.5 | Claude Haiku 5.5 |
|---|---|---|
| Claude API | claude-haiku-4-5-20251001 or claude-haiku-4-5 | claude-haiku-5-5 |
| Amazon Bedrock | anthropic.claude-haiku-4-5 | anthropic.claude-haiku-5-5 |
| Claude Platform on AWS | claude-haiku-4-5 | claude-haiku-5-5 |
| Google Cloud | claude-haiku-4-5@20251001 | claude-haiku-5-5 |
| Microsoft Foundry | claude-haiku-4-5 | claude-haiku-5-5 |
claude-haiku-5-5 is a fixed model ID with no date suffix and no separate alias.
Recount tokens
Claude Haiku 5.5 uses the same newer tokenizer as Claude 4.7 and later models. As with all models that use this tokenizer, the same input text produces approximately 30% more tokens on Claude Haiku 5.5 than on Claude Haiku 4.5. The exact increase depends on the content. Requests, responses, and streaming events keep the same shape. What changes is anything you measure or budget in tokens:
usagefields and token counting results are higher for the same text.- A given number of tokens holds less text.
- A
max_tokenslimit tuned for Claude Haiku 4.5 may cut off equivalent output. - Cost estimates made from Claude Haiku 4.5's token counts need recomputing with Claude Haiku 5.5's counts and prices.
Count your prompts with model set to claude-haiku-5-5 rather than reusing counts measured on Claude Haiku 4.5.
Configure thinking
Claude Haiku 5.5 configures thinking differently from Claude Haiku 4.5. A thinking value of {"type": "enabled", "budget_tokens": N} returns a 400 error, so a request that sends it needs a new thinking value.
Before, a request to Claude Haiku 4.5 set thinking to enabled with a token budget:
After, the same request to Claude Haiku 5.5 uses adaptive thinking. The thinking value changes, and output_config.effort sets how much the model thinks:
Adaptive thinking is on by default, so a response can begin with one or more thinking blocks even when the request doesn't set thinking. Leave thinking unset or set it to {"type": "adaptive"}, and use effort as the lever: where Claude Haiku 4.5 ran without thinking, or with a small budget to save tokens, choose a lower effort level. At a lower level the model thinks less, and it can skip thinking entirely on simpler requests. For prompting guidance, see Use effort to control thinking. Select content blocks by their type field rather than by position, and pass thinking blocks back unmodified with tool results.
Thinking tokens count toward max_tokens, so a request with a small max_tokens can stop with stop_reason: "max_tokens" after a thinking block and before any text. If you set a small max_tokens for Claude Haiku 4.5, raise it to leave room for thinking, or choose a lower effort level.
By default, Claude Haiku 5.5 returns each thinking block with an empty thinking field and only a signature, where Claude Haiku 4.5 returned summarized thinking. To receive summarized thinking, set thinking: {"type": "adaptive", "display": "summarized"}.
Claude Haiku 5.5 accepts a forced tool_choice (any or a named tool), but the response starts with the tool call and has no thinking block. To let the model think before it calls a tool, use tool_choice: {"type": "auto"} and say in the prompt when to use the tool.
Remove sampling parameters
Claude Haiku 4.5 accepts temperature, top_p, and top_k. On Claude Haiku 5.5, omit all three and use prompting to guide the model's behavior instead. If a request includes temperature, it must be 1. If it includes top_p, it must be 0.99, its default. Any other temperature or top_p value returns a 400 error, including a top_p of 1. So does any top_k value, and so does a request that includes both temperature and top_p.
Replace assistant prefill
A prefill is a final assistant turn in messages that the model continues. Claude Haiku 4.5 accepts one when thinking is off. Claude Haiku 5.5 rejects it with a 400 error, even with thinking turned off. End messages with a user turn, and replace each prefill according to what it was for:
- Output format: use structured outputs, or tools with enum fields for classification. On Claude in Amazon Bedrock, which doesn't support structured outputs, use tools.
- Preambles: ask in the system prompt for a direct answer.
- 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." - Context reminders: put them in the user turn.
Move computer use to the toolset
Claude Haiku 4.5 supports computer use through the computer_20250124 tool, with the computer-use-2025-01-24 beta header. On the Claude API and Google Cloud, Claude Haiku 5.5 supports computer use only through the computer_toolset_20260801 toolset, and a request that declares computer_20250124 returns a 400 error.
To move an integration, drop the computer-use-2025-01-24 beta header and replace the tools entry with {"type": "computer_toolset_20260801"}. Then make the other request and agent-loop changes in Migrate from computer_20251124: dispatch on each member tool_use block's name and toolset_name rather than on input.action, handle every such block in a turn, and echo toolset_name on results. Zoom is on by default in the toolset; if your environment doesn't implement it, add "configs": {"zoom": {"enabled": false}}. If you send the fine-grained-tool-streaming-2025-05-14 beta header, remove it. Alongside a toolset entry, it returns a 400 error. For other platforms, see the computer use tool's Compatibility section.
On the Claude API and Google Cloud, Claude Haiku 5.5 also supports the browser use tool (browser_toolset_20260801) for tasks inside webpages. Claude Haiku 4.5 doesn't support it.
Replay thinking blocks through the account that produced them
Thinking blocks from Claude Haiku 5.5 work only in the account that produced them, or in an account linked to it. When another account sends one of these blocks, the API drops the block before the model sees it, and the request succeeds without that reasoning. This affects code that stores conversations and replays them through a different account, for example a service that serves several customers from one conversation store. Replay each conversation through the account that produced it. See Thinking blocks stay with the account that produced them.
Keep earlier turns unchanged
A Claude Haiku 5.5 thinking block stays valid only while everything sent before it is unchanged: a request that sends a thinking block back after a change to system, tools, or earlier messages returns a 400 error. Claude Haiku 4.5 doesn't run this check. Keep conversations append-only. On accounts created before August 31, 2026, 00:00 UTC, the error comes only on requests that set thinking.block_binding.prefix_mismatch_behavior. For the changes that trigger the error and what to do instead, see Who needs to change anything.
Migrating to Claude Haiku 5.5 from Claude Haiku 3.5 and earlier Haiku models
Claude Haiku 3.5 is retired on the Claude API and Amazon Bedrock, and Claude Haiku 3 is retired on the Claude API. Requests to a retired model fail. Google Cloud lists Claude Haiku 3.5 as deprecated and available only to existing customers. See Model deprecations.
From either model, first apply every preceding section, then these changes:
- Model ID: Replace
claude-3-5-haiku-20241022, its aliasclaude-3-5-haiku-latest, orclaude-3-haiku-20240307withclaude-haiku-5-5. On Google Cloud, replaceclaude-3-5-haiku@20241022withclaude-haiku-5-5. On Amazon Bedrock, use the Claude Haiku 5.5 ID from Use the Claude Haiku 5.5 model ID. - Code execution: Claude Haiku 5.5 accepts
code_execution_20250825and later versions. If you use the legacy Python-onlycode_execution_20250522, move to one of them. See Upgrade to latest tool version. - Text editor: If you use the text editor tool, move to
text_editor_20250728(tool namestr_replace_based_edit_tool), which has noundo_editcommand. See Text editor tool. - Stop reasons: Handle
refusalandmodel_context_window_exceeded. See Handling stop reasons. - Trailing newlines: Claude 4.5 and later models keep trailing newlines in tool call string parameters. If your code matches those strings exactly, allow for them.
- Prompts: Claude 4 and later models have a more concise, direct communication style and need explicit direction. Review your prompts against Prompting Claude Haiku 5.5 and prompting best practices.
