Skip to main content

Enabling Streaming

To receive a streaming response, set stream: 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.
The response uses 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

message-start

Emitted once at the beginning of a new message. Contains the message ID.

text-start

Emitted at the beginning of a text block.

text-delta

Emitted for each chunk of generated text. Concatenate all deltas to build the full response.

text-end

Emitted when a text block is complete.

Metadata

The finish event is accompanied by a message-metadata event containing Chatbase-specific metadata:
string
required
Unique ID of the assistant message.
string
required
The ID of the user message that triggered this response. For continuation responses, this is the last user message in the conversation.
string
required
The conversation ID. Use this for follow-up messages.
string | null
required
The user ID associated with this conversation, or null if none.
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
object
required
The stream terminates with data: [DONE].

Code Examples

Non-Streaming Mode

When stream is set to false, the API returns a standard JSON response with the complete message: