> For AI agents: the complete documentation index is available at https://little-butterfly-9bfe.sentia389.workers.dev/llms.txt, the full documentation bundle is available at https://little-butterfly-9bfe.sentia389.workers.dev/llms-full.txt.

# Claude Sonnet

Sonnet 适合日常编码、数据分析与工具调用。上下文和输出上限为 Claude API 规格。

| 型号         | Claude API ID       | 官方发布日期     | 上下文 / 同步 Messages 最大输出 |
| ---------- | ------------------- | ---------- | ---------------------- |
| Sonnet 5.5 | `claude-sonnet-5-5` | 2026-09-28 | 1M / 128K tokens       |
| Sonnet 5   | `claude-sonnet-5`   | 2026-06-30 | 1M / 128K tokens       |
| Sonnet 4.6 | `claude-sonnet-4-6` | 2026-02-17 | 1M / 128K tokens       |

## Messages 关键参数

| 字段                       | 类型       | 限制与版本区别                                                                                                        |
| ------------------------ | -------- | -------------------------------------------------------------------------------------------------------------- |
| `model`、`messages`       | 字符串、对象数组 | 两者必填。在 `messages` 中传 `user`、`assistant` 对话。                                                                    |
| `max_tokens`             | 整数，必填    | 普通生成请求使用正值。同步输出最多 128K tokens，包含 thinking。                                                                     |
| `thinking.type`          | 字符串      | 5.5 和 5 默认自适应。5.5 用 `between_tools` 跳过首次回答前的 thinking，并保留工具调用间的进度更新。5 可用 `disabled`。4.6 默认关闭，可用 `adaptive` 开启。 |
| `thinking.budget_tokens` | 整数       | 4.6 的手动模式已弃用。5.5 和 5 拒绝手动预算。                                                                                   |
| `output_config.effort`   | 字符串      | 所列版本均支持 `low`、`medium`、`high`、`max`，默认 `high`。5.5 和 5 也支持 `xhigh`。                                             |
| `stream`                 | 布尔值      | 缺省返回单条消息。设为 `true` 时返回服务端发送事件（SSE）。                                                                            |

5.5 的 `between_tools` 只与 `low`、`medium`、`high` 兼容，且 `thinking` 对象只能包含 `type`。5.5 和 5 省略 `temperature`、`top_p`、`top_k`。

Anthropic 已弃用 Sonnet 4.5，Claude API 的停用日期为 2026 年 11 月 30 日，官方建议迁移至 Sonnet 5.5。参见[停用时间表](https://platform.claude.com/docs/en/about-claude/model-deprecations#2026-09-30-claude-sonnet-45-model)和 [Sonnet 5.5 迁移指南](https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide#migrating-from-sonnet-45)。

## 流式请求与响应

下面通过 routerlio 发送 Messages 请求，使用 Sonnet 5.5 的 `between_tools`，并给 cURL 添加 `-N` 以随事件读取回答。接入步骤见[快速接入](https://little-butterfly-9bfe.sentia389.workers.dev/start/index.md)。

```bash
ROUTERLIO_MODEL='claude-sonnet-5-5'

curl -sS -N \
  --url "${ROUTERLIO_BASE_URL:?请设置 ROUTERLIO_BASE_URL}/v1/messages" \
  --header "x-api-key: ${ROUTERLIO_API_KEY:?请设置 ROUTERLIO_API_KEY}" \
  --header 'anthropic-version: 2023-06-01' \
  --header 'Content-Type: application/json' \
  --data-binary @- <<JSON
{
  "model": "${ROUTERLIO_MODEL}",
  "max_tokens": 1024,
  "stream": true,
  "thinking": {
    "type": "between_tools"
  },
  "messages": [
    {
      "role": "user",
      "content": "用一句话解释什么是缓存。"
    }
  ]
}
JSON
```

一个 `content_block_delta` 事件的 `data` 解码后如下。按 `index` 拼接同一内容块的 `delta.text`。

```json
{
  "type": "content_block_delta",
  "index": 0,
  "delta": {
    "type": "text_delta",
    "text": "缓存保存可复用的数据，以缩短下一次读取的时间。"
  }
}
```

消息接近结束时，从 `message_delta` 读取停止原因。以下为该事件的数据示例，随后收到 `message_stop` 表示整条消息已结束。

```json
{
  "type": "message_delta",
  "delta": {
    "stop_reason": "end_turn",
    "stop_sequence": null
  },
  "usage": {
    "output_tokens": 28
  }
}
```

## 排错

- 5.5 收到 `thinking.type.disabled` 或关闭 thinking 时 effort 超限的错误，改用 `between_tools` 并将 effort 限定在 `high` 或更低。需要 `xhigh` 或 `max` 时使用自适应模式。
- 5.5 或 5 拒绝 `budget_tokens` 时，移除手动预算，使用 `output_config.effort` 调整 thinking。HTTP `200` 后流仍可能提前结束，核对 `error` 事件和完成信号。参见 [Thinking 与 effort](https://little-butterfly-9bfe.sentia389.workers.dev/models/anthropic/thinking.md)和[错误排查](https://little-butterfly-9bfe.sentia389.workers.dev/troubleshooting/index.md)。

## 官方资料

- Claude 型号页 [Sonnet 5.5](https://platform.claude.com/docs/en/models/sonnet-5-5/overview)、[Sonnet 5](https://platform.claude.com/docs/en/models/sonnet-5/overview)、[Sonnet 4.6](https://platform.claude.com/docs/en/models/sonnet-4-6/overview)。
- Anthropic 的[创建消息](https://platform.claude.com/docs/en/api/messages/create)、[流式消息](https://platform.claude.com/docs/en/build-with-claude/streaming)、[Thinking 故障排查](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting)、[模型生命周期](https://platform.claude.com/docs/en/about-claude/model-deprecations)。
