API Overview
SimpleClaw’s Gateway provides a WebSocket-based API for real-time communication between clients, agents, and channels. The API uses a binary framing protocol with JSON-RPC style request/response patterns.Architecture
The Gateway API is the central control plane for SimpleClaw, managing:- Session Management - Agent sessions, context, and state
- Channel Connections - Messaging platform integrations (WhatsApp, Telegram, Slack, Discord, etc.)
- Agent Routing - Message routing to appropriate agents based on channel, account, and peer
- Tool Execution - Browser control, system commands, cron jobs, and custom tools
- Configuration - Dynamic config updates and schema validation
- Device Pairing - Secure device-to-gateway authentication
Core Concepts
WebSocket Protocol
Binary frame-based protocol for real-time bidirectional communication
Protocol Schema
TypeBox schemas for all request/response/event types
Plugin SDK
Build custom channel and provider plugins
Channel Plugins
Implement messaging platform integrations
Protocol Layers
1. Transport Layer
The Gateway uses WebSocket (ws://) for local connections and WSS (wss://) for remote/Tailscale connections. Default bind:ws://127.0.0.1:18789
2. Framing Layer
All messages use a discriminated union frame format:- Request Frame (
type: "req") - Client sends method call - Response Frame (
type: "res") - Server returns result or error - Event Frame (
type: "event") - Server pushes state changes
3. Method Layer
JSON-RPC style methods organized by domain:| Domain | Methods | Purpose |
|---|---|---|
agent.* | agent.identity, agent.wait | Agent identification and control |
agents.* | agents.list, agents.create, agents.update | Multi-agent management |
chat.* | chat.send, chat.abort, chat.inject | Conversation control |
channels.* | channels.status, channels.logout | Channel lifecycle |
config.* | config.get, config.set, config.patch | Configuration management |
sessions.* | sessions.list, sessions.patch, sessions.reset | Session control |
cron.* | cron.list, cron.add, cron.update | Scheduled tasks |
nodes.* | node.list, node.invoke | Device node execution |
Event Streams
The Gateway pushes real-time events to connected clients:chat- Agent responses, tool execution, thinking updatesagent- Agent state changes (model, thinking level, etc.)tick- Periodic heartbeat (default 30s interval)shutdown- Gateway restart notification
Authentication
Connect Phase
Client sends
ConnectParams with protocol version, client info, and optional device auth.Hello Response
Server responds with
HelloOk containing protocol version, available methods/events, and snapshot.Client Libraries
The Gateway protocol is designed for:- macOS app - Swift/SwiftUI native client
- iOS/Android apps - Mobile nodes with device-specific tools
- CLI - TypeScript client using the same protocol
- Web UI - React/WebSocket dashboard and WebChat
Rate Limits
Error Handling
All errors use theErrorShape schema:
Next Steps
WebSocket Reference
Deep dive into connection flow and frame types
Build a Plugin
Create custom channel or provider plugins