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/newapi-pricing.md
View on GitHub# NewAPI Pricing Semantics (calciumion/new-api v0.12.x)
NewAPI persists pricing as **deep-mergeable JSON blobs** in the `options` table (SQLite at
`/data/one-api.db`). Default values live in code; the persisted rows override on top.
## Three pricing keys
| Key | Type | Meaning |
|---|---|---|
| `ModelRatio` | `{model: float}` | Per-1M-token input price (USD), often divided by an internal scale on some forks. Verify with a probe request. |
| `CacheRatio` | `{model: float}` | **Multiplier on input price**. cached_input = input * CacheRatio. |
| `CompletionRatio` | `{model: float}` | **Multiplier on input price**. output = input * CompletionRatio. |
| `QuotaPerUnit` | `int` | Default `500000`. Means `1 USD = 500000 quota`. Used to convert model price to internal `quota` integer recorded in `logs.quota`. |
| `GroupRatio` / `group_ratio_setting.group_ratio` | `{group: float}` | Per-user-group multiplier. `default=1` typical. |
## Worked example
Target prices (USD per 1M tokens):
- input `2.5`
- cached `0.25` ← 0.1× of input
- output `15` ← 6× of input
Write:
```json
"ModelRatio": {"gpt-5.4": 2.5}
"CacheRatio": {"gpt-5.4": 0.1}
"CompletionRatio": {"gpt-5.4": 6}
```
Probe with a real request and check `logs.quota`:
```sql
SELECT id, model_name, prompt_tokens, completion_tokens, quota
FROM logs ORDER BY id DESC LIMIT 3;
```
Compute expected `quota`:
```
expected = (prompt_tokens * input + completion_tokens * output) * (QuotaPerUnit / 1e6)
= (prompt_tokens * 2.5 + completion_tokens * 15) * 0.5
```
If observed roughly matches, mapping is correct. If observed is `~30×` higher, the fork uses an
**internal /2 scale** for ModelRatio — write `1.25` instead of `2.5` and re-probe.
## Pitfalls
- **CacheRatio is NOT a price** — writing `0.25` means cached = 0.25× input, not "cached costs 0.25 USD/1M".
- **CompletionRatio is NOT a price** — writing `15` means output = 15× input, ie a huge multiplier.
- **PUT via /api/option/ may silently no-op** on some installs. Direct SQLite write + container
restart is the canonical fallback.
- **Defaults bleed through**: missing keys mean NewAPI uses its built-in default, which may be
wildly wrong (e.g. `gpt-4`-class default applied to a `gpt-5.4` virtual model).
- **Scope to virtual models only**: CLIProxyAPI exposes virtual model names (e.g. `gpt-5.4`,
`gpt-5.3-codex`). Do not write ratios for upstream raw names — they will not be billed.
## Restart requirement
After writing rows directly to SQLite, restart the container:
```
docker restart new-api
```
The merged in-memory map is rebuilt at startup.
## Related options
- `MinTopUp`, `StripeMinTopUp`, `StripeUnitPrice` — affect the user-facing top-up UI; do not
change billing math.
- `general_setting.quota_display_type=USD` — only changes UI rendering; raw `quota` field stays
integer in `logs`.
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: 197k | 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 |