模型与多模态实用指南2026年10月21日Flatkey Team

Claude Sonnet API(2026):Sonnet 5.5 模型 ID、接入步骤、限额与代码

通过 API 调用 Claude Sonnet 5.5 所需的一切:模型 ID、密钥、可运行代码、effort 与思考设置、速率限制、成本与迁移修复。

Claude Sonnet API(2026):Sonnet 5.5 模型 ID、接入步骤、限额与代码

使用 Claude Sonnet API 的方法:先创建 Anthropic API Key,然后向 https://api.anthropic.com/v1/messages 发送请求,模型 ID 填 claude-sonnet-5-5——这是 2026 年 9 月 28 日发布的当前 Sonnet 模型。 它拥有 100 万 token 上下文窗口、最高 128K 输出、默认开启自适应思考;按 Anthropic 官方定价(核对于 2026 年 10 月 21 日),每百万输入 token 2 美元、每百万输出 token 10 美元。如果你的代码是从 Sonnet 4.6 或更早版本迁移过来的,有五个过去可用的请求参数现在会返回 400 错误,下文逐一列出。

本文面向基于 Claude 构建产品的开发者:该调用哪个 Sonnet 模型 ID、如何获取密钥、curl/Python/Node.js 可运行代码、各等级的速率限制,以及迁移中最常踩的破坏性变更。如需所有 Claude 模型的完整成本拆解,请参阅我们的 Claude API 定价指南。

可通过 API 调用的 Claude Sonnet 模型

模型 API 模型 ID 状态(2026 年 10 月 21 日) 上下文 / 最大输出 每百万 token 输入 / 输出 缓存读取
Claude Sonnet 5.5 claude-sonnet-5-5 当前版本,2026 年 9 月 28 日发布 1M / 128K $2 / $10 $0.10
Claude Sonnet 5 claude-sonnet-5 旧版(Legacy) 见模型文档 $2 / $10 $0.20
Claude Sonnet 4.6 claude-sonnet-4-6 旧版(Legacy) 见模型文档 $3 / $15 $0.30
Claude Sonnet 4.5 claude-sonnet-4-5-20250929 已弃用,2026 年 11 月 30 日下线 见模型文档 $3 / $15 $0.30

价格来自 Anthropic 定价页;模型状态来自模型总览和弃用页面;Sonnet 5.5 规格来自 Sonnet 5.5 概览,均核对于 2026 年 10 月 21 日。

该调用哪个: 新项目请使用 claude-sonnet-5-5。根据迁移指南,它的 token 单价与 Sonnet 5 相同,但缓存读取只要一半(每百万 $0.10 对 $0.20)。与 Sonnet 4.6($3 / $15)相比,Sonnet 5.5 每 token 更便宜,但要注意分词器:Anthropic 表示,同样的文本在 Sonnet 5.5 上产生的 token 比 Sonnet 4.6 多约 30%,所以请比较实际 token 数,而不是只看标价。Sonnet 4.5 用户必须在 2026 年 11 月 30 日下线前完成迁移。

Sonnet 5.5 速览

规格 数值 来源
模型 ID(Claude API、Google Cloud、Microsoft Foundry、Claude Platform on AWS) claude-sonnet-5-5 概览
Amazon Bedrock 模型 ID anthropic.claude-sonnet-5-5 概览
上下文窗口 100 万 token 概览
最大输出 128K token;Batch API 配合 beta 请求头 output-300k-2026-03-24 可达 300K 概览
输入 / 输出模态 文本和图片输入,文本输出 概览
思考 自适应,默认开启;最低档为 between_tools 概览
默认 effort high 概览
知识截止 2026 年 6 月 概览
下线时间 不早于 2027 年 9 月 28 日 概览

如何获取 Claude Sonnet API Key

  1. 登录 Claude Console,打开 API keys。
  2. 创建密钥,只复制一次,并以 ANTHROPIC_API_KEY 存入环境变量或密钥管理服务。
  3. 充值或绑定支付方式。使用等级(以及速率限制)会随消费提升,详见下文的速率限制部分。

一个密钥适用于所有 Claude 模型,并不存在单独的"Sonnet API Key"。如果你希望用一个密钥同时调用 Claude、GPT、Gemini 和 DeepSeek,可以使用 Flatkey 这类统一 API,它为所有模型签发同一个密钥(文末介绍)。

第一个 Claude Sonnet 5.5 请求

下面的请求依照 Anthropic 在 Sonnet 5.5 迁移指南中的官方示例编写:设置了 effort 级别,并避开了所有在该模型上会返回 400 的参数。

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 4096,
    "messages": [{"role": "user", "content": "Write a SQL query that finds churned customers in the last 30 days."}],
    "output_config": {"effort": "medium"}
  }'

Python,使用官方 anthropic SDK:

# pip install anthropic
import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY

response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=4096,
    messages=[{"role": "user", "content": "Write a SQL query that finds churned customers in the last 30 days."}],
    output_config={"effort": "medium"},
)

print("stop_reason:", response.stop_reason)
for block in response.content:
    if block.type == "text":  # adaptive thinking may add thinking blocks first
        print(block.text)

Node.js,使用 @anthropic-ai/sdk:

// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic(); // reads ANTHROPIC_API_KEY

const response = await client.messages.create({
  model: "claude-sonnet-5-5",
  max_tokens: 4096,
  messages: [{ role: "user", content: "Write a SQL query that finds churned customers in the last 30 days." }],
  output_config: { effort: "medium" },
});

const text = response.content.find((b) => b.type === "text");
console.log(response.stop_reason, text?.text);

请按内容块类型读取响应。开启自适应思考后,第一个内容块可能是 thinking 块,因此在 Sonnet 5.5 上直接读 response.content[0].text 并不安全。

Sonnet 5.5 的 effort 与思考设置

Sonnet 5.5 用 output_config 中的 effort 取代了固定的思考预算(effort 文档)。默认值为 high。Anthropic 的迁移指南列出了 low、medium、high、xhigh 和 max 几个级别。

你的需求 发送内容 Anthropic 文档说明
默认行为 不传,或 thinking: {"type": "adaptive"} 自适应思考默认开启
更便宜、更快的回答 output_config: {"effort": "low"} 或 "medium" effort 越低,输出 token 越少
不做前置思考 thinking: {"type": "between_tools"} 可用于 low、medium、high;在 xhigh 或 max 下返回 400
最难的问题 output_config: {"effort": "xhigh"} 或 "max" 使用自适应思考,而不是 between_tools

Sonnet 5.5 不接受 thinking: {"type": "disabled"};between_tools 是最低档设置(迁移指南)。

现在会返回 400 错误的参数

如果你从 Sonnet 4.6 或更早版本升级,请删除以下参数。这五项均列在 Anthropic 的 Sonnet 5.5 迁移指南中:

旧参数 在 Sonnet 5.5 上 替代方案
thinking: {"type": "enabled", "budget_tokens": N} 400 错误 output_config.effort
temperature、top_p、top_k 400 错误 提示词指令;effort
Assistant 预填充(最后一条消息来自 assistant) 400 错误 结构化输出或系统指令
强制 tool_choice(any 或指定工具) 400 错误 auto 加上清晰的工具说明
thinking: {"type": "disabled"} 400 错误 thinking: {"type": "between_tools"}

由于 token 数比 Sonnet 4.6 多约 30%,也请重新检查 max_tokens 和成本估算。如果升级后遇到模型 ID 报错,我们的 Claude 模型版本未找到和 Anthropic 400 错误指南涵盖了常见原因。

Claude Sonnet API 速率限制

Anthropic 在速率限制页面公布了各等级限额。截至 2026 年 10 月 21 日,Sonnet 5.5 的限额如下:

等级 每分钟请求数 每分钟输入 token 每分钟输出 token
Start 1,000 2,000,000 400,000
Build 5,000 5,000,000 1,000,000
Scale 10,000 10,000,000 2,000,000

Sonnet 5、Sonnet 4.x 和 Haiku 5.5 在各等级的数值相同。Anthropic 指出,对大多数模型而言,缓存读取的输入 token 不计入每分钟输入 token 限额,因此提示缓存既是省钱工具,也是缓解限流的工具。

Sonnet 5.5 的实际成本

2026 年 10 月 21 日官方价格,每百万 token(定价):

