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
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.How It Works
| Component | Role |
|---|---|
| Gateway Server | Manages WebSocket connections and routes messages |
| Channels | Platform-specific integrations (Telegram, Discord, etc.) |
| Router | Directs messages to appropriate agents based on rules |
| Agents | Process messages and generate responses |
| Inbound Triggers | POST /hooks/<path> — start agent runs from external HTTP events (webhooks, CI, IoT). See Inbound Hooks. |
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. 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 - Shutdown forensics — on every exit, one log line and one diagnostic file record why the gateway stopped. See Crash Forensics.
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.
| Option | Type | Default | Description |
|---|---|---|---|
host | str | "127.0.0.1" | Gateway bind address |
port | int | 8765 | Gateway port |
max_connections | int | 100 | WebSocket connection limit |
heartbeat_interval | int | 30 | WebSocket ping interval |
session_timeout | int | 3600 | Session expiration in seconds |
session.persist | bool | false | Persist sessions across restarts |
session.persist_path | str | ~/.praisonai/sessions/ | Storage directory |
session.resume_window | int | 86400 | Seconds detached sessions stay resumable |
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.
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

