stream: true on any POST /api/v1/completions request to receive a Server-Sent Events (SSE) stream instead of a single JSON response.
Request
Wire Format
Every event is two lines followed by a blank line:\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:thinking → meta → (skills? / genui_meta?) → tool* → artifact* → token* → done. If anything fails mid-stream an error event is emitted and the stream closes.
| Event | Description |
|---|---|
thinking | Heartbeat — a single byte so proxies flush the response immediately. No JSON payload |
meta | Engine info, resolved mode, artifacts, routing, conversation_id, request_id |
skills | Active skills for this turn (only when one or more skills were applied) |
genui_meta | GenUI component library info (only when resolved_mode === "genui") |
tool | A tool was called (may fire multiple times) |
artifact | A generated file (image, document, code, video) (may fire multiple times) |
token | A text chunk (fires for each token) |
done | Final payload: full content, follow-ups, usage, conversation_id, request_id |
error | An error occurred — payload matches the REST error envelope |
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 aftermeta 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:
SDK Usage
The SDK returns aTheoStream — an async iterable with cancel() for mid-generation abort plus final-metadata properties.