项目 价格
输入 $2.00
输出 $10.00
缓存写入,5 分钟 $2.50
缓存写入,1 小时 $4.00
缓存读取 $0.10
Batch API 输入 / 输出 $1.00 / $5.00
仅美国境内推理(inference_geo) 所有 token 价格 ×1.1

示例测算:一个客服助手每月处理 50,000 次请求,每次包含 3,000 token 的已缓存系统提示、500 个新输入 token 和 400 个输出 token。缓存读取:1.5 亿 token × $0.10 = $15。新输入:2,500 万 × $2 = $50。输出:2,000 万 × $10 = $200。合计每月约 $265,未计一次性的缓存写入费用。输出占大头,所以调整 effort 比优化输入更重要。如需逐个模型对比,请参阅 Claude API 定价和 Claude 与 GPT 的 API 路由。

用 OpenAI SDK 调用 Claude Sonnet

Anthropic 在 https://api.anthropic.com/v1/ 提供兼容 OpenAI 的端点,但其 OpenAI SDK 兼容性页面说明,它主要用于测试和对比,不适合大多数生产场景:函数调用的 strict 参数会被忽略,response_format 会被忽略,而且不支持提示缓存。在生产环境中使用 Sonnet 5.5,请用上文的原生 Messages API。我们的 Claude API 与 OpenAI SDK 兼容性一文对各种方案有详细介绍。

一个密钥调用 Sonnet 和其他模型:Flatkey

如果你的产品同时调用 GPT、Gemini 或 DeepSeek,Flatkey 让你用一个密钥、一个预付余额覆盖所有模型。2026 年 10 月 21 日,Flatkey 的 Claude Sonnet 5.5 模型页标价为每百万 token 输入 $1.60 / 输出 $8.00,比 Anthropic 的 $2 / $10 低 20%;Sonnet 4.6 为 $2.40 / $12.00。根据 Flatkey 的 Anthropic SDK 指南,只需把 Anthropic SDK 的 base URL 改为 https://router.flatkey.ai(不带 /v1)即可:

import anthropic

client = anthropic.Anthropic(api_key="YOUR_FLATKEY_KEY", base_url="https://router.flatkey.ai")
msg = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Draft a release note for v2.3."}],
)
print(next(b.text for b in msg.content if b.type == "text"))

Claude Code 的配置方法请见 Claude Code API 路由设置。如果你需要只在 Anthropic 官方平台提供的功能或合同(例如发布当天的特定 beta 请求头或企业协议),请直接使用 Anthropic。

常见问题

Claude Sonnet API 的模型名称是什么?

截至 2026 年 10 月 21 日,当前模型 ID 在 Claude API、Google Cloud、Microsoft Foundry 和 Claude Platform on AWS 上是 claude-sonnet-5-5,在 Amazon Bedrock 上是 anthropic.claude-sonnet-5-5。较早的 ID 包括 claude-sonnet-5 和 claude-sonnet-4-6。

Claude Sonnet API 多少钱?

根据 2026 年 10 月 21 日核对的 Anthropic 定价页,Claude Sonnet 5.5 每百万输入 token $2、每百万输出 token $10,缓存读取 $0.10,Batch API 半价($1 / $5)。

Claude Sonnet API 免费吗?

不免费。Anthropic API 按 token 计费,Sonnet 没有免费 API 额度。面向消费者的 Claude 应用有自己的免费和付费套餐,与 API 计费相互独立。如需其他厂商的免费选项,请参阅我们的免费 LLM API 指南。

Claude Sonnet 5.5 的上下文窗口有多大?

100 万 token,每次请求最多输出 128K token;在 Message Batches API 上配合 output-300k-2026-03-24 beta 请求头可达 300K。

升级后 Sonnet 请求为什么返回 400 错误?

Sonnet 5.5 会拒绝思考预算、temperature/top_p/top_k、assistant 预填充、强制工具选择以及 thinking: {"type": "disabled"}。删除这些参数,改用 output_config.effort 或 thinking: {"type": "between_tools"}。

还能使用 Claude Sonnet 5 API 吗?

可以。claude-sonnet-5 仍可作为旧版模型调用,价格为每百万 token $2 / $10,缓存读取 $0.20。Sonnet 5.5 的 token 单价相同、缓存读取减半,因此新项目更适合默认选它。

资料来源