Call Model Streaming
Use async iteration to render low-latency output in UI and CLIs.
Streaming Iterator
TypeScript
const stream = await client.callModel.stream({ model, input });
for await (const event of stream) {
if (event.type === "text.delta") process.stdout.write(event.delta);
if (event.type === "tool_call") console.log("tool:", event.name);
}Stream Event Types
| Name | Type | Required | Description |
|---|---|---|---|
text.delta | event | Required | Incremental token text payload. |
tool_call | event | Tool call emitted during stream. | |
usage | event | Usage summary near stream end. | |
completed | event | Required | Terminal event with stop reason. |
UI Buffering
buffer.ts
let text = "";
for await (const event of stream) {
if (event.type === "text.delta") text += event.delta;
}Backpressure
If your consumer is slow, queue events and flush on animation frames to keep the interface responsive.