Skip to main content
stream() returns an async generator that yields chunks as the model generates them. Each chunk carries an incremental text delta — ideal for chat UIs and live-completion experiences.

Basic streaming

Each chunk has three fields:

Collecting the full response

Accumulate deltas across the stream to build the complete text:

Cancelling mid-stream

Pass an AbortSignal to stop generation early:

Updating a UI

The streaming API is designed for reactive UIs. Here’s a React hook sketch:
Or use useGatelit() from @gatelit/sdk-vue for Vue — it handles all of this for you.

Streaming a saved prompt

Streaming works with prompts too. Pass the prompt’s slug as promptId for log correlation:
This tags the log entry with the prompt ID — the prompt’s content is not used. To run a prompt’s actual template with variable interpolation, use /v1/prompts/:slug/run via curl or the SDK’s chat() with the promptId field pointing at the slug.