Early Beta — The Web SDK is in early beta. APIs may change between releases.
Overview
RunAnywhere.generateStream() yields answer tokens as the model produces them. It takes the same
options object as generate() and resolves to a handle carrying two iterables,
a result promise, and a cancel function.
Basic usage
Signature
generate(). See
Generation options.
Typed events
stream gives you answer text only. When you need reasoning tokens, tool calls, or progress
counters, iterate events instead and switch on eventKind.
LLMStreamEventKind covers UNSPECIFIED, STARTED, TOKEN, THINKING, TOOL_CALL, PROGRESS,
COMPLETED, and ERROR. Every event also carries seq, timestampUs, isFinal,
promptTokensProcessed, completionTokensGenerated, and elapsedMs.
LLMStreamEventKind lives in @runanywhere/proto-ts, a published dependency of
@runanywhere/web, because the root facade re-exports only the enums it uses in its own
signatures.
Cancellable streaming
AbortSignal works too, and is wired to cancel() internally:
React hook
useStreamingGenerate.ts
Batching UI updates
For fast models, coalesce tokens into one paint per frame.Performance notes
Streaming adds negligible overhead. Time to first token is the same as non-streaming, and total generation time is close to identical. Cancel streams when the user navigates away so the WASM heap is released promptly.Related
Simple generation
Prompt in, string out
Generate
Full generation with metrics
System prompts
Control model behavior
Configuration
SDK configuration