Enabling Streaming
To receive a streaming response, setstream: true in the request body of the chat or retry endpoints:
Request Body
string
The user message to send to the agent. Omit to continue the conversation after submitting a client action result.
boolean
default:true
Stream the response as SSE. Defaults to
true.string
Continue an existing conversation. Omit to create a new one.
string
Associate a user with a new conversation. Max 128 chars,
[a-zA-Z0-9._-] only. Ignored when conversationId is provided.Once set, a conversation’s
userId is immutable — it cannot be changed or removed. See User Conversations for details on managing per-user conversation history.Content-Type: text/event-stream and follows the AI SDK UIMessage Stream protocol. Events arrive as Server-Sent Events — each event is a data: line whose payload is a JSON object with a type field, and the stream terminates with data: [DONE]:
Event Types
- Text Events
- Client Action Events
- Step & Completion Events
Metadata
Thefinish event carries the finish reason and, nested under messageMetadata, the Chatbase-specific metadata:
string
required
Why the model stopped generating:
"stop"— normal completion"error"— an error occurred"tool-calls"— the agent invoked a client action — submit the result and continue
"length", "content-filter", "other", "unknown") are possible but rare.object
required
The protocol also allows standalone
message-metadata events mid-stream, with the same object nested under a messageMetadata key. Handle them if present, but expect the metadata on the finish event.data: [DONE].
Code Examples
Non-Streaming Mode
Whenstream is set to false, the API returns a standard JSON response with the complete message:
- Text Response
- Client Action Response
