開發文件

深度思考

推理模型會在回答前先「思考」,適合數學、程式設計、複雜規劃等需要多步推理的任務。思考過程消耗的 token 按輸出價格計費,所以可以按任務難度調整思考深度,在效果和成本之間取捨。

GPT 系列

Chat Completions 用 reasoning_effort,Responses API 用 reasoning.effort,取值通常為 low、medium、high:

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 往往速度更快、成本更低,效果也不差。
FlyRouter

一組 Key,直飛全球大型模型