
Bug: /v1 compatibility endpoint injects non-standard ‘reasoning’ field, breaking OpenAI clients
快速结论:该报错通常发生在使用Ollama的/v1/chat/completions兼容端点调用需要推理(thinking)的模型(如Gemma4、DeepSeek等),且下游客户端(如Warp终端)严格按OpenAI标准schema解析响应时。Ollama在message对象中注入了非标准的”reasoning”字段,导致客户端JSON反序列化失败。优先排查方法是在请求体中添加reasoning_effort: "none"或reasoning: { effort: "none" }以关闭推理输出。
问题场景
用户在Warp终端或其他严格遵循OpenAI Chat Completions API规范的客户端中,通过Ollama的/v1/compatibility端点调用支持”思考链”的模型(例如gemma4:12b)。客户端仅允许配置端点URL,无法修改请求体结构。Ollama在响应中的message对象内额外返回了"reasoning"字段,违反了OpenAI标准schema,导致客户端解析失败。
报错原文
// Ollama 返回的非标准响应(包含 reasoning 字段)
{
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "**Fideism** is a philosophical and theological position...",
"reasoning": "* Word: \"Fideism\"...\n* Root word: *fides*..."
},
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 24, "completion_tokens": 1162, "total_tokens": 1186 }
}
// OpenAI 标准规范期望的响应(不含 reasoning 字段)
{
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "**Fideism** is a philosophical and theological position..."
},
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 24, "completion_tokens": 1162, "total_tokens": 1186 }
}
原因分析
Ollama在0.30.10版本(及部分后续版本)中,对于支持”thinking/reasoning”的模型(如gemma4、deepseek系列等),在/v1/chat/completions端点的响应中,将模型内部生成的推理过程文本直接注入到message对象的reasoning字段。此字段并非OpenAI Chat Completions API标准规范的一部分(OpenAI官方API中推理过程通常在服务端内部消耗,不在响应体中暴露)。严格按schema解析的客户端(如Warp)遇到未知字段时可能导致JSON反序列化失败。用户尝试的"options": {"think": false}未能屏蔽该字段。
经社区验证,该问题具有模型和版本特异性:在Ollama 0.30.7版本中,非推理模型(如mistral-nemo、qwen2.5:14b)的响应并不包含reasoning字段,符合规范。因此问题主要影响0.30.10及附近版本中的推理模型。
环境排查
- Ollama 版本:确认是否 > 0.30.7,特别是 0.30.10(问题报告版本)。
- 模型类型:确认是否为支持推理/思考的模型(如 gemma4、deepseek-r1 等)。
- 客户端工具:确认是否使用严格按OpenAI schema解析的客户端(如Warp、自定义API调用等)。
- 请求参数:检查是否已经在请求体中尝试添加
reasoning_effort参数。
解决步骤
- 能控制请求体的场景:在请求体中添加
reasoning_effort: "none"或reasoning: { effort: "none" }。Ollama的OpenAI兼容层会识别该参数并移除响应中的reasoning字段。已验证reasoning_effort: "none"可将推理内容设为空字符串,配合omitempty标签使reasoning键完全不出现在JSON响应中。 - 不能控制请求体的场景(如Warp终端):建议跟踪Ollama官方修复。社区建议的长期方案包括:
- 将推理内容迁移到顶层自定义字段(如
x_ollama_reasoning)或添加?thinking=false查询参数,避免破坏标准schema。 - 对/v1端点默认启用严格模式,仅在想得到推理内容时允许显式启用。当前Ollama在推理模型上默认注入
reasoning,可能并非所有客户端都能优雅忽略该字段。
- 将推理内容迁移到顶层自定义字段(如
- 回退版本作为临时方案:如果必须严格兼容OpenAI schema且无法控制请求体,可暂时降级Ollama至0.30.7或更早版本(需自行评估安全与功能风险)。
验证方法
使用curl或类似工具发送请求并检查响应JSON,确认message对象中是否不再包含reasoning字段:
# 验证方式(替换 model 和端口号)
curl -s http://localhost:11434/v1/chat/completions \
-d '{"model":"gemma4","messages":[{"role":"user","content":"why is the sky blue"}],"reasoning":{"effort":"none"},"stream":false}' \
| jq '.choices[0].message | keys'
若输出仅包含 ["content", "role"](或任意的标准字段),则问题已解决。对于Warp终端用户,修复后应能正常解析并显示AI回复内容。



