Events API
The OpenClaw Gateway broadcasts real-time events to connected WebSocket clients for agent responses, system health, device pairing, and more.Event Format
All events follow this structure:Event type identifier
Event-specific data
Agent Events
Event: agent
Agent response chunks during execution.
Assistant text stream:
Chat Events
Event: chat
WebChat session updates.
System Events
Event: presence
System presence changes (nodes connecting/disconnecting).
Array of node presence objects
Presence version for change tracking
Event: health
Gateway health status updates.
Overall health:
"healthy", "degraded", "unhealthy"Channel health status
Health version for change tracking
Event: tick
Periodic heartbeat to keep connections alive.
Event: heartbeat
Client heartbeat acknowledgment.
Event: shutdown
Gateway is shutting down.
Device Pairing Events
Event: node.pair.requested
New device pairing request.
Unique node identifier
Device name
Platform:
"ios", "android", "macos", "linux", "windows"Event: node.pair.resolved
Device pairing resolved (approved/rejected).
Whether pairing was approved
Device token (when approved)
Event: device.pair.requested
Device pairing request (alternative format).
Event: device.pair.resolved
Device pairing resolved.
Voice Events
Event: talk.mode
Voice mode changed.
Voice mode:
"push-to-talk", "voice-wake", "always-on"Whether voice is enabled
Event: voicewake.changed
Voice wake triggers updated.
Execution Approval Events
Event: exec.approval.requested
Execution approval requested for sensitive commands.
Unique approval request ID
Command requiring approval
Event: exec.approval.resolved
Execution approval resolved.
Cron Events
Event: cron
Cron job status update.
Cron job identifier
Status:
"running", "completed", "failed"Update Events
Event: update.available
Software update available.
Connection Challenge
Event: connect.challenge
Sent during device pairing to display challenge code.
6-digit challenge code to display to user
Expiration timestamp (milliseconds)
Event Subscriptions
Most events are automatically broadcast to all connected clients. For session-specific events, use subscriptions:Subscribe to Session
Unsubscribe from Session
Example: Event Listener
Event Filtering
Clients receive all events by default. To filter events client-side:Event Ordering
Events are delivered in the order they occur, but:- Agent events for the same
runIdare strictly ordered - System events may be interleaved with agent events
- Network delays may affect perceived ordering
Best Practices
Handle all lifecycle phases
Handle all lifecycle phases
Always handle
start, end, and error phases for agent runs:Accumulate text streams
Accumulate text streams
Buffer assistant text chunks to display complete responses:
Respond to shutdown events
Respond to shutdown events
Gracefully close connections and attempt reconnection:
Track presence versions
Track presence versions
Use version numbers to detect missed updates:
Next Steps
WebSocket Protocol
Learn WebSocket connection details
Agent Protocol
Invoke agents and handle responses
Device Pairing
Pair mobile and desktop devices

