Add automatic CPA Management API import after mint

Upload xai-*.json to POST /v0/management/auth-files when cpa_auto_import_remote is enabled. Failures are logged only and never block registration.
This commit is contained in:
chaos committed 2026-07-11 17:47:34 +08:00
1 parent d8e65ae4ef
commit 0d8265de03
5 files changed
+299 -1

No files matched your search

+49 -1
View File
@@ -36,7 +36,9 @@
↓
cpa_auths/xai-email.json 【注册机主导出】
↓ (cpa_copy_to_hotload=true 时)
CPA auth-dir 热加载 【可选】
CPA auth-dir 热加载 【可选·本地拷贝】
↓ (cpa_auto_import_remote=true 时)
CPA Management API 导入 【可选·HTTP】
↓
CLIProxyAPI :8317 model=grok-4.5
```
@@ -128,6 +130,8 @@ cp config.example.json config.json
| `GROK2API_APP_KEY` | 远端 grok2api Admin |
| `API_REVERSE_TOOLS` | 可选:外部 `cpa_xai` 父目录 |
| `CPA_EXPORT` | `auto_register` 是否导出 CPA(`0/false` 关) |
| `CPA_REMOTE_BASE` | 远程 CPA 根地址(配合 `cpa_auto_import_remote`) |
| `CPA_REMOTE_PASSWORD` | 远程 CPA 管理密码 |
| `https_proxy` / `http_proxy` | 代理回退 |
模板见 `.env.example`。
@@ -220,6 +224,48 @@ cpa_proxy > proxy > 环境变量 https_proxy/http_proxy
| `cpa_mint_cookie_inject` | `true` | 回退时注入注册 cookie |
| `cpa_mint_workers` | `-1` | mint 并发:`-1` 自动;`0` 内联;`1-10` 固定 |
| `cpa_mint_required` | `false` | mint 失败是否整号失败 |
| `cpa_auto_import_remote` | `false` | 写出后是否自动导入远程 CPA |
| `cpa_remote_base` | `""` | CPA **根地址**,如 `http://127.0.0.1:8317` |
| `cpa_remote_password` | `""` | CPA 管理密码(也可用环境变量) |
| `cpa_remote_import_retries` | `3` | 远程导入重试次数 |
| `cpa_remote_import_retry_delay` | `2` | 重试间隔(秒) |
### 自动导入远程 CPA(Management API)
写出 `cpa_auths/xai-*.json` 后,可自动调用 CLIProxyAPI 管理接口导入,无需再手动 `cp` 到 auth-dir。
```json
{
"cpa_export_enabled": true,
"cpa_auto_import_remote": true,
"cpa_remote_base": "http://127.0.0.1:8317",
"cpa_remote_password": "你的管理密码"
}
```
或写在 `.env`:
```bash
CPA_REMOTE_BASE=http://127.0.0.1:8317
CPA_REMOTE_PASSWORD=你的管理密码
```
说明:
- **只填根地址**(到端口即可);程序会请求
`POST {base}/v0/management/auth-files?name=xai-email.json`
- 认证头:`Authorization: Bearer <管理密码>`(同时附带 `X-Management-Key`)
- 管理密码对应 CPA 的 `MANAGEMENT_PASSWORD` 或 `remote-management.secret-key` **原文**
- 远程访问需 CPA 允许管理端(设置 `MANAGEMENT_PASSWORD` 或 `allow-remote: true`)
- **导入失败不阻断注册**:本地文件已写出仍算成功,只打日志
`[cpa] remote import failed: ...`
- 成功日志:`[cpa] remote import ok -> http://host:8317 name=xai-....json`
等价手动调用:
```bash
curl -sS -X POST "http://127.0.0.1:8317/v0/management/auth-files?name=xai-user@domain.json" -H "Authorization: Bearer $CPA_REMOTE_PASSWORD" -H "Content-Type: application/json" --data-binary @./cpa_auths/xai-user@domain.json
```
### 落盘约定
@@ -306,6 +352,7 @@ uv run python grok_register_ttk.py
2. 可选:推 grok2api
3. 若 `cpa_export_enabled`:协议 mint(失败则浏览器)→ `cpa_auths/xai-<email>.json`
4. 若 `cpa_copy_to_hotload`:再拷到 `cpa_hotload_dir`
5. 若 `cpa_auto_import_remote`:POST 导入到 CPA Management API(失败只记日志)
### B. 存量号补 CPA(只 mint,不重新注册)
@@ -392,6 +439,7 @@ curl -sS http://127.0.0.1:8317/v1/chat/completions \
| Hotmail 收不到码 | 检查四段凭证、ClientID/Token、IMAP 主机与 alias 计数 |
| 有 token 但无 grok-4.5 | `cpa_base_url` 是否为 `cli-chat-proxy` |
| 注册成功但无 `cpa_auths` | `cpa_export_enabled`?看 `cpa_auths/cpa_auth_failed.txt` |
| 远程导入失败 | 检查 `cpa_remote_base` / 管理密码、CPA 是否开启 management、`allow-remote`;本地文件仍在 `cpa_auths/` |
调试原则:以 **token 端点返回 `access_token` + refresh_token** 为准;probe 看 `/v1/models` 是否含 `grok-4.5`。