Claude Code 订阅账号代理配置套件,基于 CLIProxyAPI
将 Claude Code 订阅账号转换为 OpenAI/Claude 兼容的 API 服务,支持多账号轮换、自动刷新 Token、健康监控。
| 优化项 | 原版默认 | SubProxy | 收益 |
|---|---|---|---|
routing.strategy |
round-robin |
fill-first |
节省 ~70% token(保持 Prompt Cache) |
force-model-prefix |
false |
true |
精确控制账号负载分配 |
request-retry |
1 |
3 |
更强容错,减少偶发失败 |
max-retry-interval |
10s |
30s |
给限速账号更多恢复时间 |
| 脚本 | 功能 |
|---|---|
watchdog.sh |
三层健康检查:进程→API→Token,自动修复 + Telegram 告警 |
health-check.sh |
彩色状态面板,一键查看所有账号状态 |
rate-limit-cooldown.sh |
限速账号自动禁用,5小时后自动恢复 |
restart.sh |
优雅重启(兼容 brew services) |
┌─────────────────────────────────────────────────────┐
│ Layer 1: 进程检查 (pgrep cliproxyapi) │
│ ↓ 失败 → 自动重启服务 │
├─────────────────────────────────────────────────────┤
│ Layer 2: API 检查 (GET /v1/models → HTTP 200) │
│ ↓ 失败 → 自动重启服务 │
├─────────────────────────────────────────────────────┤
│ Layer 3: Token 检查 (POST /v1/chat/completions) │
│ ↓ 401/403 → 强制刷新 Token │
│ ↓ invalid_grant → Telegram 告警(需手动登录) │
└─────────────────────────────────────────────────────┘
检测 429 → 自动禁用该账号 → 切换到下一账号 → 5小时后自动恢复
避免反复撞限速,最大化账号利用率。
- ✅ 多账号支持(team1/team2/team3/daily 等)
- ✅ OAuth Token 自动刷新
- ✅ 账号限速自动切换
- ✅ Prompt Cache 优化(fill-first 策略)
- ✅ 三层健康监控 & 看门狗
- ✅ 限速冷却自动恢复
- ✅ Telegram 告警通知
- ✅ OpenAI/Claude API 兼容
- ✅ OpenClaw 深度集成
brew install cliproxyapigit clone https://github.com/wade56754/subproxy.git
cp subproxy/config/subproxy.conf.template /opt/homebrew/etc/cliproxyapi.conf
# 编辑配置,设置你的 API Key 和代理
vim /opt/homebrew/etc/cliproxyapi.confcliproxyapi login claude --prefix team1
cliproxyapi login claude --prefix team2
cliproxyapi login claude --prefix team3
cliproxyapi login claude --prefix dailybrew services start cliproxyapicp subproxy/scripts/*.sh ~/.cli-proxy-api/
chmod +x ~/.cli-proxy-api/*.sh
# 设置看门狗定时任务(每5分钟)
(crontab -l 2>/dev/null; echo "*/5 * * * * ~/.cli-proxy-api/watchdog.sh") | crontab -# 检查所有账号状态
~/.cli-proxy-api/health-check.sh
# 或手动测试
curl http://127.0.0.1:8317/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"| 配置项 | 说明 | 推荐值 |
|---|---|---|
host |
绑定地址 | 127.0.0.1(安全) |
port |
监听端口 | 8317 |
proxy-url |
上游代理 | socks5://127.0.0.1:7897 |
force-model-prefix |
强制账号前缀 | true |
routing.strategy |
路由策略 | fill-first |
request-retry |
重试次数 | 3 |
| 策略 | Prompt Cache | 负载分布 | 推荐场景 |
|---|---|---|---|
fill-first |
✅ 高命中 | 集中 | 推荐 - 长对话、Agent |
round-robin |
❌ 低命中 | 均匀 | 短请求、高并发 |
为什么选 fill-first?
- Claude 的 Prompt Cache 是按账号隔离的
round-robin会导致每次请求换账号,Cache 无法命中- 实测
fill-first可节省 ~70% token 费用(通过 Cache Read)
# 手动运行
~/.cli-proxy-api/watchdog.sh
# 查看日志
tail -f ~/.cli-proxy-api/watchdog.log
# 配置 Telegram 告警(可选)
export SUBPROXY_TG_BOT="your_bot_token"
export SUBPROXY_TG_CHAT="your_chat_id"~/.cli-proxy-api/health-check.sh
# 输出示例:
# ==========================================
# SubProxy Health Check
# ==========================================
#
# Process: ✓ Running
# API: ✓ Reachable (HTTP 200)
#
# Accounts:
# ----------
# [team1] user1@example.com: ✓ Working
# [team2] user2@example.com: ⚠ Rate limited
# [team3] user3@example.com: ✓ Working
# [daily] user4@example.com: ✓ Working
#
# Summary: 3/4 accounts active# 后台运行
nohup ~/.cli-proxy-api/rate-limit-cooldown.sh &
# 查看日志
tail -f ~/.cli-proxy-api/cooldown.logcurl http://127.0.0.1:8317/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "team1/claude-sonnet-4-6",
"messages": [{"role": "user", "content": "Hello"}]
}'curl http://127.0.0.1:8317/v1/messages \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "team1/claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'在 openclaw.json 中添加 provider:
{
"models": {
"providers": {
"subproxy": {
"baseUrl": "http://127.0.0.1:8317/v1",
"apiKey": "sk-your-api-key",
"api": "openai-completions",
"models": [
{
"id": "team1/claude-sonnet-4-6",
"name": "Claude Sonnet 4.6 (team1)"
},
{
"id": "team3/claude-opus-4-6",
"name": "Claude Opus 4.6 (team3)"
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "subproxy/team3/claude-opus-4-6",
"fallbacks": [
"subproxy/team1/claude-sonnet-4-6",
"subproxy/daily/claude-sonnet-4-6"
]
}
}
}
}Q: 所有账号都限速了?
# 检查账号状态
~/.cli-proxy-api/health-check.sh
# 等待冷却(默认5小时)或添加新账号
cliproxyapi login claude --prefix team_newQ: Token 刷新失败?
# 检查日志
tail -f ~/.cli-proxy-api/logs/main.log
# 重新登录
cliproxyapi login claude --prefix team1 --forceQ: unexpected EOF 错误?
- 检查代理连接是否稳定
- 检查网络是否正常
- 服务会自动重试(已配置 3 次)
Q: Watchdog 没有自动修复?
# 检查 crontab
crontab -l | grep watchdog
# 手动测试
~/.cli-proxy-api/watchdog.sh
cat ~/.cli-proxy-api/watchdog.logSubProxy 包含一个轻量级监控面板,只有两个核心功能:
- 📊 速率监控 - 每个账号的 5h 窗口使用量
- 💰 成本分析 - 按模型/账号/Agent 分析费用
cd dashboard
node server.js
# 或
npm start详细文档见 dashboard/README.md
本配置套件基于 MIT 协议开源。
CLIProxyAPI 本身采用 MIT License。
- CLIProxyAPI - 核心代理服务
- OpenClaw - AI Agent 框架
