深度思考
推理模型会在回答前先「思考」,适合数学、编程、复杂规划等需要多步推理的任务。思考过程消耗的 token 按输出价格计费,所以可以按任务难度调整思考深度,在效果和成本之间取舍。
GPT 系列
Chat Completions 用 reasoning_effort,Responses API 用 reasoning.effort,取值通常为 low、medium、high:
reasoning_chat.py
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://api.flyrouter.ai/v1")
resp = client.chat.completions.create(
model="gpt-6.1-sol",
reasoning_effort="high",
messages=[{"role": "user", "content": "证明根号 2 是无理数"}],
)
print(resp.choices[0].message.content)推理消耗的 token 记在 usage 的 reasoning tokens 明细里。
Claude 系列
新款 Claude 使用自适应思考:模型自己决定要不要思考、思考多久,你用 output_config.effort 控制整体的投入程度,取值为 low、medium、high、xhigh、max。
reasoning_claude.py
from anthropic import Anthropic
client = Anthropic(api_key="sk-...", base_url="https://api.flyrouter.ai")
with client.messages.stream(
model="claude-opus-5-5",
max_tokens=32000,
thinking={"type": "adaptive", "display": "summarized"},
output_config={"effort": "high"},
messages=[{"role": "user", "content": "设计一个支持百万并发的短链接服务,给出架构与取舍"}],
) as stream:
msg = stream.get_final_message()
for block in msg.content:
if block.type == "thinking":
print("【思考摘要】", block.thinking)
elif block.type == "text":
print(block.text)display: "summarized"会返回思考过程的摘要;不设置时思考块的文字为空(思考照常进行、照常计费)。- 选择深度的经验:聊天、分类用
low;日常编程和 Agent 任务从medium或high开始;正确率比成本更重要时再用xhigh或max。
新旧参数的区别
claude-opus-5-5、claude-sonnet-5-5、claude-haiku-5-5、claude-fable-5-1 等新款模型不再接受 {"type": "enabled", "budget_tokens": N}(会返回 400),请改用 {"type": "adaptive"} 加 output_config.effort。其中 claude-opus-5-5、claude-sonnet-5-5、claude-fable-5-1 也不能用 {"type": "disabled"} 关闭思考,想要更快更省就把 effort 调低。claude-haiku-4-5 等旧款模型仍使用 budget_tokens。
使用建议
- 思考时间较长,请使用 流式输出,并把
max_tokens设得足够大,避免回答被截断。 - 多轮对话中,请把模型返回的思考块原样放回历史消息,不要修改或删除。
- 简单任务不需要高思考深度,降低 effort 往往速度更快、成本更低,效果也不差。