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

Complete example

Four steps get you from an empty page to streamed on-device tokens: initialize the SDK, register a backend, register and download a model, generate.
runanywhere.ts
App.tsx

Step by step

1. Install

Add @runanywhere/web-onnx for speech (STT, TTS, VAD). See Installation for bundler configuration and the cross-origin isolation headers.

2. Initialize

initialize() is fail-closed: if the commons WASM cannot load, it throws and isInitialized stays false. It also starts the service phase in the background, so completeServicesInitialization() awaits work already in flight rather than starting it. Registering a backend after initialize() is the documented order on Web, because backend packages install onto core adapters. SDKInitOptions accepts environment, apiKey, baseURL, buildToken, appIdentifier, appName, appVersion, and appBuild. There is no debug flag; log level follows the environment, and RunAnywhere.setLogLevel() overrides it. Wrap the whole sequence in a cached promise so it is safe to call from several components.

Environments

There is no staging member. Wire value 2 was removed.

3. Register a model

Three registration entry points, picked by artifact shape: Each returns the assembled ModelInfo. The app supplies flat arguments; the SDK builds the proto, the MultiFileArtifact, and the ExpectedModelFiles manifest.

4. Download and load

downloadModel also accepts a bare model id string. downloadModelStream yields DownloadProgress values instead of taking a callback. Downloads land in OPFS and survive reloads. downloadModel requires persistent browser storage; if RunAnywhere.storage.backend is 'memory', it throws ERROR_CODE_STORAGE_ERROR because independent backend WASM instances cannot share a private MEMFS.

5. Generate

The prompt lives inside the options object. See generate() for every option and its default.

Tracking download progress

Two options. The onProgress callback above, or the SDK event bus.
RunAnywhere.events is the shared EventBus. Payload fields sit directly on the event object.

Checking acceleration

Prefer RunAnywhere.runtime.active: when a backend worker owns the GPU, the main-thread bridge mode can still read cpu.

What’s next

LLM generate

Full generation with options and metrics

Streaming

Real-time token streaming

Speech-to-text

Transcribe audio in the browser

Text-to-speech

Convert text to spoken audio