OriginTensorDOCS
返回主站 创建 API Key
开发指南 · API v1

推理模式与空正文排查

区分 reasoning_content、thinking 与最终正文,处理输出预算、空内容和推理计费。

OpenAI 兼容Anthropic 原生更新于 2026-12-05
管理 API Key

Reasoning fields

推理内容与正文是不同字段

OpenAI 兼容流可能返回 delta.reasoning_content 或 delta.reasoning,随后才返回 delta.content。Anthropic 协议可能返回 thinking 内容块与 thinking_delta。

Reasoning chunk
{
  "choices": [
    {
      "index": 0,
      "delta": {
        "reasoning_content": "先分析题目条件……"
      },
      "finish_reason": null
    }
  ]
}

客户端应把推理内容与最终正文分开存储。推理内容可能不适合直接展示给终端用户,也不应被当作最终答案。

Empty content

为什么有 usage 却没有正文?

  1. 检查是否收到 reasoning_content / thinking。
  2. 检查 finish_reason 是否为 length。
  3. 检查 max_tokens 是否全部被思考阶段消耗。
  4. 确认模型是否真的支持当前推理参数,而不是忽略了它。
  5. 查看 usage 的 output / completion tokens,区分“生成了但未展示”与“完全没有输出”。

Budget

为思考预留输出空间

Inspect reasoning and finish reason
response = client.chat.completions.create(
    model="glm-5.3",
    messages=[{"role": "user", "content": "比较两种方案并给出结论。"}],
    max_tokens=2048,
)

choice = response.choices[0]
print("finish_reason:", choice.finish_reason)
print("reasoning:", getattr(choice.message, "reasoning_content", None))
print("answer:", choice.message.content)
print("usage:", response.usage)

提高 max_tokens 不是万能修复。如果模型不支持 reasoning_effort,或上游忽略了参数,应改用明确支持推理的模型或关闭思考模式。

Parameters

推理相关参数

参数 / 字段说明
reasoning_effort推理强度请求;是否支持取决于模型。
thinkingAnthropic 原生 thinking 配置;可能包含类型与预算。
enable_thinking / thinking_budget部分渠道扩展;不是跨模型通用契约。
reasoning_contentOpenAI 兼容扩展字段,不是所有渠道都返回。

Billing

推理 token 与费用

思考 token 通常计入输出侧用量。长推理任务即使最终正文很短,也可能产生较高输出费用。生产环境应记录 completion / output tokens,并对推理预算设置上限。

如果业务只需要短答案,优先选择 flash、轻量或明确支持关闭思考的型号,并做真实 A/B 测试。

输入 API 名称、参数、错误码或场景,例如「stream」「429」「Anthropic」「缓存」。