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 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

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 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
Other values ("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.
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: