A lightweight, modular, self-hosted OpenAI-compatible API Gateway and AI Discord Bot built with Express.js and Discord.js.
Drop any module file into the api/ folder and it appears instantly on the dynamic interactive documentation site (/docs) — no config files or rebuilds required!
- Developer / Maintainer: frnAlt
- GitHub Profile: https://github.com/frnAlt
- Repository URL: https://github.com/frnAlt/zaiis2api
- Issue Tracker: https://github.com/frnAlt/zaiis2api/issues
- 🤖 Native AI Discord Bot (
discord_bot.js): Out-of-the-box Discord bot with streaming AI responses, model selection, typing indicators, and multi-message splitting. - ⚡ OpenAI-Compatible Gateway:
/v1/chat/completionsand/v1/modelsendpoints compatible with standard OpenAI SDKs and tools. - 🔑 Automatic Token Load Balancer: Dynamically rotates zAI & Discord tokens for maximum reliability.
- 📦 Dynamic Module Auto-Loader: Drop a
.jsmodule file anywhere insideapi/(subfolders supported:api/ai/,api/tools/,api/info/) and the server automatically registers the endpoint on startup. - 🌐 Interactive Documentation (
/docs): Dynamic OpenAPI-style UI with live search, category filtering, parameter preview, and a built-in "Try It Out" API runner. - 🐳 Docker Ready: Preconfigured
Dockerfileanddocker-compose.ymlfor instant deployment.
.
├── api/ # Dynamic API modules
│ ├── ai/
│ │ ├── zai_chat.js # /v1/chat/completions (OpenAI Compatible)
│ │ └── models.js # /v1/models
│ ├── tools/
│ │ └── token_manager.js # /api/tools/token-status
│ └── info/
│ └── ping.js # /api/info/ping
├── core/ # Server core & middleware
├── json/ # Configuration & tokens storage
├── png/ # Setup screenshots & documentation images
│ ├── discord_bot_preview.png
│ └── get_discord_token.png
├── discord_bot.js # Ready-to-run AI Discord Bot
├── index.js # Gateway entry point
├── package.json
└── README.md
npm installnpm startFor development mode (auto-reload on Node 18+):
npm run devThe server starts on port 5000 by default.
- Landing Page:
http://localhost:5000 - Interactive Docs:
http://localhost:5000/docs - Management Console:
http://localhost:5000/manage - OpenAI Base:
http://localhost:5000/v1
- Open discord.com/app on Chrome / Edge / Brave and log into your Discord account.
- Press
F12to open Developer Tools. - Go to the Console tab, paste the following command, and press
Enter:window.webpackChunkdiscord_app.push([[Math.random()],{},e=>{for(constmofObject.values(e.c))if(m?.exports?.default?.getToken!==undefined)console.log(m.exports.default.getToken())}])
- Copy your user token.
- Open
http://localhost:5000/managein your browser and add the token to the system.
Follow these simple steps to run your AI Discord Bot:
- Go to Discord Developer Portal.
- Click New Application, enter a name (e.g.
zAI Assistant), and click Create. - Go to the Bot tab on the left menu:
- Click Reset Token (or Add Bot) and copy your Bot Token.
- CRITICAL STEP - Enable Privileged Gateway Intents:
- Scroll down to Privileged Gateway Intents.
- Enable MESSAGE CONTENT INTENT 🟢.
- Click Save Changes.
- Go to OAuth2 -> URL Generator.
- Under Scopes, select
bot. - Under Bot Permissions, select:
Send MessagesRead Message HistoryEmbed Links
- Copy the generated URL, paste it into your browser, select your server, and click Authorize.
Make sure the API Gateway (npm start) is running, then open a terminal and run:
node discord_bot.js YOUR_DISCORD_BOT_TOKENOr set the environment variable:
export DISCORD_BOT_TOKEN="YOUR_DISCORD_BOT_TOKEN"
node discord_bot.jsIn any channel on your Discord server:
!ai <prompt>➜ Ask the bot any question (e.g.,!ai Write a python quicksort function).@zAI Assistant <prompt>➜ Mention the bot directly.!models➜ List available AI models.!ping➜ Check bot latency.
| Endpoint | Method | Description |
|---|---|---|
/v1/chat/completions | POST | OpenAI-compatible chat completions |
/v1/models | GET | List all supported AI models |
/api/info/ping | GET | System health check & uptime |
/api/tools/token-status | GET | Active token count & rotation status |
/docs | GET | Interactive OpenAPI documentation UI |
docker-compose up -dThis project is for educational and research purposes only.

