Instead of waiting for the full response, you can stream tokens incrementally as the model generates them. This gives your users a faster, more interactive experience.
The stream() method
client.stream() is an async generator that yields StreamChunk objects as the model streams its response via Server-Sent Events (SSE):
Basic streaming example
Use a for await...of loop to iterate over chunks and accumulate the response text:
The last chunk in the stream has finishReason set to a non-null value (e.g. "stop" or "length") and usage populated with input, output, and total token counts. All preceding chunks have finishReason: null and usage: null.
Cancelling a stream with AbortSignal
Pass an AbortSignal via options.signal to cancel an in-progress stream. This is useful when the user navigates away or explicitly stops generation:
Streaming in a React component
Here is a pattern for streaming into component state:
Using the Vue SDK composable
If you are building a Vue application, the useGatelit composable from @gatelit/sdk-vue handles streaming, accumulation, and cancellation automatically — no manual for await loop needed.
See the useGatelit composable reference for full details.