Zen Gateway is a local proxy that forwards requests to OpenCode's free AI models. It accepts both OpenAI and Anthropic API formats.
uv run python zen_client.py --serve --port 8462
curl http://127.0.0.1:8462/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "mimo-v2-pro-free",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Use Zen Gateway as a free backend for Claude Code.
In ~/.claude.json, add:
{ "hasCompletedOnboarding": true }
.zshrc or .bashrc, then run pclaude instead of claude.~/.claude/settings.json. Persists across terminal sessions.To use the extended 1M token context window, run this inside Claude Code:
/model opus[1m]
Or append it when launching from terminal:
pclaude --model 'opus[1m]'
Returns the list of available free models.
curl http://127.0.0.1:8462/v1/models
| Model ID | Name | Status |
|---|---|---|
mimo-v2-pro-free | MiMo V2 Pro Free | Free |
mimo-v2-omni-free | MiMo V2 Omni Free | Free |
big-pickle | Big Pickle | Free |
nemotron-3-super-free | Nemotron 3 Super Free | Free |
minimax-m2.5-free | MiniMax M2.5 Free | Free |
OpenAI-compatible chat completions endpoint. Supports streaming.
curl http://127.0.0.1:8462/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-zen-your-key" \
-d '{
"model": "mimo-v2-pro-free",
"messages": [{"role": "user", "content": "Explain quantum computing"}],
"stream": true
}'
Anthropic Messages API compatible endpoint. Automatically translates to OpenAI format and back.
curl http://127.0.0.1:8462/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: sk-zen-your-key" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "mimo-v2-pro-free",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'
By default, authentication is disabled. When enabled via the Admin panel, all proxy requests require a valid API key.
API keys use the sk-zen- prefix and can be passed via:
| Method | Example |
|---|---|
| Authorization header | Authorization: Bearer sk-zen-abcdef1234... |
| x-api-key header | x-api-key: sk-zen-abcdef1234... |
Create and manage API keys from the Admin dashboard.
Token estimation endpoint. Returns approximate input token count for the given messages. Used by Claude Code for context window management.
curl http://127.0.0.1:8462/v1/messages/count_tokens \
-H "Content-Type: application/json" \
-d '{
"model": "mimo-v2-pro-free",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Rate limits are IP-based, enforced by OpenCode Zen server-side. The gateway sends x-opencode-client: cli headers for higher limits.
To bypass IP-based rate limits, the gateway supports proxy rotation with three modes:
| Mode | Behavior |
|---|---|
Off | Direct connection only (default) |
Auto | Direct until 429 rate-limited, then auto-switches to rotating proxies. Retries direct every 5 minutes. |
On | Always route through proxies |
Proxies are dynamically fetched from Geonode (HTTP/HTTPS, filtered by uptime). The pool auto-refreshes every 30 minutes. Each request retries up to 5 different proxies on failure.
Configure via the Admin panel or the proxy API endpoints below.
The gateway automatically sets all required OpenCode headers on every upstream request:
| Header | Purpose |
|---|---|
x-opencode-client | Identifies as CLI client for higher rate limits |
x-opencode-session | Stable session ID per gateway instance |
x-opencode-request | Unique request ID per call |
x-opencode-project | Project identifier |
All stats endpoints require admin authentication via Authorization: Bearer TOKEN.
Returns gateway statistics: total requests, errors, avg latency, uptime, input/output token totals, and recent requests.
Paginated request log. Supports ?limit=100&offset=0. Each entry includes method, path, model, format, stream, status, latency, tokens, API key, proxy used, input messages, output content, and error.
Clears all request log entries from the database.
All admin endpoints require authentication. Obtain a token via /_admin/login.
Authenticate with admin password. Returns a session token.
curl http://127.0.0.1:8462/_admin/login \
-H "Content-Type: application/json" \
-d '{"password": "admin"}'
List all API keys with prefix, name, created date, last used, and active status.
Create a new sk-zen-* API key. Returns the full key (shown once).
Revoke an API key by ID.
Get all gateway settings (require_auth, proxy_enabled, etc).
Update a setting. Body: {"key": "require_auth", "value": "true"}
Change admin password. Body: {"old_password": "...", "new_password": "..."}
Returns proxy pool status: mode, enabled, using_proxy, rate_limited_direct, total/alive/dead counts.
Cycle proxy mode: Off → Auto → On → Off.
Trigger immediate proxy pool refresh from Geonode.
Update proxy filters. Body: {"min_uptime": 80}