外观
思考与推理参数
推理模型会在回答前先「思考」。不同接口格式控制思考的参数、返回思考内容的字段各不相同,下面按格式说明。
速查表
| 接口格式 | 控制参数 | 思考内容所在字段 |
|---|---|---|
| Chat Completions | reasoning_effort | message.reasoning_content(流式为 delta.reasoning_content) |
| Responses | reasoning: {effort, summary} | output 中 type: "reasoning" 的 summary |
| Claude Messages | thinking + output_config.effort | content 中 type: "thinking" 的块 |
| Gemini 原生 | generationConfig.thinkingConfig | parts 中 thought: true 的部分 |
Chat Completions
GPT-5 系列、o 系列等推理模型使用 reasoning_effort 控制思考强度,并用 max_completion_tokens 限制总输出(包含思考):
json
{
"model": "gpt-5.4-mini",
"reasoning_effort": "medium",
"max_completion_tokens": 8192,
"messages": [{"role": "user", "content": "..."}]
}- 常用取值:
minimal/low/medium/high,部分新模型支持none、xhigh。 - 推理模型通常不支持
temperature、top_p、presence_penalty等采样参数,也不支持max_tokens。 - 思考消耗的 token 记录在
usage.completion_tokens_details.reasoning_tokens,按输出价格计费。
DeepSeek、Qwen、Kimi、GLM 等模型会在 reasoning_content 中返回思考过程:
python
resp = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "9.11 和 9.9 哪个大?"}],
)
msg = resp.choices[0].message
print("思考:", getattr(msg, "reasoning_content", None))
print("回答:", msg.content)流式时逐块读取 delta.reasoning_content 与 delta.content 即可分别拿到思考和回答。
Responses
json
{
"model": "gpt-5.5",
"reasoning": { "effort": "high", "summary": "auto" },
"input": "..."
}summary 设为 auto 或 detailed 时,响应的 output 中会包含 type: "reasoning" 的条目,其 summary 数组里是思考摘要(原始思考过程不返回)。
Claude Messages
| 模型 | 写法 |
|---|---|
| Claude 4.6 及更新(Sonnet 4.6、Opus 4.6 / 4.7 / 4.8 / 5 等) | "thinking": {"type": "adaptive"},可选 "output_config": {"effort": "high"} |
| Claude Haiku 4.5 及更早 | "thinking": {"type": "enabled", "budget_tokens": 8000}(需小于 max_tokens) |
json
{
"model": "claude-opus-4-8",
"max_tokens": 16000,
"thinking": { "type": "adaptive" },
"output_config": { "effort": "high" },
"messages": [{"role": "user", "content": "..."}]
}- 响应的
content中会先出现type: "thinking"的块,再出现type: "text"的回答。多轮对话时要把 thinking 块原样带回。 - Opus 4.7 及更新模型默认不返回思考文本(
thinking为空字符串),不影响回答。 - Opus 4.7 / 4.8、Opus 5 等较新模型不接受
budget_tokens与temperature、top_p、top_k,传入会返回 400;Opus 4.8 / 4.7 不传thinking时不会思考。 effort可选low/medium/high/max(较新模型还支持xhigh),越高思考越充分、消耗越多。
Gemini 原生
json
{
"contents": [{ "role": "user", "parts": [{ "text": "..." }] }],
"generationConfig": {
"thinkingConfig": { "thinkingLevel": "high", "includeThoughts": true }
}
}- Gemini 3 系列:使用
thinkingLevel(low/high)。 - Gemini 2.5 系列:使用
thinkingBudget(思考 token 上限,0关闭思考,-1由模型自动决定)。 includeThoughts: true时,响应parts中thought: true的部分为思考摘要。
通过模型名切换
部分模型提供带后缀的名称,无需额外参数即可切换思考行为(以 模型列表 中实际存在的名称为准):
| 后缀 | 效果 | 示例 |
|---|---|---|
-thinking | 开启思考 | gemini-3.1-pro-preview-thinking |
-nothinking | 关闭思考,响应更快更省 | gemini-2.5-flash-nothinking |
-high / -medium / -low | 指定推理强度 | o3-mini-high |