Featured image of post 如何解决 opencode 中 deepseek 模型的 reasoning 问题

如何解决 opencode 中 deepseek 模型的 reasoning 问题

使用 opencode 配合 deepseek-reasoner 时,遇到 "reasoning_content must be passed back to the API" 报错的排查与解决过程。

语速

当我们使用 deepseek-reasoner 的时候,往往会遇到这个问题:

1
The reasoning_content' in the thinking mode must be passed back to the API.

更新

现在两个问题都已经被 opencode 官方解决。用户只需要安装最新的 opencode,通过 deepseek provider 即可使用,无需额外配置。

1
2
3
4
5
6
问题1
The reasoning_content' in the thinking mode must be passed back to the API.

问题2
Bad Request: {"error":{"message":"The content[].thinking in the thinking mode must be passed back to the 
API.","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}

这两个问题已经被官方解决。安装 1.14.29 以及以上版本即可。


以下旧的解决方法:

怎么解决呢?也容易。

如何配置

添加 provider 信息到配置中:

.config/opencode/opencode.json 或者 .config/opencode/opencode.jsonc

修改 provider 部分为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
    "provider": {
        "deepseek": {
            "npm": "@ai-sdk/anthropic",
            "name": "DeepSeek",
            "options": {
                "baseURL": "https://api.deepseek.com/anthropic",
                "apiKey": "<apikey>"
            },
            "models": {
                "deepseek-v4-pro": {
                    "name": "DeepSeek-V4-Pro",
                    "limit": {
                        "context": 1048576,
                        "output": 262144
                    },
                    "options": {
                        "thinking": {
                            "type": "enabled",
                            "budgetTokens": 8192
                        }
                    }
                },
                "deepseek-v4-flash": {
                    "name": "DeepSeek-V4-Flash",
                    "limit": {
                        "context": 1048576,
                        "output": 262144
                    },
                    "options": {
                        "thinking": {
                            "type": "enabled",
                            "budgetTokens": 8192
                        }
                    }
                }
            }
        }
     }
}

如何使用

选择 deepseek 模型。

效果。

补充

这个方式无法解决问题

Bad Request: {"error":{"message":"The content[].thinking in the thinking mode must be passed back to the API.","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}

如果你遇到这个问题,还需要等待 opencode 去修复。

相关文章DeepSeek + Claude Code: Thinking Block 兼容性问题分析 — 分析了 Claude Code 使用 DeepSeek 时 extended thinking 模式下多轮对话触发 400 错误的根因,以及社区解决方案。