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

Overview

This guide covers SDK initialization options, backend registration, model management, events, browser capabilities, and audio utilities.

SDK Initialization

Basic Initialization

Full Configuration

Backend Registration

After initializing the core SDK, register the inference backends you need:
Backend registration loads WASM binaries and can take a few seconds. Always await the register calls before using any inference APIs. Registration is idempotent — calling it multiple times is safe.

Environment Modes

Logging

Configure Log Level

Log Levels

Events

EventBus

The SDK provides a typed event system for monitoring SDK activities:
Event properties are directly on the event object (e.g., evt.modelId, evt.progress), not nested under evt.data.

Event Types

Model Sources

All models in RunAnywhere are sourced from HuggingFace. The SDK provides a model registry that resolves compact model definitions into full download URLs and manages the complete lifecycle: registration -> download -> storage -> loading.

How It Works

When you register a model with a repo field, the SDK constructs the download URL automatically:
For example, repo: 'LiquidAI/LFM2-350M-GGUF' with files: ['LFM2-350M-Q4_K_M.gguf'] resolves to:

CompactModelDef

The registerModels API accepts an array of compact model definitions:

URL Resolution Rules

Model Management

All model management operations use ModelManager from @runanywhere/web.

Register Models

Available Models on HuggingFace

LLM Models

VLM Models

STT / TTS / VAD Models

Download and Load

Multi-Model Loading with coexist

By default, loading a new model unloads any previously loaded model. For the voice pipeline (which needs STT + LLM + TTS + VAD simultaneously), pass coexist: true:

Storage (OPFS)

Downloaded models are persisted in the browser’s Origin Private File System (OPFS). This means:
  • Models survive page refreshes and browser restarts
  • Each origin (domain) has its own isolated storage
  • The SDK auto-detects previously downloaded models on page load
  • If storage quota is exceeded, the SDK auto-evicts least-recently-used models
Large model downloads (>200MB) can crash the browser tab on memory-constrained devices. The OPFS write buffers data in memory before committing. If the tab crashes mid-download, refresh and retry — the SDK can resume partial downloads. Start with smaller models (LFM2 350M at ~250MB) before attempting larger ones (Qwen2-VL 2B at ~1.5GB).

Delete Models

Audio Utilities

Audio utilities (AudioCapture, AudioPlayback) are in @runanywhere/web-onnx, while video utilities (VideoCapture) are in @runanywhere/web-llamacpp. Don’t mix up the import sources.

AudioCapture (Microphone)

AudioCapture is in @runanywhere/web-onnx. Configuration is passed to the constructor, and callbacks are passed to start():

AudioPlayback (Speaker)

AudioPlayback is in @runanywhere/web-onnx:

VideoCapture (Camera)

VideoCapture is in @runanywhere/web-llamacpp:

Acceleration

GPU Acceleration

The SDK auto-detects WebGPU availability when LlamaCPP.register() is called:
If the WebGPU WASM file returns a 404, the SDK gracefully falls back to CPU mode. This is normal behavior — check LlamaCPP.accelerationMode to confirm which mode is active.

Error Handling

Handle errors gracefully

Best Practices

Optimization tips