Chat

Streaming

Set stream: true to receive the chatbot reply as Server-Sent Events. Tokens are sent as they're generated, giving your users a real-time typing experience.

Event format

Each event is a single SSE line: data: {...JSON...} followed by a blank line. Parse the JSON after the data: prefix and switch on type.

Stream output
data: {"type":"token","content":"Our"}

data: {"type":"token","content":" business"}

data: {"type":"token","content":" hours"}

data: {"type":"token","content":" are"}

data: {"type":"token","content":" Monday-Friday, 9am-5pm."}

data: {"type":"sources","sources":[{"url":"https://example.com/about","title":"About Us"}]}

data: {"type":"done"}

Event types

  • token{ content: string }. A chunk of the response text. Concatenate every token content for the full message.
  • sources{ sources: array }. Source documents used for the response. Sent once, after all tokens.
  • done{}. Stream complete. Close the connection.

Examples

cURL
curl -X POST https://services.chatmount.co/v1/chat \
  -H "Authorization: Bearer cm_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  --no-buffer \
  -d '{
    "message": "What are your business hours?",
    "stream": true
  }'

Related