> 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.

# Thinking 与 effort

## 原生 Messages 的版本差异

用 `thinking.type` 控制模式，用 `output_config.effort` 调整模型的工作量。`effort` 同时影响 thinking、正文和工具调用。`max_tokens` 是包括 thinking 在内的总输出上限。下表列出 Anthropic Claude API 的正式型号行为。

| Claude 型号       | 省略 `thinking` | 关闭或启用的原生参数                                                         | 官方 effort                       |
| --------------- | ------------- | ------------------------------------------------------------------ | ------------------------------- |
| Fable 5.2、5.1、5 | 始终自适应         | 通过 `effort` 调节深度                                                   | 五档，默认 `high`                    |
| Haiku 5.5       | 自适应           | `disabled` 可用于 `high` 或更低 effort                                   | 五档，默认 `medium`                  |
| Haiku 4.5       | 关闭            | `enabled` 和 `budget_tokens` 开启手动 thinking                          | 不支持                             |
| Sonnet 5.5      | 自适应           | `between_tools` 关闭回答前的 thinking，保留工具调用间的进度更新，仅接受 `high` 或更低 effort | 五档，默认 `high`                    |
| Sonnet 5        | 自适应           | `disabled` 关闭                                                      | 五档，默认 `high`                    |
| Sonnet 4.6      | 关闭            | `adaptive` 开启自适应 thinking，手动模式已弃用但仍可用                              | `low`、`medium`、`high`（默认）、`max` |
| Opus 5.5        | 始终自适应         | 通过 `effort` 调节深度                                                   | 五档，默认 `medium`                  |
| Opus 5          | 自适应           | `disabled` 可用于 `high` 或更低 effort                                   | 五档，默认 `high`                    |
| Opus 4.8、4.7    | 关闭            | `adaptive` 开启自适应 thinking                                          | 五档，默认 `high`                    |
| Opus 4.6        | 关闭            | `adaptive` 开启自适应 thinking，手动模式已弃用但仍可用                              | `low`、`medium`、`high`（默认）、`max` |

