回答为空或中途截断(finish_reason 是 length)
Echo Token Station 的 API 返回了 HTTP 200,但回答为空或中途截断时的原因与解决方法。finish_reason 是 length、stop_reason 是 max_tokens 时,输出已经达到 max_tokens。会推理的模型,思考的部分也算在 max_tokens 里。
输出达到 max_tokens(输出 token 数的上限),回答在中途停下的状态。这不是错误,返回的是 HTTP 200,所以要看 finish_reason(OpenAI 格式)或 stop_reason(Anthropic 格式)来区分。
错误示例
下面是给会推理(回答前先思考)的模型 deepseek-v4.1-flash 指定 max_tokens: 5 时的响应。5 个 token 全部用在推理上,回答的正文是空的。
OpenAI 格式(/v1/chat/completions)。content 是空的,completion_tokens_details 的 reasoning_tokens 是 5:
JSON
{"choices":[{"finish_reason":"length","index":0,"message":{"content":"","reasoning_content":"We need answer in Japanese","role":"assistant"}}],"created":1795432196,"id":"279a8bbf-10e6-4280-a901-8c4590e33288","model":"deepseek-v4.1-flash","object":"chat.completion","usage":{"prompt_tokens":41,"completion_tokens":5,"total_tokens":46,"prompt_tokens_details":{"cached_tokens":0},"completion_tokens_details":{"reasoning_tokens":5}}}Anthropic 格式(/v1/messages)。content 里只有推理(thinking)。记录下来的只是响应的开头(到 usage 的中间):
JSON
{"id":"69a3c691-38ce-4111-9286-08645fddc0dc","type":"message","role":"assistant","content":[{"type":"thinking","thinking":"We need answer in Japanese"}],"stop_reason":"max_tokens","model":"deepseek-v4.1-flash","usage":{"input_tokens":41,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5,"claude_cache_creation_5_m_tokens":0,"claude_cache_creation_1_h_tokens":0,"billing_usage":{"source":"oai_chat","semantic":"openai","openai_usage":{"prompt_tokens":41,"completion_tokens"常见原因
max_tokens太小:回答较长时,达到上限就会停下- 会推理的模型,推理用完了
max_tokens:推理的部分也算在max_tokens里。上面的例子里,5 个 token 全部用在推理上,正文是空的 - 用 OpenAI 格式(
/v1/chat/completions)调用 Claude 的模型,没有指定max_tokens:这时会在 8,192 个 token 处停下
解决方法
- 确认回答有没有完整返回。
finish_reason是length,或stop_reason是max_tokens时,就是停在了上限。OpenAI 格式完整返回时,finish_reason是stop - 增大
max_tokens。会推理的模型,要把推理的部分也算进去,设大一些。上限是模型页面上的最大输出 token 数
bash
curl "https://token.echohub.io/v1/chat/completions" \
-H "Authorization: Bearer $ECHO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-fable-5-1",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "日本の首都はどこですか?"}
]
}'max_tokens设得太大,估算金额可能超过余额,返回 403(403 insufficient_quota)
流式输出时,没有收到 finish_reason 或 stop_reason 就停下的,不是停在上限,而是因为上游 API 的错误或连接断开而停下(错误与处理的「流式输出中途停止时」)。