Streaming (SSE)

Chat replies stream as Server-Sent Events by default, so users see words as they are produced.

Set "stream": true (the default) on POST /agents/{agentId}/chat. The response is text/event-stream. Each event is one data: line containing JSON with a type; the stream ends with data: [DONE].

Good to know

  • Errors that happen before the first byte (bad key, no credits, rate limit) are normal JSON errors with a non-2xx status, not events.
  • Ignore event types you do not know — new ones may be added.
  • Closing the connection stops the stream. The conversation and the user’s message are already saved.
  • Keyless clients (browser, mobile) stream from POST /api/public/agents/{agentId}/chat/stream with the same event format.