WebUI HTTP API Entry
This subdirectory covers the HTTP / WebSocket APIs exposed by the MaiBot WebUI backend, targeting deployment ops personnel and users who need scripted management. If you only use the WebUI panel through a browser, you don't need to read this content.
Before proceeding, start with this page. It explains the skeleton of the entire API: how the server runs, how you authenticate, which route groups exist, and where to jump for specific scenarios.
FastAPI Backend Overview
The WebUI backend is a FastAPI application that starts alongside the MaiBot main process. Default behavior:
- Listening port —
8001(WebUIConfig.port) - Bind addresses —
127.0.0.1and::1(WebUIConfig.host) - Run mode —
production(WebUIConfig.mode), switch todevelopmentduring development
Security Warning
By default, the server binds to loopback addresses and is only accessible locally. Never set host to 0.0.0.0 and expose it directly on the public internet — the WebUI does not include built-in TLS termination or WAF. If remote access is required, route traffic through a reverse proxy (Nginx / Caddy) and configure the proxy IP in webui.trusted_proxies.
Key configuration options at a glance:
webui.enabled—trueto start WebUI,falseto fully disablewebui.host— List of listening addresses, can bind both IPv4 and IPv6 simultaneouslywebui.port— Listening port, default8001webui.allowed_ips— IP whitelist, comma-separatedwebui.secure_cookie— Whether to only send the login Cookie over HTTPSwebui.anti_crawler_mode— Anti-crawler level, defaultbasicwebui.trusted_proxies— Reverse proxy IP listwebui.trust_xff— Whether to trust theX-Forwarded-Forheader
These fields are defined in the WebUIConfig class in src/config/official_configs.py. All can be read/written via the WebUI configuration interface or the /api/config/raw endpoint.
Authentication Model: Three Methods
The vast majority of WebUI API endpoints require authentication. MaiBot provides three authentication methods, covering browser, scripting tools, and WebSocket scenarios.
1. Cookie Token (Primary Browser Mode)
This is the default authentication path for the WebUI frontend. Flow:
- Obtain the temporary Token from MaiBot's startup log (auto-generated on first startup, printed in the terminal)
- Call
POST /api/webui/auth/verifywith this Token - After server-side validation passes, an HttpOnly Cookie (
maibot_session) is set in theSet-Cookieheader, valid for 7 days - Subsequent requests automatically carry this Cookie — no need to pass the Token each time
/auth/verify request example:
curl -X POST http://127.0.0.1:8001/api/webui/auth/verify \
-H "Content-Type: application/json" \
-d '{"token": "你的临时或固定Token"}'Related endpoints:
POST /api/webui/auth/verify— Verify Token and set Cookie (rate-limited: 5 attempts / 5 minutes, trigger results in 10-minute ban)GET /api/webui/auth/check— Check whether the current Cookie is still validPOST /api/webui/auth/logout— Clear Cookie, log outPOST /api/webui/auth/update— Replace with a custom Token (requires login)POST /api/webui/auth/regenerate— Have the system regenerate a random Token (requires login)
/auth/check query example:
curl -X GET http://127.0.0.1:8001/api/webui/auth/check \
-H "Cookie: maibot_session=你的Token"2. api_server_allowed_api_keys (Script / External Calls)
When calling the WebUI API from scripts, CI pipelines, or other external services, you can use the api_server_allowed_api_keys whitelist from the MaimMessage configuration. These API Keys are validated at MaiBot's message server and are suited for automation scenarios not tied to browser Cookies.
When calling via API Key, populate the maibot_session Cookie with the Key value to bypass the WebUI's own Token verification (provided the Key is in the message service whitelist and maps to a valid token).
3. WebSocket Temporary Token
Browser-side WebSocket connections cannot carry custom HTTP Headers and cannot reliably carry Cookies. MaiBot provides a temporary Token mechanism for this:
- The frontend first authenticates via Cookie, then calls
GET /api/webui/ws-token - The server generates a one-time temporary Token, valid for 60 seconds, consumed on use
- The frontend uses this temporary Token as the
?token=query parameter in the WebSocket URL to complete the handshake
curl -X GET http://127.0.0.1:8001/api/webui/ws-token \
-H "Cookie: maibot_session=你的Token"Route Structure and Base Path
The entire API is organized in two layers: the main routes are mounted under /api/webui, and three compat routes are registered independently.
Main Routes: /api/webui/*
The core is the APIRouter(prefix="/api/webui") created in src/webui/routes.py. It aggregates the following sub-route modules (all mounted under /api/webui/):
/health— Health check (no auth required)/auth/*— Authentication/setup/*— First-time setup wizard/config/*— Runtime config read/write (TOML format)/person/*— Person info management/model/*— Model list and connectivity verification/plugin/*— Plugin lifecycle management/system/*— System control and data migration/memory/*— Long-term memory graph/emoji/*— Emoji/sticker management/expression/*,/jargon/*,/behavior/*— Expression styles, slang, behaviors/statistics/*— Statistics/avatar/*— Avatars/ws-token— WebSocket temporary Token- WebSocket endpoints (
unifiedunified channel,logslog stream,plugin/progressplugin progress)
Compat Routers
For compatibility with older frontends and some external integrations, the following three routes bypass the /api/webui prefix and are registered independently:
/api/config/* (module src/webui/routers/config.py) — Structured read/write of TOML configuration. Paths include /api/config/schema (get config form schema), /api/config/raw (read/write complete TOML content).
/api/* (module src/webui/routers/memory.py) — Full REST interface for the Amemorix memory graph. Paths include /api/graph (knowledge graph query), /api/episodes (memory episodes), /api/import (data import), /api/retrieval_tuning (retrieval tuning).
/api/chat/* (module src/webui/routers/chat/) — Local chat room. The "chat directly with MaiMai" feature in the WebUI is implemented through these endpoints.
When to use: If you're writing automation scripts, prefer the /api/webui/* main routes (consistent paths, uniform auth). Use the compat routes only when existing scripts depend on old paths, or when doing large-scale data operations on the memory graph.
Quick Connectivity Test
The simplest health check requires no authentication — a single curl confirms whether the backend is running:
curl http://127.0.0.1:8001/api/webui/healthExpected response:
{"status": "healthy", "service": "MaiBot WebUI"}First Run Setup Flow
On first startup, the TokenManager generates a temporary Token and prints it in the terminal log. When the WebUI frontend detects token_source is temporary, it enters the first-time setup wizard.
There are only two key endpoints:
GET /api/webui/setup/status(auth required) — Check whether in first-setup statePOST /api/webui/setup/complete(auth required) — Mark setup as complete
Full flow:
- Call
/auth/verifywith the temporary Token to get a Cookie - Call
/setup/statusto confirmis_first_setup: true - Complete basic setup in the WebUI (model, persona, etc.)
- Call
POST /auth/updateto replace with a permanent custom Token - Call
POST /setup/completeto mark as done
Additionally, POST /api/webui/setup/reset clears the config state and rebuilds the wizard flow. Typically used during migration or reset.
Roadmap
Jump to the corresponding sub-page based on what you need:
- [This page] WebUI HTTP API Entry — API skeleton, auth, route structure, health check, first-time setup
- Auth and First Setup — Full Token replacement/regeneration/logout flow, First Run Setup automation scripts
- System Control — Ops endpoints: restart, shutdown, log viewing, runtime status queries
- Plugin Lifecycle API — HTTP interface for installing, uninstalling, enabling, disabling plugins
- Data and Memory API — Amemorix memory graph CRUD, data import/export, retrieval tuning
- Realtime and Stats — WebSocket (unified channel, log stream, plugin progress) and statistics queries
Next Steps
If you're writing a script to interface with the WebUI API, follow this order:
- Start with
/healthto ensure the backend is online - Go through
/auth/verifyto log in and get a Cookie - Consult the roadmap to find the scenario page you need, then write logic following its endpoint examples
All endpoints (except /health) require authentication. Cookies are valid for 7 days — long-running scripts should handle re-login after Cookie expiry.