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 asgenerate() — 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
- Use
requestAnimationFrameto 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
Related
Simple Generation
Quick generation interface
Generate
Full generation with metrics
System Prompts
Control AI behavior
Configuration
SDK configuration