Skip to main content

Overview

Send a message to the chat agent and receive a real-time streamed response. The response uses Server-Sent Events (SSE) to stream text incrementally as the LLM generates it. Authentication: Authorization: Bearer {session_token} Content-Type: text/event-stream

Request

Path Parameters: Headers:
Body:

Request Fields


Response

Status: 200 OK Content-Type: text/event-stream Format: SSE stream with event types

SSE Event Format

Each event consists of:
Events are separated by blank lines (\n\n).

Event Types

stream_start

Fired when agent starts generating response.
Use: Show loading indicator

chunk

Fired for each text delta.
Use: Append to chat bubble

tool_call

Fired when agent calls a function/tool.
Use: Optionally show “Looking that up…” indicator

tool_result

Fired when tool completes.
Use: Hide tool indicator

handoff

Fired during multi-agent handoff.
Use: Show “Transferring to specialist…” message

stream_end

Fired when response complete.
Use:
  • Clear loading state
  • Check end_session flag
  • If true, call /end endpoint

error

Fired on error.
Use: Show error message to user

Parsing SSE Stream

JavaScript Example

React Hook Example


Session Lock

The API automatically acquires a session lock when processing messages:
  • Prevents concurrent message processing
  • Ensures message order
  • Prevents race conditions
If a previous message is still streaming, new requests wait for the lock.

Conversation History

The API maintains conversation history internally:
  • Last 40 items (20 exchanges) sent to LLM
  • Prevents unbounded growth
  • Automatic capping
You can retrieve full history via Get History endpoint.

Token Tracking

Automatic tracking of:
  • Input tokens (user messages)
  • Output tokens (assistant responses)
  • Total usage per session
Returned in stream_end event’s usage field.

Error Responses

400 Bad Request

401 Unauthorized

403 Forbidden

404 Not Found


Best Practices

1. Show Loading State

2. Handle All Event Types

3. Check end_session Flag

4. Handle Disconnections

5. Use keepalive for /end



Next Steps

End Session

Always end sessions explicitly to trigger cleanup.

Get History

Retrieve message history for resuming conversations.