npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

qwen-adapter

v1.0.4

Published

Use Qwen models with Claude Code - An Anthropic-compatible API adapter

Downloads

218

Readme

qwen-adapter

使用通义千问模型与 Claude Code - Anthropic 兼容 API 适配器

npm version License: MIT

🎯 功能

  • ✅ 将通义千问 API 转换为 Anthropic 兼容格式
  • ✅ 支持 Claude Code 完整功能
  • ✅ 支持流式响应
  • ✅ 支持 Tool Calling
  • ✅ 支持多模态(图片)

📦 安装

npm install -g qwen-adapter

或使用 npx:

npx qwen-adapter start

🚀 快速开始

1. 获取通义千问 API Key

访问 阿里云 DashScope 开通服务并创建 API Key。

2. 自动配置 Claude Code(推荐)

# 一键安装配置
npx qwen-adapter install

# 设置 API Key
export QWEN_API_KEY=your_api_key

# 启动代理
npx qwen-adapter start

3. 启动代理服务

方式一: 使用 .env 配置文件(推荐)

在项目目录或用户目录创建 .env 文件:

# 创建配置文件
cp .env.example .env

# 编辑 .env 文件,填入你的 API Key
# QWEN_API_KEY=your_api_key_here

# 启动服务
npx qwen-adapter start

配置文件搜索路径(按优先级):

  1. 当前工作目录的 .env
  2. 项目目录的 .env
  3. ~/.qwen-adapter/.env

方式二: 使用环境变量

export QWEN_API_KEY=your_api_key
npx qwen-adapter start

方式三: 使用命令行参数

npx qwen-adapter start -k your_api_key

方式四: 指定配置文件路径

npx qwen-adapter start -c /path/to/.env

3. 配置 Claude Code

编辑 ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "qwen-key",
    "ANTHROPIC_BASE_URL": "http://localhost:3000"
  }
}

4. 启动 Claude Code

claude

📖 命令

# 启动代理服务
npx qwen-adapter start

# 自动配置 Claude Code(推荐)
npx qwen-adapter install

# 移除配置
npx qwen-adapter uninstall

# 显示配置说明
npx qwen-adapter config

# 测试 API 连接
npx qwen-adapter test

启动选项

| 选项 | 说明 | 默认值 | |------|------|--------| | -k, --api-key <key> | 通义千问 API Key | QWEN_API_KEY 环境变量 | | -m, --model <model> | 使用的模型 | qwen-2.5-max | | -p, --port <port> | 服务端口 | 3000 | | -h, --host <host> | 服务地址 | localhost |

🤖 支持的模型

通义千问原生模型

| 模型 | 说明 | |------|------| | qwen-2.5-max | 最强模型,推荐使用 | | qwen-2.5-plus | 平衡性能和成本 | | qwen-2.5-turbo | 快速响应 |

Claude 模型别名

以下 Claude 模型名称会被自动映射到对应的通义千问模型:

| Claude 模型 | 映射到 | |------------|--------| | claude-opus-4-6claude-opus-4 | qwen-max | | claude-sonnet-4-6claude-sonnet-4 | qwen-plus | | claude-haiku-4-5claude-haiku-4 | qwen-turbo |

🔧 高级用法

作为库使用

import { startServer } from 'qwen-adapter';

await startServer({
  apiKey: 'your_api_key',
  port: 3000,
  host: 'localhost',
  model: 'qwen-2.5-max'
});

自定义转换

import { claudeToOpenAI, openAIToClaude } from 'qwen-adapter';

// Claude 请求 → OpenAI 格式
const openaiReq = claudeToOpenAI(claudeRequest);

// OpenAI 响应 → Claude 格式
const claudeRes = openAIToClaude(openaiResponse);

📊 与其他模型对比

| 模型 | 代码能力 | 推理能力 | 中文能力 | 成本 | |------|---------|---------|---------|------| | Claude 4.6 Opus | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | 💰💰💰 | | GPT-4o | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | 💰💰 | | Qwen-2.5-Max | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | 💰 | | GLM-4 | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | 💰 |

⚠️ 已知限制

  1. Tool Calling 差异: 通义千问的 Function Calling 格式与 Claude 略有不同,大部分场景可正常工作
  2. 上下文长度: 通义千问 128K vs Claude 200K,超长对话可能受限
  3. 响应速度: 可能比 Claude 原生 API 稍慢

🛠️ 故障排除

API Key 无效

Error: Qwen API error: 401

检查:

  • API Key 是否正确
  • 是否已开通通义千问服务
  • API Key 是否有余额

端口被占用

Error: listen EADDRINUSE

使用其他端口:

npx qwen-adapter start -p 3001

📝 License

MIT

🤝 贡献

欢迎提交 Issue 和 Pull Request!

🔗 相关项目