Skip to main content

Gateway

The Gateway is the heart of OpenClaw—a WebSocket server that acts as the central control plane for all messaging channels, AI agents, and platform apps.

What is the Gateway?

The Gateway is a background process that:
  • Runs a WebSocket server at ws://127.0.0.1:18789 (default)
  • Manages messaging channels (WhatsApp, Telegram, Discord, etc.)
  • Routes messages to appropriate AI agents based on configuration
  • Maintains sessions for conversation context
  • Provides HTTP endpoints for Control UI and webhooks
  • Broadcasts events to connected clients

Gateway Process

Starting the Gateway

Manual Start:
With Daemon:
Location: src/gateway/, src/daemon/

Gateway Lock

The Gateway uses a lock file to prevent multiple instances:
If the Gateway won’t start, check for stale lock files:
Location: src/infra/gateway-lock.ts:6

Process Modes

The Gateway can run in different modes:
  1. Local: Binds to 127.0.0.1 (default, most secure)
  2. LAN: Binds to 0.0.0.0 (all interfaces)
  3. Tailscale: Auto-configures Tailscale Serve/Funnel
  4. Custom: Specific IP address
Configuration:
Location: src/config/types.gateway.ts:1

WebSocket Server

The Gateway’s WebSocket server provides real-time communication between channels, agents, and clients.

Connection

Connect to the Gateway:

Authentication

The Gateway supports multiple auth modes: Token Authentication:
Password Authentication:
Configuration:
Always use authentication when binding to non-localhost interfaces.
Location: src/gateway/auth.ts:9

Protocol Methods

The Gateway supports these JSON-RPC methods:

agent

Send a message to the agent:

sessions.list

List all active sessions:

sessions.get

Get session details:

channels.status

Get channel status:

gateway.info

Get Gateway information:

Event Streaming

The Gateway pushes events to connected clients: Agent Events:
  • agent.text: Streaming text response
  • agent.thinking: Extended thinking output
  • agent.tool.start: Tool invocation started
  • agent.tool.result: Tool execution result
  • agent.done: Message complete
Channel Events:
  • presence: Channel online/offline status
  • typing: Typing indicators
  • message: Inbound message
Session Events:
  • session.created: New session
  • session.updated: Session metadata changed
  • session.pruned: Session history compacted
Example Event:

HTTP Server

The Gateway also runs an HTTP server for web access and webhooks.

Control UI

Access the Control UI at http://127.0.0.1:18789/:
The Control UI provides:
  • Dashboard: Gateway status and metrics
  • Sessions: View and manage sessions
  • Channels: Channel status and configuration
  • WebChat: Browser-based chat interface
  • Logs: Real-time log streaming
  • Configuration: Edit config via UI
Location: src/provider-web.ts, ui/

REST Endpoints

GET /health

Health check endpoint:
Response:

POST /webhook

Webhook endpoint for external triggers:
Configure webhooks:
Location: src/hooks/

Configuration

Basic Configuration

Remote Access

LAN Access:
Tailscale Serve (tailnet-only):
Tailscale Funnel (public):
Tailscale Serve/Funnel requires the tailscale CLI to be installed and authenticated.

TLS Configuration

Auto-generated certificates are self-signed and suitable for development. For production, use certificates from Let’s Encrypt or your CA. Location: src/infra/tls/

Discovery Configuration

mDNS/Bonjour:
Modes:
  • off: Disable mDNS entirely
  • minimal: Advertise Gateway without sensitive info
  • full: Include CLI path and SSH port in TXT records
Wide-Area Discovery:
Location: src/config/types.gateway.ts:16

Management

Status

Check Gateway status:
Output:

Logs

View Gateway logs:
Log Locations:
  • Daemon logs: ~/.openclaw/logs/gateway.log
  • Console output: stderr when running manually
Location: src/logging/

Restart

Restart the Gateway:
Or manually:

Diagnostics

Run Gateway diagnostics:
This checks:
  • Configuration validity
  • Port availability
  • File permissions
  • Channel credentials
  • Session integrity
  • Migration status
Location: src/commands/doctor.ts

Performance

Connection Limits

  • Channels: 10-20 concurrent
  • Platform apps: 5-10
  • CLI clients: Unlimited
  • WebSocket connections: Hundreds

Memory Usage

Typical memory footprint:
  • Base: 100-200 MB
  • +10-50 MB per channel
  • +1-5 MB per active session

CPU Usage

  • Idle: less than 1%
  • Active messaging: 5-15%
  • Peak (tool execution): 30-60%

Security

Default Security

  • Binds to localhost by default
  • No authentication required for localhost
  • DM pairing for unknown senders
  • Allowlists for channel access

Production Security

1

Enable authentication

2

Enable TLS

3

Configure firewall

Only allow connections from trusted IPs:
4

Use reverse proxy

Run behind Caddy, nginx, or Pomerium for additional auth:
See the security guide for detailed recommendations.

Troubleshooting

Check for:
  1. Port conflicts: lsof -i :18789 or ss -ltnp | grep 18789
  2. Stale lock file: rm ~/.openclaw/.gateway.lock
  3. Config errors: openclaw config validate
  4. Permission issues: Check ~/.openclaw/ permissions
Verify:
  1. Gateway is running: openclaw gateway status
  2. Correct port: Check gateway.port in config
  3. Firewall: Ensure port is open
  4. Authentication: Use correct token/password
Common causes:
  1. Too many active sessions: Prune old sessions
  2. Large message history: Enable auto-compaction
  3. Memory leak: Restart Gateway and file a bug report
Check:
  1. Network connectivity
  2. Channel credentials validity
  3. Rate limiting (too many messages)
  4. Gateway logs for errors

Next Steps

Agents

Learn about AI agent configuration and runtime

Channels

Configure messaging channel integrations

Sessions

Understand session management and storage

Deployment

Deploy Gateway to production environments