200

返回 200,但 content 是空的,finish_reason 是 length

请求成功了,也扣了费,但没有任何文字。输出额度被模型的“思考”过程用完了,还没开始写正文。

报错原文2026-10-23 实测

claude-haiku-5-5,max_tokens=120,temperature=0.7(已截取关键字段)
{
  "choices": [{
    "message": {"role": "assistant", "content": "", "reasoning_content": ""},
    "finish_reason": "length"
  }],
  "usage": {"prompt_tokens": 175, "completion_tokens": 120}
}

原因

我们用 claude-haiku-5-5 让它写一条 SQL,max_tokens 设为 120,temperature 设为 0.7。返回结果:

  • finish_reason: "length"(因为到达上限而停止)
  • content: "",reasoning_content: ""
  • usage.completion_tokens: 120(额度全部用掉)

同样的请求不带 temperature 时,模型直接输出了 SQL。我们观察到:在这个网关上,这个模型带 temperature 参数时会先进入思考阶段,思考消耗的词元也算在输出里、按输出价格计费。推理类模型也有同样的现象,只是触发条件不同。

排查步骤

  1. 看 finish_reason:是 length 而 content 为空,基本就是这个问题。
  2. 把 max_tokens 调大(推理或思考场景建议 2000 以上)。
  3. 不需要随机性的任务,去掉 temperature 参数,用模型默认值。
  4. 在代码里加一个判断:content 为空且 finish_reason 是 length 时,提示调大额度后重试,不要直接把空字符串当结果用。

正确写法

r = client.chat.completions.create(model="claude-haiku-5-5", messages=msgs, max_tokens=2000)
choice = r.choices[0]
if not choice.message.content and choice.finish_reason == "length":
    raise RuntimeError("输出额度被思考用完,调大 max_tokens 再试")