Skip to main content
Early Beta — The Web SDK is in early beta. APIs may change between releases.

Overview

Token streaming allows you to display AI responses as they’re generated, token by token. This provides a much better user experience than waiting for the entire response, especially for longer outputs.

Basic Usage

API Reference

Parameters

Same as generate() — see Generation Options.

Returns

Examples

React Component

StreamingChat.tsx

Cancellable Streaming

Custom Streaming Hook (React)

useStreamingGenerate.ts

Optimize UI Updates

For very fast generation, batch UI updates to avoid overwhelming the browser:

Performance Tips

Streaming has minimal overhead compared to non-streaming generation. The time-to-first-token (TTFT) is the same, and total generation time is nearly identical.
  • Use requestAnimationFrame to batch DOM updates for smoother rendering
  • Avoid setting React state on every token for very fast models — batch updates with a throttle
  • Cancel streams when users navigate away to free WASM resources

Simple Generation

Quick generation interface

Generate

Full generation with metrics

System Prompts

Control AI behavior

Configuration

SDK configuration