GLM proxy service based on FastAPI + Granian Suitable for local development, self-hosted proxy, Token pool management, and compatible client access
English / 中文简体
- Compatible with
OpenAI,Claude Code,Anthropicstyle requests - Supports streaming responses, tool calls, Thinking models
- Built-in Token pool, supports polling, failure circuit breaker, recovery, and health checks
- Provides admin panel: Dashboard, Token management, Configuration management, Real-time logs
- Uses SQLite to store Tokens and request logs, simple deployment
- Supports local running and Docker / Docker Compose deployment
- Python
3.9to3.12 - Recommend using
uv
git clone https://github.com/ZyphrZero/z.ai2api_python.git
cd z.ai2api_python
uv sync
cp .env.example .env
uv run python main.pyFirst startup will automatically initialize the database.
Default addresses:
- API root path:
http://127.0.0.1:8080 - OpenAI docs:
http://127.0.0.1:8080/docs - Admin panel:
http://127.0.0.1:8080/admin
docker compose -f deploy/docker-compose.yml up -d --buildMore deployment instructions see deploy/README_DOCKER.md.
At least suggest confirming these environment variables:
| Variable | Description |
|---|---|
AUTH_TOKEN |
Bearer Token used by clients to access this service |
ADMIN_PASSWORD |
Admin panel login password, default value must be changed |
LISTEN_PORT |
Service listening port, default 8080 |
ANONYMOUS_MODE |
Whether to enable anonymous mode |
GUEST_POOL_SIZE |
Anonymous pool capacity |
DB_PATH |
SQLite database path |
TOKEN_FAILURE_THRESHOLD |
Token consecutive failure threshold |
TOKEN_RECOVERY_TIMEOUT |
Token recovery wait time |
Complete configuration please see .env.example.
Admin panel unified entry:
/admin: Dashboard/admin/tokens: Token management/admin/config: Configuration management/admin/logs: Real-time logs
# Start service
uv run python main.py
# Run tests
uv run pytest
# Run an existing smoke test
uv run python tests/test_simple_signature.py
# Lint
uv run ruff check app tests main.pyCommon interface entries:
- OpenAI compatible:
/v1/chat/completions - Anthropic compatible:
/v1/messages - Claude Code compatible:
/anthropic/v1/messages
Model mapping and default model can be adjusted in .env or admin configuration page.
This project uses MIT license - see LICENSE file for details.
- This project is for learning and research use only, do not use for other purposes
- This project is not affiliated with Z.AI official
- Please ensure compliance with Z.AI's terms of service before use
- Do not use for commercial purposes or scenarios that violate terms of service
- Users must bear their own usage risks
Made with ❤️ by the community