The gateway now ships in the
praisonai-bot package. praisonai serve gateway still works exactly as documented here; for a standalone install see praisonai-bot Migration.Quick Start
1
Install Gateway Dependencies
Install both bot and API dependencies for gateway functionality:The
[api] extra provides uvicorn, fastapi, and starlette required by the gateway server.2
Create Gateway Configuration
Create a
gateway.yaml file:3
Start the Gateway
Launch the gateway server:The gateway starts on port 8765 with WebSocket and HTTP health endpoints.
How It Works
Architecture Principles
Single Instance Rule
Critical: Only run one gateway process per machine. Multiple processes conflict:- Both try to bind port 8765
- Both poll the same Telegram token (causes 409 conflicts)
- Session state becomes inconsistent
Channel Isolation
Each channel operates independently:- Separate token per platform
- Independent routing rules
- Isolated session management
- Per-channel error handling
Live Config Reload
The gateway diffsgateway.yaml against the running config and restarts only affected agents or channels — and for three timing/logging keys, applies the change in place with no restart at all. Invalid YAML saves keep the last-known-good config. The WebSocket server is never restarted. See Gateway Hot-Reload.
Fail-Safe Design
The gateway implements fail-safe patterns:- Health checks at
/healthendpoint - Automatic reconnection for platform polling
- Graceful degradation when agents are unavailable
- Request timeout handling (25-30 seconds for RAG)
- Versioned
hellohandshake with capability negotiation — see Handshake Protocol. Connecting from Python, the bundledpraisonai-botclient performs this handshake automatically and exposes the negotiatedclient.features/client.policy/client.heartbeat_ms— see Client-side wiring. - Shutdown forensics — on every exit, one log line and one diagnostic file record why the gateway stopped. See Crash Forensics.
- Opt-in close-the-loop notice on permanent delivery failure — see Undelivered Message Notice.
Config Validation
A typo ingateway.yaml won’t start a broken gateway — it fails fast with exit 78 before your users notice.
praisonai gateway start and praisonai bot serve now validate the same gateway.yaml to the same standard: canonical configs start, legacy configs auto-migrate then start, and typos exit 78.
The validator consults the platform registry — built-in platforms plus any published via praisonai.channels / praisonai.bots entry points plus any registered at runtime with register_platform().
Typo channel (telegran) — rejected, exit 78
Typo channel (telegran) — rejected, exit 78
/health returns 200 — but Telegram is silently dead.Real adapter (linear) — accepted cleanly
Real adapter (linear) — accepted cleanly
linear is a shipped adapter on the registry.Plugin channel (mattermost) — accepted via register_platform()
Plugin channel (mattermost) — accepted via register_platform()
praisonai bot serve and praisonai gateway start.Gateway Modes
Multi-Channel Mode
Multi-Channel Mode
Run multiple platforms simultaneously:Each channel requires a unique token and can route to different agents.
WebSocket-Only Mode
WebSocket-Only Mode
Pure WebSocket server without chat platforms:Provides WebSocket endpoint for custom client integration.
Agent File Mode
Agent File Mode
Load agents from separate configuration:Separates agent definitions from gateway configuration.
Health Monitoring
The gateway exposes health information:Health Check Limitations
Current implementation limitations:"running": truedoesn’t guarantee platform polling health- No detection of Telegram 409 conflicts until PraisonAI fix ships
- Manual verification required for silent bot issues
Configuration Options
For complete configuration reference, see the auto-generated SDK documentation. The table below shows common options.
Best Practices
Edit gateway.yaml live
Edit gateway.yaml live
You can change agent instructions, models, or a single channel section while the gateway runs. Agent-only edits recreate agents without restarting channels. See Hot-Reload.
Use environment variables for secrets
Use environment variables for secrets
Never hardcode tokens in configuration files:Store tokens in
.env file or environment variables.Implement proper error handling
Implement proper error handling
Monitor gateway logs for platform-specific errors:
Configure resource limits
Configure resource limits
Set appropriate limits based on expected load:
Use unique tokens per channel
Use unique tokens per channel
Each channel must have its own platform token:Never reuse tokens across channels.
Cost Optimization
Running a PraisonAI gateway on serverless hosts (Fly.io Machines, Modal, Cloud Run) charges for every second the machine is alive — even when no users are chatting. The Scale-to-Zero feature lets the gateway stand transports down after a configurable period of silence and wake back up on the next inbound message, so you pay only for active time.Scale-to-Zero Gateway
Suspend the gateway when idle and wake on the next message — pay only for active time.
Lifecycle
Three opt-in lifecycle policies wire into the primaryWebSocketGateway through a lifecycle: block in gateway.yaml, matching CLI flags, and a Python surface. Each is off unless enabled, and configured features surface under health()["lifecycle"].
Scale to Zero
Quiesce when idle for
idle_minutes and self-wake on the next message.Drain Trigger
Epoch-safe external drain marker with a built-in watcher.
Crash-Loop Guard
Halt auto-resume of a channel that keeps crashing on resume.
Event-Loop Watchdog
Detect a wedged asyncio loop and restart before it becomes a zombie.
Related
Admission Control
Bound concurrent inbound agent runs with a fair queue and overflow policy
Session Persistence
Survive restarts and resume mid-conversation
Windows Deployment
Complete Windows setup guide
Multi-Channel Telegram
Hermes-style workforce deployment
Scale to Zero
Pay only for active time — idle-dormancy for serverless hosts
Tracing Hook
Emit OpenTelemetry spans across each pipeline stage
Undelivered Notice
Notify users and operators when a reply can’t be delivered

