Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
captcha_node/node_modules/
*.log
config.yaml
.omo/evidence/
Expand All @@ -8,3 +9,6 @@ dist/
/.omo
/_reverse
/zcode-proxy.exe
runner/__pycache__/*
runner/explore
runner/lib/__pycache__
99 changes: 97 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ cp config.example.yaml config.yaml
# Start the proxy
bun run src/index.ts

# Open the web dashboard
# http://localhost:8080/app

# Or specify a config path
bun run src/index.ts /path/to/config.yaml
```
Expand Down Expand Up @@ -64,14 +67,105 @@ If you already use the ZCode desktop app, import the API key directly:
bun run src/index.ts auth login bigmodel --import
```

### Option 4: ZCode Start Plan (free tier, JWT + captcha)

Start Plan uses `zcode.z.ai` with OAuth JWT and Aliyun traceless captcha — not the paid `api.z.ai` key.

**Web dashboard (recommended):**

```bash
bun run src/index.ts
# open http://localhost:8080/app
```

Click **Add account (OAuth)** — sign in, quota provisioning, and pool setup happen automatically.

**CLI alternatives:**

```bash
bun run src/index.ts auth onboard zai # new account
bun run src/index.ts auth import-jwt # existing ZCode desktop login
```

**Then configure and start:**

```yaml
auth:
mode: oauth
proxyApiKey: "your-proxy-secret"
plan: start-plan
provider: zai

identity:
appVersion: "3.1.2"
```

```bash
bun run src/index.ts
```

Requires Node.js for captcha solver (`captcha_node/` — installed automatically on first use).

```bash
curl http://localhost:8080/v1/messages \
-H "x-api-key: your-proxy-secret" \
-H "Content-Type: application/json" \
-d '{"model":"glm-5.2","max_tokens":32,"messages":[{"role":"user","content":"say ok"}]}'
```

Re-run `auth import-jwt` or `auth onboard zai` after switching accounts. **Test one message at a time** — burst captcha requests can trigger abuse block (3012).

### Multi-account pool (one app, load balancing)

**Use the web dashboard** at `http://localhost:8080/app` — add accounts via OAuth, import from desktop, paste JWTs, pause/remove accounts, and send test messages. No CLI required.

Add multiple Start Plan accounts; the proxy round-robins and auto-fails over on quota (`1005`), abuse block (`3012`), or bad JWT (`401`).

```bash
# Add accounts (each runs OAuth + optional ZCode provisioning)
bun run src/index.ts auth onboard zai --name acct-1
bun run src/index.ts auth onboard zai --name acct-2

# Or add an existing JWT
bun run src/index.ts auth add acct-3 --jwt eyJ...

# List / remove
bun run src/index.ts auth accounts
bun run src/index.ts auth remove <account-id>
```

Enable in `config.yaml` (default when accounts exist):

```yaml
pool:
enabled: true
maxAccountAttempts: 5 # try up to N accounts per request
```

HTTP admin (requires `auth.proxyApiKey`):

```bash
curl http://localhost:8080/admin/accounts -H "x-api-key: your-proxy-secret"
curl -X POST http://localhost:8080/admin/accounts/<id>/enable -H "x-api-key: your-proxy-secret"
curl -X DELETE http://localhost:8080/admin/accounts/<id> -H "x-api-key: your-proxy-secret"
```

`GET /health` includes pool summary (account count, enabled, last errors).

Fixes #2.

## Endpoints

| Method | Path | Description |
|--------|------|-------------|
| `POST` | `/v1/chat/completions` | OpenAI-compatible chat completions (streaming + non-streaming) |
| `POST` | `/v1/messages` | Anthropic-format messages (streaming + non-streaming) |
| `GET` | `/v1/models` | List available models |
| `GET` | `/health` | Health check |
| `GET` | `/app` | Web dashboard (account management UI) |
| `GET` | `/health` | Health check (+ pool summary when enabled) |
| `GET` | `/admin/accounts` | List account pool (proxy API key required) |
| `POST` | `/admin/accounts/:id/enable` | Re-enable a disabled account |
| `DELETE` | `/admin/accounts/:id` | Remove account from pool |

## Usage Examples

Expand Down Expand Up @@ -129,7 +223,8 @@ curl http://localhost:8080/v1/models \
| `auth.apiKey` | `ZCODE_API_KEY` | — | Upstream API key |
| `auth.proxyApiKey` | `ZCODE_PROXY_API_KEY` | — | Client auth key |
| `provider` | `ZCODE_PROVIDER` | `zai` | Upstream provider |
| `identity.appVersion` | `ZCODE_APP_VERSION` | `3.1.1` | `User-Agent: ZCode/{version}` |
| `identity.appVersion` | `ZCODE_APP_VERSION` | `3.1.2` | `User-Agent: ZCode/{version}` |
| `plan` | — | `coding-plan` | `start-plan` for ZCode free tier (JWT + captcha) |
| `identity.sourceTitle` | `ZCODE_SOURCE_TITLE` | `cli` | `X-Title: Z Code@{title}` |
| `identity.refererOrigin` | `ZCODE_REFERER_ORIGIN` | `https://zcode.z.ai` | `HTTP-Referer` URL |

Expand Down
9 changes: 0 additions & 9 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading