Claude Code + Qwen 的配置方法

前言

由于 Claude Code 和 Qwen 的请求格式有点不兼容,需要另外写一个代理来确保正常地请求

使用代理拦截和修改请求

javascript 复制代码
const http = require('http');
const https = require('https');

const targetHost = 'dashscope.aliyuncs.com';
const targetPath = '/apps/anthropic/v1/messages';

const server = http.createServer((req, res) => {
    let body = '';
    req.on('data', chunk => { body += chunk; });
    req.on('end', () => {
        try {
            const originalReq = JSON.parse(body);
            // 修改 max_tokens
            if (originalReq.max_tokens > 8192) {
                originalReq.max_tokens = 8192;
            }
            // 确保 top_p 等参数也在范围内
            if (originalReq.top_p && originalReq.top_p > 1) {
                originalReq.top_p = 0.95;
            }
            
            const options = {
                hostname: targetHost,
                path: targetPath,
                method: 'POST',
                headers: {
                    ...req.headers,
                    'host': targetHost,
                    'content-length': Buffer.byteLength(JSON.stringify(originalReq))
                }
            };
            
            const proxyReq = https.request(options, (proxyRes) => {
                res.writeHead(proxyRes.statusCode, proxyRes.headers);
                proxyRes.pipe(res);
            });
            
            proxyReq.write(JSON.stringify(originalReq));
            proxyReq.end();
        } catch(e) {
            console.error('Proxy error:', e);
            res.writeHead(500);
            res.end('Proxy error');
        }
    });
});

server.listen(8080, () => {
    console.log('Proxy running on http://localhost:8080');
});

然后修改 settings.json:

json 复制代码
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "你的apikey",
    "ANTHROPIC_BASE_URL": "http://localhost:8080",
    "ANTHROPIC_MODEL": "qwen-max"
  }
}

先用 node 运行 proxy.js 最后再启动 claude 就可以用了

相关推荐
其实防守也摸鱼5 小时前
Day 3 · Agent Loop:从调用模型到控制循环 —— 课件精讲笔记
服务器·开发语言·javascript·数据库·人工智能·笔记·ecmascript
夕水5 小时前
我把颜色选择器拆成了 15 个插件,最后长成了 22 个包
前端·javascript·typescript
用户88956195481716 小时前
戴上眼镜就把今天听完:绿光快报的 AIUI 语音新闻智能体
javascript
stormsha6 小时前
ResizeObserver loop completed with undelivered notifications:它只是个警告,但也是你代码的供词
javascript·css
Nazarick7 小时前
从 fetch 到 then:Demo在线订单系统 Ajax 回调的逐帧拆解
java·javascript·ajax·web
徐同保9 小时前
模板里的图标组件找不到定义?聊聊 @tabler/icons-vue 与自动导入
前端·javascript·vue.js
橙光成长10 小时前
GameScrcpy:不装模拟器,用键鼠手柄和 TypeScript 脚本接管你的安卓手游
android·javascript·typescript·开源·1024程序员节
米米商聊11 小时前
AI 搜群附件,同一份 PDF 占满前三条?按附件 ID 折叠片段
javascript·人工智能
代码小学生&11 小时前
IIS 反向代理配置完整流程
javascript