Skip to main content
Set stream: true on any POST /api/v1/completions request to receive a Server-Sent Events (SSE) stream instead of a single JSON response.

Request

Requires authentication via Bearer token. See Authentication.

Wire Format

Every event is two lines followed by a blank line:
Callers MUST buffer partial chunks and split on \n\n — token events can be tens of bytes each and the transport does not guarantee alignment with event boundaries.

Event Types (in order of arrival)

The server emits events in a fixed order: thinkingmeta → (skills? / genui_meta?) → tool* → artifact* → token* → done. If anything fails mid-stream an error event is emitted and the stream closes.

Payload Schemas

meta

token

tool

artifact

The payload depends on artifact.type. Common fields: id, type, title, providerId, modelId. Image artifacts include imageUrl; video artifacts include videoUrl; document artifacts include downloadUrl and sizeBytes; code artifacts include code and language.

genui_meta

skills

done

error

The error event payload matches the REST error envelope (see Overview):

Example Stream

Extracting conversation_id

conversation_id appears on both meta and done. For stateless callers (no conversation_id in the request) it is null. For callers that passed a conversation_id in the request, it is echoed back unchanged. The SDK exposes this as stream.conversationId after the stream completes.

Mid-Stream Errors

When orchestration fails after meta has already been emitted (e.g. the upstream LLM provider times out or a per-mode rate limit kicks in), the server emits an error event with the REST envelope and closes the stream:
Use the same code path as your REST error handler:

SDK Usage

The SDK returns a TheoStream — an async iterable with cancel() for mid-generation abort plus final-metadata properties.
See Streaming for the conceptual guide.