majiayu000/spellbook / skills/cliproxy-newapi-stack
cliproxy-newapi-stack
Flagged在已经过独立验证的 CLIProxyAPI upstream 之上部署 NewAPI 计费层,把 Codex/Claude/Gemini/Qwen 等订阅账号包装成可计费的 OpenAI 兼容 API。本 Skill 不负责新建裸 CLIProxyAPI;负责 NewAPI Docker 部署、容器到宿主桥接、模型计费倍率、参数化额度修正、多账号 OAuth 凭据热加载和双路径验证。当用户说“给现有 cliproxy 加 NewAPI”“配置 NewAPI 渠道接已运行的 cliproxy”“NewAPI 价格不对”“给现有部署加账号”“172.17.0.1 容器网络”或“408 冷却放大故障”时触发。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.0 KB |
| agents/openai.yaml | config | 248 B |
| references/multi-account.md | markdown | 2.6 KB |
| references/newapi-pricing.md | markdown | 2.8 KB |
| references/troubleshooting.md | markdown | 2.9 KB |
| scripts/add_codex_account.shexecutable | script | 2.9 KB |
| scripts/deploy_newapi.shexecutable | script | 1.9 KB |
| scripts/lib/validation.sh | script | 3.3 KB |
| scripts/set_pricing.pyexecutable | script | 5.8 KB |
| scripts/test_security_validation.shexecutable | script | 3.1 KB |
| scripts/topup.shexecutable | script | 1.8 KB |
| scripts/verify_stack.shexecutable | script | 4.9 KB |
references/troubleshooting.md
View on GitHub# Stack Troubleshooting (踩过的坑)
| 症状 | 根因 | 修复 |
|---|---|---|
| NewAPI 渠道测试失败:`upstream connection refused` | 容器里的 `127.0.0.1` 是容器自己 | base_url 改成 `http://172.17.0.1:<CLIPROXY_PORT>` |
| 写价格用 `/api/option/` PUT 返回 success 但实际不生效 | 这版接口幂等行为不一致 | 直接 `sqlite3 UPDATE options ...` + `docker restart new-api` |
| 调用经 NewAPI 后 `quota=0` 入 logs | 模型名没在 ModelRatio 里登记,走 default 0 | 必须显式写 ratio 给 CLIProxyAPI 暴露的虚拟模型名(如 `gpt-5.4`) |
| 30 并发 5KB payload 时混合 200/503 (~50%) | CLIProxyAPI conductor 把 408 当 5xx 触发 1 分钟冷却,selector 在窗口期同步拒所有请求 | `config.yaml` 加 `disable-cooling: true`,改 `internal/config/config.go` 触达的开关 |
| 直连 :8317 返回 408 但经 NewAPI 变 503 | NewAPI 把 auth_unavailable 包装成 503 | 看 `/root/CLIProxyAPI/cli-proxy-api.log` 里的真实上游码 |
| `Empty reply from server` 公网调用 | UFW 默认 `deny incoming`,端口未放行 | `ufw allow <PORT>/tcp` |
| 加新 OAuth 账号后日志显示老号还在被路由 | 多账号轮询正常 | 老号 429/quota 用尽时 selector 才把它 mark unavailable,新号自动顶上 |
| NewAPI `/api/option/` 401 | 未登录或漏 `New-Api-User: 1` 头 | 先 `POST /api/user/login` 拿 cookie,再调 `GET /api/option/ -H 'New-Api-User: 1'` |
| 用户看到 `quota=-N` 但前端没反应 | 持续消费导致负余额 | 直接 `UPDATE users SET quota=N WHERE id=?` + 重启容器 |
| 老 PID 还监听端口,新启动不生效 | 旧 `go run` 进程没退 | `lsof -i:<PORT>` → 精确 `kill <pid>`;不要 `pkill -9 go` |
| OAuth 卡 `Authentication timed out` | 5 分钟窗口 + 隧道未就位 | 改走本地 OAuth + scp |
| Codex login 通过但实际请求 401 | 账号无 ChatGPT Plus/Pro 订阅 | 换有效订阅账号;不要假设 login 成功 = 可用 |
## 容器网络速记
```
container 127.0.0.1 ≠ host
container -> host = http://172.17.0.1:<port> (default bridge)
host -> container = http://127.0.0.1:<port> (port-published)
external -> host = http://<HOST>:<port> (UFW must allow)
```
## CLIProxyAPI cooldown 原理
- 文件:`sdk/cliproxy/auth/conductor.go`
- 触发:`case 408, 500, 502, 503, 504` → `state.NextRetryAfter = now+1min`
- 后果:单次 408 把整账号冻 60s;30 并发期间 99% 请求落在窗口内
- 解药:`config.yaml: disable-cooling: true`(`internal/config/config.go` 的开关,运行时读)
## NewAPI 计费日志
```sql
SELECT id, datetime(created_at,'unixepoch','localtime') AS t,
model_name, prompt_tokens, completion_tokens,
quota, channel_id, request_id
FROM logs ORDER BY id DESC LIMIT 20;
```
- `quota=0` 通常意味着模型名漏了 ratio 配置或走了 default 0。
- `request_id` 与响应头 `X-Oneapi-Request-Id` 对应,可跨层追踪。
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |