How orbitoo/zai2api works
zai2api is an OpenAI-compatible proxy for Z.ai. API clients send chat-completion or Responses requests; the server authenticates and normalizes them, assembles prompts, obtains upstream output, and returns OpenAI-shaped responses, including streaming. A separate admin UI supports account management, security settings, and logs. The account pool routes requests through stored or environment-provided accounts. Edges reflect sampled calls, imports listed in the source index, or README-documented capabilities; unsampled internals are represented only where the README or tree supports them.
Main entry points: server.py HTTP API server · account_pool.py Account routing · auth.py Authentication · admin_page.py Admin UI
Components 11
Proxy API
- HTTP API server
src/zai2api/server.py - Prompt assembly
src/zai2api/prompt_assembly.py
Z.ai integration
- Account routing
src/zai2api/account_pool.py - Z.ai client
src/zai2api/zai_client.py
Administration
- Admin UI
src/zai2api/admin_page.py - Authentication
src/zai2api/auth.py
Configuration and state
- Settings
src/zai2api/config.py - SQLite state
src/zai2api/db.py
Other components
- API client
- Z.ai service
- Admin browser
Connections 15
- API client → HTTP API server: sends requests
README.md - HTTP API server → Authentication: checks credentials
src/zai2api/server.py - HTTP API server → Prompt assembly: assembles prompts
src/zai2api/server.py - HTTP API server → Account routing: routes completions
src/zai2api/server.py - HTTP API server → SQLite state: records request logs
src/zai2api/server.py - HTTP API server → Admin UI: renders UI
src/zai2api/server.py - HTTP API server → Settings: reads settings
src/zai2api/server.py - Account routing → Z.ai client: creates clients
src/zai2api/account_pool.py - Account routing → SQLite state: loads account state
src/zai2api/account_pool.py - Account routing → Settings: uses settings
src/zai2api/account_pool.py - Z.ai client → Z.ai service: authenticates and streams
src/zai2api/zai_client.py - Authentication → SQLite state: reads and writes sessions
src/zai2api/auth.py - Authentication → Settings: reads credentials config
src/zai2api/auth.py - Admin browser → Admin UI: uses interface
src/zai2api/admin_page.py - Admin UI → HTTP API server: calls admin APIs
src/zai2api/admin_page.py