思考功能(enable_thinking)是千问 Qwen3 系列混合思考模型的特性参数,用于控制模型在给出最终答案前是否先输出思考过程(链式推理)。思考长度可通过思考预算(thinking_budget)限制。该功能适用于数学推导、逻辑分析、代码调试等需要多步推理的场景。
thinking_budget
思考开关enable_thinking:
enable_thinking
True
False
思考预算thinking_budget(仅在开启思考时生效):
4000
注:各模型 enable_thinking 默认值不同(部分新版本模型默认开启思考),建议始终显式传入。
import json import requests # 配置 API 密钥 api_key = "sk-................................." # 替换为你的 知能API 令牌 url = "https://api.apexrouter.top/v1/chat/completions" # 设置请求头 headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } # 构造请求数据 data = { "model": "qwen3.7-max", # 千问 Qwen3 系列模型(按 知能API 实际提供的名称填写) "messages": [ { "role": "user", "content": "从1加到10等于多少?" # 用户提问 } ], "enable_thinking": True, # 开启思考功能:先输出思考过程再给答案 "thinking_budget": 4000, # 可选:思考过程最大 token 数,达到上限立即停止思考 } try: # 发送 API 请求 response = requests.post(url, headers=headers, json=data) response.raise_for_status() # 检查 HTTP 错误 # 处理响应结果 print("请求成功!") print(json.dumps(response.json(), indent=2, ensure_ascii=False)) except requests.exceptions.RequestException as e: # 异常处理 print(f"请求失败: {e}")
import json import requests # 配置 API 密钥 api_key = "sk-................................." # 替换为你的 知能API 令牌 url = "https://api.apexrouter.top/v1/chat/completions" # 设置请求头 headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } # 构造请求数据 data = { "model": "qwen3.7-max", # 千问 Qwen3 系列模型(按 知能API 实际提供的名称填写) "messages": [ { "role": "user", "content": "从1加到10等于多少?" # 用户提问 } ], "enable_thinking": False # 关闭思考功能:直接给出最终答案(无需 thinking_budget) } try: # 发送 API 请求 response = requests.post(url, headers=headers, json=data) response.raise_for_status() # 检查 HTTP 错误 # 处理响应结果 print("请求成功!") print(json.dumps(response.json(), indent=2, ensure_ascii=False)) except requests.exceptions.RequestException as e: # 异常处理 print(f"请求失败: {e}")
extra_body={"enable_thinking": True, "thinking_budget": 4000}
enable_thinking=false
reasoning_content
content
© 2026 知能API 千问 thinking