Overview
Knowledge Stack provides two real-time communication channels:- WebSocket — For receiving instant notifications about events in your tenant (e.g., document ingestion completed)
- Server-Sent Events (SSE) — For streaming AI assistant responses token-by-token
WebSocket Notifications
Connecting
Connect to the WebSocket endpoint at:ks_uat). On a successful connection, you will receive a confirmation message:
Subscribing to Channels
After connecting, subscribe to notification channels by sending JSON messages:Channel Security
Two security rules are enforced on all subscriptions:- The
tenant_idin the channel must match your authenticated tenant - For user channels, the
user_idmust match your authenticated user
Notification Events
Server Messages
Connection Close Codes
Keepalive
The connection uses standard WebSocket ping/pong frames (RFC 6455) for keepalive. No application-level heartbeat is needed.SSE Thread Streaming
Endpoint
Query Parameters
Streaming Events
When the AI assistant generates a response, you receive a sequence of SSE events:
The typical event lifecycle is:
step events may be interleaved during processing.
SSE Event Format
Each event follows this format:Reconnection
If your connection drops while an assistant response is still streaming, you can reconnect with replay:replay_complete event when replay is finished:
message_not_streaming event instead. In that case, fetch the complete message via the REST API:
Best Practices for SSE
- Open a new SSE connection when you navigate to a thread
- For reconnection mid-stream, always include both
last_message_idandlast_entry_id - Do not rely on
EventSourceauto-reconnect — close the connection and open a new one with updated parameters - The stream self-terminates when done. Open a new connection for the next message.
SSE Keepalive
The server sends SSE comment pings (: ping) every 30 seconds to keep the connection alive.
