Openclaw 3.24版本接入Deepseek V4 Pro 400报错

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

Openclaw 3.24版本接入Deepseek V4 Pro/ Flash 报错码 400,即使关了reasoning:false依然报错,可能是版本太低的缘故。

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

openclaw全局安装目录:C:\Users\user\AppData\Roaming\npm\node_modules\openclaw

Step 1: 创建补丁文件

在目录中新建文件deepseek-fix.mjs,代码如下:

// DeepSeek V4 reasoning_content auto-padding patch
// 在 openclaw 入口前加载此文件修复 400 错误

import { createRequire } from 'module';
const require = createRequire(import.meta.url);

// 拦截 fetch — 在请求发送前补齐 reasoning_content
const _fetch = globalThis.fetch.bind(globalThis);
globalThis.fetch = async function patchedFetch(url, init = {}) {
    const urlStr = typeof url === 'string' ? url : url.href || '';
    const isDeepSeek = urlStr.includes('api.deepseek.com');

    if (isDeepSeek && init.body && typeof init.body === 'string') {
        try {
            const body = JSON.parse(init.body);
            if (body.messages && Array.isArray(body.messages)) {
                let changed = false;
                for (const msg of body.messages) {
                    if (msg.role === 'assistant' && !('reasoning_content' in msg)) {
                        msg.reasoning_content = '';
                        changed = true;
                    }
                }
                if (changed) {
                    init.body = JSON.stringify(body);
                }
            }
        } catch (_) {
            // body 不是 JSON,放行
        }
    }

    return _fetch(url, init);
};

console.log('[deepseek-fix] Patch applied — reasoning_content auto-padding for DeepSeek V4');

Step 2:修改 OpenClaw 入口

修改 dist\index.js,在文件第一行加:

import '../deepseek-fix.mjs';

Step 3: 验证

重新启动 OpenClaw,看到 [deepseek-fix] Patch applied 就说明生效了。

原理:拦截 fetch,所有发往 api.deepseek.com 的请求在发出前自动扫描 messages,assistant 消息缺 reasoning_content 就加空字符串——跟 Python 版逻辑一样,换成 JS 实现。

结论:方法就是在主目录添加补丁,引入入口文件。

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值