claude-code-router
项目地址
GitHub - musistudio/claude-code-router: Use Claude Code as the foundation for coding👇
https://github.com/musistudio/claude-code-router
使用步骤
1. 安装 Claude 代码
npm install -g @anthropic-ai/claude-code
2. 安装 claude-code-router
npm install -g @musistudio/claude-code-router
3. 生成初始配置
ccr start
提示: 暂时随意输入值,因为我们将在下一步直接编辑配置文件,完成后按 Ctrl+C
退出终端。
4. 编辑配置文件
打开配置文件(可以直接copy我的配置)
- linux/mac:
~/.claude-code-router/config.json
- Windows:
C:/User/用户/.claude-code-router/config.json
这是一个 Moonshot (Kimi k2) 官方模型和 siliconflow硅基流动 的简单配置示例:
{
"LOG": false,
"OPENAI_API_KEY": "",
"OPENAI_BASE_URL": "",
"OPENAI_MODEL": "",
"Providers": [
{
"name": "siliconflow",
"api_base_url": "https://api.siliconflow.cn/v1/chat/completions",
"api_key": "sk-xxx",
"models": [
"moonshotai/Kimi-K2-Instruct"
],
"transformer": {
"use": [
[
"maxtoken",
{
"max_tokens": 16384
}
]
]
}
},
{
"name": "moonshot",
"api_base_url": "https://api.moonshot.cn/v1/chat/completions",
"api_key": "sk-xxx",
"models": [
"kimi-k2-0711-preview"
],
"transformer": {
"use": [
"openrouter"
]
}
}
],
"Router": {
"default": "siliconflow,moonshotai/Kimi-K2-Instruct"
}
}
6. 启动
配置完成后,使用 ccr code 命令替代原来的 claude 命令来启动您的项目
ccr code
注意:
transformer
是一个关键参数,用于解决不同 LLM 提供商之间 API 格式的兼容性问题。
- 更多参数可以去项目中查看
配置起来很方便,分享给大家!