Skip to main content

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

LLMGenerationResult (returned by streaming) differs from GenerationResult (returned by generate()). Streaming results have tokensPerSecond at the top level, while GenerationResult nests it under performanceMetrics.

Examples

React Native Component

StreamingChat.tsx

Custom Streaming Hook

useStreamingGenerate.ts

With Typing Animation Effect

TypingEffect.tsx

Event-Based Streaming

You can also use the EventBus for streaming:

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.

Optimize UI Updates

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

Chat

Simple one-liner interface

Generate

Full generation with metrics

System Prompts

Control AI behavior

Events

Event subscription system