@aistack/claude-code-代理服务器
一个高性能的代理服务器,将Anthropic Claude API请求翻译为LiteLLM格式,能与多个LLM供应商实现无缝集成,包括OpenAI,Google双子座,OpenRouter,和Anthropic.
特征
- 🚀 多服务支持: OpenAI、双子座、OpenRouter和Anthropic模型之间的无缝交换
- 🔄 自动格式翻译: 将 Anthropic API 格式转换为 LiteLLM 格式并返回
- 🎯 智能模型映射:智能地将克洛德模型映射到来自其他提供者的等同模型
- 📡 流程支持: 完全支持服务器-恒星事件流媒体响应
- 🛡️ 生产准备: 全面错误处理、记录和优雅的关闭
- ⚡ 高性能: 与 Go 为最佳性能和资源使用率低而建
- 🔧 可配置: 通过环境变量进行灵活配置
安装
使用 npm 在全球安装 :
npm install -g @aistack/claude-code-proxy
快速启动
- 初始化配置数字 :
ccproxy init
这将促使您创建配置文件 :
- 用户级别 :
$HOME/.ccproxy/settings.json - 项目级别:
./.ccproxy/settings.json
- 编辑配置文件数字 :
{
"server": {
"port": 8082,
"host": "0.0.0.0"
},
"providers": {
"openai": {
"apiKey": "sk-...",
"baseURL": "https://api.openai.com/v1",
"responseStyle": "openai"
},
"anthropic": {
"apiKey": "sk-ant-...",
"baseURL": "https://api.anthropic.com",
"responseStyle": "anthropic"
},
"gemini": {
"apiKey": "...",
"baseURL": "https://generativelanguage.googleapis.com",
"responseStyle": "openai"
},
"openrouter": {
"apiKey": "sk-or-v1-...",
"baseURL": "https://openrouter.ai/api/v1",
"responseStyle": "openai"
}
},
"models": {
"bigModel": "gpt-4@openai",
"smallModel": "gpt-4-mini@openai"
},
"logging": {
"level": "info",
"format": "json"
}
}
- 启动代理数字 :
# Start proxy server and launch claude CLI (default behavior)
ccproxy
# Or start only the proxy server
ccproxy server
服务器将启动 http://localhost:8082 (或您配置的端口).
图标
可用命令
ccproxy(默认) - 启动代理服务器( 如果需要)并启动 Claude CLIccproxy server- 只启动代理服务器ccproxy init- 交互式初始化配置文件--scope user- 创建用户级配置--scope project- 创建项目级别配置
ccproxy help- 显示帮助消息ccproxy version- 显示版本信息
全球选项
--debug- 启用调试记录( 适用于所有命令)--port- 覆盖服务器端口(只有服务器命令)
实例
# Start server and launch claude CLI (default behavior)
ccproxy
# Start with debug logging enabled
ccproxy --debug
# Start only the proxy server
ccproxy server
# Start server on custom port
ccproxy server --port 8080
# Start server with debug logging
ccproxy server --debug
# Initialize configuration interactively
ccproxy init
# Create user-level configuration
ccproxy init --scope user
# Create project-level configuration
ccproxy init --scope project
使用量
配置
配置文件
代理加载配置按优先级顺序从多个来源进行 :
- 命令行参数 (最高优先级)
--port: 覆盖服务器端口
- JSON 配置文件数字 :
/etc/ccproxy/managed-settings.json(管理/全系统)$CWD/.ccproxy/settings.json(项目一级)$HOME/.ccproxy/settings.json(用户级)
模型格式
格式中指定模型 modelname@provider数字 :
gpt-4@openaiclaude-3-opus@anthropicgemini-pro@geminigpt-4@openrouter
响应样式
提供者可以有不同的响应风格:
"responseStyle": "anthropic"- 原生Anthropic格式(无转换)"responseStyle": "openai"- OpenAI格式(需要转换)
这使得代理机可以跳过本地支持Anthropic的API格式的提供者不必要的转换.
模型绘图
代理自动映射 Claude 模型以配置模型 :
| 克劳德模型 | 调试到 | 说明 |
|---|---|---|
| 克劳德..-海库 | smallModel | 配置的小模型的地图 |
| 克劳德..- 孙网 | bigModel | 配置的大模型地图 |
| 其他模式 | 按规定 | 使用模型@ professor 格式 |
配置选项
JSON 配置
| 外地 | 说明 | 默认 |
|---|---|---|
server.port | 服务器端口 | 8082 |
server.host | 服务器主机 | 0.0.0.0 |
providers.<name>.apiKey | API 密钥提供者 | - 说吧 |
providers.<name>.baseURL | 提供者基础 URL | - 说吧 |
providers.<name>.responseStyle | 响应格式样式 | openai |
models.bigModel | 大宗请求的模式 | gpt-4@openai |
models.smallModel | 小请求模式 | gpt-4-mini@openai |
logging.level | 日志级别 | info |
logging.format | 日志格式 | json |
默认行为
当你跑的时候 ccproxy 它将:
- 检查代理服务器是否已运行
- 未运行时启动服务器
- 用 ANTHROPIC BASE URL 设置到代理服务器启动 CLI
这意味着你可以使用 ccproxy 用于替换 claude 命令,同时自动获得多提供者支持.
添加自定义提供者
本地安特罗皮克支持的自定义提供者 :
{
"providers": {
"custom-llm": {
"baseURL": "https://your-llm-api.com",
"apiKey": "your-api-key",
"responseStyle": "anthropic"
}
}
}
然后使用它与: custom-model@custom-llm
平台支持
用于下列平台的CLI:
- macOS (英特尔和苹果硅)
- Linux (x64 & ARM64) (韩语)
- 视窗 (x64)
解决问题
二进制未找到
如果您看到"Binary没有找到"错误,这意味着您的平台不被支持. 请 打开一个问题 你的平台细节.
拒绝权限
在Unix系统上,如果遇到许可错误:
sudo npm install -g @aistack/claude-code-proxy
API 关键问题
保证您的 API 密钥正确设置在您的中 settings.json 并获得必要的权限.
发展
为了发展或作出贡献,访问 GitHub 仓库。 。 。 .
许可证
麻省理工学院的执照 - 看 自由主义 详细文件.
支助
更改日志
见 变动情况 为释放历史.