Self-hosted OpenAI-compatible API proxy for chat.z.ai (GLM-5.3 / GLM-5.2 / etc). Runs a real browser session via Playwright, so the site sees a genuine Chrome fingerprint — the invisible Aliyun captcha passes automatically.
Built for use with opencode and any other OpenAI-compatible client.
git clone https://github.com/lothiann/Free-ZAI-Api.git
cd Free-ZAI-Api
pip install -r requirements.txt
playwright install chromiumOpen https://chat.z.ai → DevTools (F12) → Console:
fetch('/api/v1/auths/').then(r=>r.json()).then(d=>window.__acc={id:d.id,email:d.email,name:d.name,token:d.token})copy(JSON.stringify(__acc))Paste into accounts.json:
{
"rotate_every": 10,
"accounts": [
{ "name": "main", "email": "you@gmail.com", "token": "eyJ..." }
]
}| Field | Description |
|---|---|
token |
JWT from DevTools (required) |
rotate_every |
requests per account before switching to the next one |
Accounts rotate round-robin — add more than one to spread load and survive a dead token.
python main.pyServer starts on http://127.0.0.1:8492/v1.
curl http://127.0.0.1:8492/v1/models
curl -N http://127.0.0.1:8492/v1/chat/completions \
-H "Content-Type: application/json" \
-d "{\"model\":\"glm-5.2\",\"stream\":true,\"messages\":[{\"role\":\"user\",\"content\":\"say OK\"}]}"
# account status
curl http://127.0.0.1:8492/accountsAdd to ~/.config/opencode/opencode.jsonc (or opencode.json):
apiKey is ignored — the proxy binds to 127.0.0.1 and does not check it.
| Endpoint | Description |
|---|---|
GET /v1/models |
model list parsed from the site |
POST /v1/chat/completions |
chat, streaming & non-streaming, with tools |
GET /accounts |
rotation status |
- Tool calling works out of the box: send standard OpenAI
tools, results come back asrole: "tool"messages — nothing to configure. - Reasoning is streamed via
delta.reasoning_content, the answer viadelta.content. usagecounts characters, matching the site's ~2M limit — thelimitvalues in the config above account for that.- Logs are written to
logs/, the last raw response tolast_response.json.
For personal / educational use. Automating chat.z.ai may violate its Terms of Service — use your own accounts at your own risk.

{ "provider": { "zai": { "npm": "@ai-sdk/openai-compatible", "name": "Z.AI (browser proxy)", "options": { "baseURL": "http://127.0.0.1:8492/v1", "apiKey": "sk-nothing" }, "models": { "glm-5.3": { "name": "GLM-5.3", "limit": { "context": 2000000, "output": 2000000 } }, "x-preview-l": { "name": "GLM-5.3 Flash", "limit": { "context": 2000000, "output": 2000000 } }, "glm-5.2": { "name": "GLM-5.2", "limit": { "context": 2000000, "output": 2000000 } }, "GLM-5-Turbo": { "name": "GLM-5 Turbo", "limit": { "context": 2000000, "output": 2000000 } }, "GLM-5v-Turbo": { "name": "GLM-5v Turbo", "limit": { "context": 2000000, "output": 2000000 } }, "glm-4.7": { "name": "GLM-4.7", "limit": { "context": 2000000, "output": 2000000 } }, "glm-4.6v": { "name": "GLM-4.6v", "limit": { "context": 2000000, "output": 2000000 } }, "GLM-4.1V-Thinking-FlashX": { "name": "GLM-4.1V Thinking FlashX", "limit": { "context": 2000000, "output": 2000000 } }, "deep-research": { "name": "Deep Research", "limit": { "context": 2000000, "output": 2000000 } }, "zero": { "name": "Zero", "limit": { "context": 2000000, "output": 2000000 } }, "0727-106B-API": { "name": "0727 106B API", "limit": { "context": 2000000, "output": 2000000 } }, "0727-360B-API": { "name": "0727 360B API", "limit": { "context": 2000000, "output": 2000000 } }, "0808-360B-DR": { "name": "0808 360B DR", "limit": { "context": 2000000, "output": 2000000 } }, "glm-4-flash": { "name": "GLM-4 Flash", "limit": { "context": 2000000, "output": 2000000 } }, "glm-4-air-250414": { "name": "GLM-4 Air", "limit": { "context": 2000000, "output": 2000000 } } } } } }