Skip to main content
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

Parameters and defaults are identical to 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

An 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.

Simple generation

Prompt in, string out

Generate

Full generation with metrics

System prompts

Control model behavior

Configuration

SDK configuration