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

Complete Example

Here’s a complete example to get you started with on-device text generation in the browser using React + Vite:
runanywhere.ts
App.tsx

Step-by-Step Guide

1. Install Packages

Add @runanywhere/web-onnx too if you need STT, TTS, or VAD. See Installation for the full list.

2. Initialize the SDK

Initialize RunAnywhere once when your app starts. This is a three-step process:
Wrap initialization in an idempotent function (using a cached promise) so it’s safe to call from multiple components. See the complete example above.

Environment Options

3. Register and Load a Model

Models are registered in a catalog, downloaded to OPFS, and then loaded into memory:

4. Generate Text

Generation Result

The result promise resolves with:

Model Management with OPFS

Models are downloaded from HuggingFace and stored in the browser’s OPFS:
When you provide a repo field like 'LiquidAI/LFM2-350M-GGUF', the SDK automatically constructs the download URL: https://huggingface.co/LiquidAI/LFM2-350M-GGUF/resolve/main/LFM2-350M-Q4_K_M.gguf. See Model Sources for all available models.

Using in a React App

Chat.tsx

Checking Acceleration Mode

After registering the LlamaCpp backend, you can check whether WebGPU is active:

What’s Next?

LLM Generate

Full generation with options and metrics

Streaming

Real-time token streaming

Speech-to-Text

Transcribe audio to text in the browser

Text-to-Speech

Convert text to spoken audio