Skip to main content

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
Both channels use Redis Streams as the underlying message transport, which enables horizontal scaling across multiple server instances.

WebSocket Notifications

Connecting

Connect to the WebSocket endpoint at:
Authentication is handled automatically via your session cookie (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:
You can also subscribe to user-specific notifications:
To unsubscribe:

Channel Security

Two security rules are enforced on all subscriptions:
  1. The tenant_id in the channel must match your authenticated tenant
  2. For user channels, the user_id must 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

Authentication uses standard REST authentication (session cookie).

Query Parameters

Streaming Events

When the AI assistant generates a response, you receive a sequence of SSE events: The typical event lifecycle is:
Tool call 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:
Knowledge Stack will replay any events you missed and then continue with live events. You will receive a replay_complete event when replay is finished:
If the message has already finished streaming when you reconnect, you will receive a message_not_streaming event instead. In that case, fetch the complete message via the REST API:

Best Practices for SSE

  1. Open a new SSE connection when you navigate to a thread
  2. For reconnection mid-stream, always include both last_message_id and last_entry_id
  3. Do not rely on EventSource auto-reconnect — close the connection and open a new one with updated parameters
  4. 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.

Configuration

If you are self-hosting Knowledge Stack, these settings control the real-time notification system:

Error Handling