五档 effort 为 `low`、`medium`、`high`、`xhigh`、`max`。常规手动请求的 `budget_tokens` 最小为 `1024`，且小于 `max_tokens`。手动交错 thinking 有预算例外和 beta 条件，Opus 4.6 仅在自适应模式中支持交错 thinking。参见 [Effort](https://platform.claude.com/docs/en/build-with-claude/effort)和[手动 Extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking)。

用 `display: "summarized"` 请求 thinking 摘要，用 `display: "omitted"` 保留签名并隐藏摘要。本文所列 5 系列和 Opus 4.8、4.7 默认 `omitted`，Sonnet 4.6、Opus 4.6 和 Haiku 4.5 默认 `summarized`。自适应模式可能跳过简单请求的 thinking，此时没有 thinking 块。`disabled` 和 `between_tools` 模式均只能发送 `thinking.type`。参见[官方 thinking 文档](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display)。

## Messages 请求与核心流事件

下面通过 routerlio 发送 Messages 请求，显式选择自适应模式、摘要和 effort。`stream` 设为 `true` 后按 SSE 事件读取响应。接入步骤见[快速接入](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": 4096,
  "stream": true,
  "thinking": {
    "type": "adaptive",
    "display": "summarized"
  },
  "output_config": {
    "effort": "medium"
  },
  "messages": [
    {
      "role": "user",
      "content": "用欧几里得算法求 1071 和 462 的最大公约数。"
    }
  ]
}
JSON
```

如果模型生成了摘要，流中可能出现以下三个 `content_block_delta`。下面的数组按接收顺序列出各事件解码后的 `data`，签名仅示意。`thinking_delta` 是摘要，`signature_delta` 携带签名，`text_delta` 才是给用户的回答。

```json
[
  {
    "type": "content_block_delta",
    "index": 0,
    "delta": {
      "type": "thinking_delta",
      "thinking": "使用辗转相除法。"
    }
  },
  {
    "type": "content_block_delta",
    "index": 0,
    "delta": {
      "type": "signature_delta",
      "signature": "example-signature"
    }
  },
  {
    "type": "content_block_delta",
    "index": 1,
    "delta": {
      "type": "text_delta",
      "text": "最大公约数是 21。"
    }
  }
]
```

处理完整流时，从 `content_block_start` 到 `content_block_stop` 按 `index` 组装各块。工具调用回合发回 Messages 时，保留完整的 `thinking` 或 `redacted_thinking` 块、顺序及原始签名。

## Anthropic 的 OpenAI SDK 兼容层

兼容层忽略 `reasoning_effort`，拒绝 `thinking: {"type": "adaptive"}`，响应省略 thinking 块。Claude 5 系列默认启用 thinking。其他型号需要启用时，可按官方兼容文档在请求体中传 `thinking.type: "enabled"` 和 `budget_tokens`。对于原生 Messages 已拒绝 `enabled` 的模型，兼容层将其转换为自适应 thinking，此时 `budget_tokens` 仍须提供，但不影响推理深度。参见 [Anthropic OpenAI SDK 兼容文档](https://platform.claude.com/docs/en/cli-sdks-libraries/libraries/openai-sdk#thinking-support)。

需要设置原生 effort、读取 thinking 摘要或保留工具回合签名时，使用 Messages。参见 [Anthropic 协议总览](https://little-butterfly-9bfe.sentia389.workers.dev/models/anthropic/index.md)。

已有 Chat 客户端在兼容层调用 Fable 5.2、Fable 5.1、Opus 5.5 或 Sonnet 5.5 时，可将 `tool_choice` 设为 `"auto"`。这些型号在兼容层收到 `"required"` 或强制调用指定函数时会返回 HTTP `400`。[兼容层参数表](https://platform.claude.com/docs/en/cli-sdks-libraries/libraries/openai-sdk#simple-fields)

## 平台别名

下表列出 routerlio 目录中的后缀别名。使用时，核对当前密钥的模型列表和渠道说明，确认具体协议、参数和上游映射。

| 系列     | routerlio 目录 ID                                                                                                                                                                                                                  |
| ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Haiku  | `claude-haiku-4-5-20251001-thinking`                                                                                                                                                                                             |
| Sonnet | `claude-sonnet-5-5-thinking`、`claude-sonnet-5-thinking`、`claude-sonnet-4-6-thinking`                                                                                                                                             |
| Opus   | `claude-opus-5-5-thinking`、`claude-opus-5-thinking`、`claude-opus-4-8-thinking`、`claude-opus-4-7-thinking`、`claude-opus-4-6-thinking`、`claude-opus-4-6-high`、`claude-opus-4-6-low`、`claude-opus-4-6-max`、`claude-opus-4-6-medium` |

## 排错

- Fable 与 Opus 5.5 若需减少 thinking，可降低 effort，隐藏摘要用 `display: "omitted"`。Haiku 4.5 拒绝 `adaptive` 时使用手动预算，Opus 4.7 或更新型号及所列 Claude 5 型号拒绝手动模式时改用 `adaptive`。
- Sonnet 5.5 的 `between_tools`、Haiku 5.5 与 Opus 5 的 `disabled` 都只接受 `high` 或更低 effort。Sonnet 5.5 和 Haiku 5.5 在这些模式下还限制逐消息 effort 变更。
- 遇到签名错误时，先核对模型、消息顺序和工具回合内容块。流式结束时检查 `message_stop` 或 `error`。遇到 `stop_reason: "max_tokens"` 时调整输出上限或 effort。参见[错误排查](https://little-butterfly-9bfe.sentia389.workers.dev/troubleshooting/index.md)。

## 官方资料

- Anthropic 的 [Thinking](https://platform.claude.com/docs/en/build-with-claude/thinking)、[手动 Extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking)、[Effort](https://platform.claude.com/docs/en/build-with-claude/effort)、[Thinking 故障排查](https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting)。
- Claude 型号页 [Fable 5.2](https://platform.claude.com/docs/en/models/fable-5-2/overview)、[Haiku 5.5](https://platform.claude.com/docs/en/models/haiku-5-5/overview)、[Sonnet 5.5](https://platform.claude.com/docs/en/models/sonnet-5-5/overview)、[Opus 5.5](https://platform.claude.com/docs/en/models/opus-5-5/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-tool-workflows)。
