WebSocket Protocol
The OpenClaw Gateway WebSocket API provides real-time bidirectional communication for agent interactions, event streaming, and control plane operations.Connection
Endpoint
Connection Flow
- Open WebSocket connection
- Send
connectmethod with authentication - Receive
connect.challengeevent (optional, for device pairing) - Receive connection response
- Subscribe to events (optional)
- Invoke RPC methods
Example Connection
Message Format
All messages follow JSON-RPC 2.0 format.Request Frame
Must be
"2.0"Unique request identifier for matching responses
RPC method name (e.g.,
"agent", "send", "sessions.list")Method-specific parameters
Response Frame
Matches request
idtrue for success, false for errorsMethod-specific response data (when
ok: true)Error details (when
ok: false)Error Response
Authentication
Authenticate during the initialconnect call:
Client role:
control, node, or webchatAuthentication credentials
Bearer token or device token
Password (alternative to token)
Client metadata
Event Streaming
The Gateway broadcasts events to subscribed clients.Event Frame
Event name
Event-specific data
Available Events
| Event | Description |
|---|---|
agent | Agent response chunks (streaming) |
chat | Chat session updates |
presence | System presence changes |
health | Health status updates |
tick | Gateway heartbeat (periodic) |
heartbeat | Client heartbeat (periodic) |
talk.mode | Voice mode changes |
shutdown | Gateway shutdown notification |
cron | Cron job status |
node.pair.requested | Device pairing request |
node.pair.resolved | Device pairing resolved |
device.pair.requested | Device pairing request |
device.pair.resolved | Device pairing resolved |
voicewake.changed | Voice wake triggers changed |
exec.approval.requested | Execution approval requested |
exec.approval.resolved | Execution approval resolved |
update.available | Software update available |
Subscribing to Events
Events are automatically sent to all connected clients. No explicit subscription is required for most events. For session-specific events, use session subscriptions:Common Methods
Invoke Agent
Send Message
List Sessions
Heartbeat
The Gateway sends periodictick events to keep connections alive:
Connection Management
Reconnection
If the WebSocket connection drops:- Wait a short delay (exponential backoff recommended)
- Re-establish WebSocket connection
- Re-send
connectmethod - Resume operations
Graceful Shutdown
The Gateway sends ashutdown event before closing:
Error Handling
Common Error Codes
| Code | Description |
|---|---|
INVALID_REQUEST | Request validation failed |
UNAUTHORIZED | Authentication failed |
METHOD_NOT_FOUND | Unknown RPC method |
INTERNAL_ERROR | Server error |
RATE_LIMITED | Rate limit exceeded |
Example Error Response
Example: Complete Flow
Next Steps
Agent Protocol
Invoke agents via WebSocket
Events
Subscribe to Gateway events
Sessions
Manage agent sessions
Messages
Send messages via channels

