Enabling Streaming
To receive a streaming response, setstream: true in the request body of the chat or retry endpoints:
Request Body
The user message to send to the agent. Omit to continue the conversation after submitting a client action result.
Stream the response as SSE. Defaults to
true.Continue an existing conversation. Omit to create a new one.
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 are newline-delimited JSON, where each line is a JSON object with a type field.
Event Types
- Text Events
- Client Action Events
- Step & Completion Events
Metadata
Thefinish event is accompanied by a message-metadata event containing Chatbase-specific metadata:
Unique ID of the assistant message.
The ID of the user message that triggered this response. For continuation responses, this is the last user message in the conversation.
The conversation ID. Use this for follow-up messages.
The user ID associated with this conversation, or
null if none.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
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