How chaoticmindv/zai2api works
nodez2ai is a Node.js gateway that exposes OpenAI-compatible chat and model endpoints, forwards requests to Z.AI, and provides a web dashboard. Its main flow is client request → HTTP routes → Z.AI session/request handling → streamed or complete response; chat sessions retain conversation state, and tool calls and reasoning are adapted for the upstream model. A separate token lifecycle collects device tokens, stores them in SQLite, and replenishes the pool in the background. The route excerpt is partial, so some links—especially tool handling and worker startup—are not directly verified.
Main entry points: index.js HTTP Routes · zai.js Z.AI Session · collector.js Device Token Collector · db.js SQLite Token Store
Components 14
Gateway API
- HTTP Routes
src/index.js - Web Dashboard
src/dashboard.js
Z.AI Integration
- Z.AI Session
src/zai.js - Conversation Store
src/zai.js - Tool and Reasoning Adapter
src/tools.js - Captcha Verification
src/captcha.js
Token Lifecycle
- Device Token Collector
src/collector.js - Token Replenishment Worker
src/worker.js - SQLite Token Store
src/db.js
Configuration and State
- Runtime Configuration
src/config.js
Other components
- API Client
- Z.AI Service
- Playwright Browser
- Aliyun Captcha
Connections 17
- API Client → HTTP Routes: sends requests
README.md - HTTP Routes → API Client: returns responses
README.md - HTTP Routes → Z.AI Session: forwards chat
src/index.js - HTTP Routes → Conversation Store: tracks sessions
src/index.js - HTTP Routes → Web Dashboard: renders page
src/index.js - HTTP Routes → Tool and Reasoning Adapter: adapts tool calls
src/index.js - Z.AI Session → Z.AI Service: sends chat
README.md - Z.AI Session → Captcha Verification: computes captcha
src/zai.js - Z.AI Session → Tool and Reasoning Adapter: splits reasoning
src/zai.js - Captcha Verification → Aliyun Captcha: verifies captcha
src/captcha.js - Token Replenishment Worker → Device Token Collector: collects batches
src/worker.js - Token Replenishment Worker → SQLite Token Store: checks pool
src/worker.js - Device Token Collector → Playwright Browser: harvests tokens
src/collector.js - Device Token Collector → SQLite Token Store: stores tokens
src/collector.js - Z.AI Session → SQLite Token Store: uses tokens
- HTTP Routes → Runtime Configuration: reads settings
src/index.js - Z.AI Session → Runtime Configuration: reads settings
src/zai.js