Architecture
WebSocket API
Complete reference for the WebSocket API between Constclaw and the OpenClaw gateway, including all frame types, events, and error codes.
Endpoint
ws://127.0.0.1:18789 Default — configurable in ~/.openclaw/openclaw.json Connection lifecycle
01
Open
Client opens a WebSocket connection to the gateway endpoint.
02
Challenge
Gateway sends a connect.challenge event with a nonce.
03
Connect
Client replies with a connect request including auth, scopes, and nonce.
04
Hello
Gateway responds with hello-ok (res with ok: true). Handshake complete.
05
Ready
Client can now send "send" requests to the agent.
06
Close
Either side may close the connection at any time.
Frame types
All frames are JSON objects with a type field:
Type
Direction
Fields
Description
reqClient → Server
id, method, paramsRequest frame
resServer → Client
id, ok, payloadResponse to a request
eventServer → Client
event, payload, seqServer-pushed event
Request: connect
Sent after receiving connect.challenge. Authenticates the client.
Request: send
Sends a message (prompt) to the AI agent. Requires a completed handshake.
Events
Event
Payload
Description
connect.challenge{ nonce }Sent immediately on connection. Contains the nonce for auth.
agent{ text, … }AI response payload. May arrive in multiple chunks for streaming.
agent.thinking{ status }Indicates the model is processing. Use for loading indicators.
agent.done{ }Signals that the agent has finished its response.
error{ code, message }Gateway or provider error.
Error codes
Code
Name
Description
1001AUTH_FAILEDInvalid or missing gateway token.
1002PROTOCOL_MISMATCHClient/server protocol version incompatible.
1003RATE_LIMITEDToo many requests in a short period.
2001PROVIDER_ERRORAI provider returned an error (quota, model unavailable).
2002PROVIDER_TIMEOUTAI provider did not respond within the timeout.
3001INVALID_REQUESTMalformed request frame (missing fields, bad JSON).
Full example
Complete request/response flow from connection to response: