Early Beta — The Web SDK is in early beta. APIs may change between releases.
Overview
The VLM (Vision Language Model) module enables multimodal inference — you can feed an image and a text prompt to get descriptions, answers, or analysis. It uses llama.cpp’s mtmd (multimodal) backend compiled to WebAssembly and runs inference in a dedicated Web Worker to keep the UI responsive.Package Imports
VLM classes come from@runanywhere/web-llamacpp, while model management is in @runanywhere/web:
Worker Setup
VLM inference runs in a dedicated Web Worker for responsiveness. You need to set up the worker bridge during SDK initialization:runanywhere.ts
workers/vlm-worker.ts
Basic Usage
Worker-Based VLM (Recommended)
UseVLMWorkerBridge for the best user experience — inference runs in a Web Worker so the UI stays responsive:
API Reference
VLMWorkerBridge (Off-Thread, Recommended)
Types
Camera Integration
VideoCapture
TheVideoCapture class is in @runanywhere/web-llamacpp:
Waiting for Camera Readiness
The camera stream takes a moment to initialize afterstart() resolves. Always guard against zero-dimension frames:
Examples
Live Camera Streaming
React Component
VisionChat.tsx
Supported Models
Registering VLM Models
VLM models require two files: the main model GGUF and a multimodal projector (mmproj) GGUF. Register them using the files array — the first file is the main model, the second is the projector:
WASM Memory Crash Handling
VLM image encoding is computationally expensive in WASM and can occasionally triggermemory access out of bounds errors. Always wrap VLM calls in try/catch and handle these gracefully:
Performance Tips
- Use 256x256 capture dimensions — larger images dramatically increase encoding time
- Use VLMWorkerBridge instead of direct VLM — it runs in a Web Worker and won’t freeze the UI
- Limit maxTokens for descriptions (30-60 tokens for quick descriptions, 80+ for detailed analysis)
- Liquid LFM2-VL 450M is the best starting point — smallest multimodal model, fast and memory-efficient (~500MB)
- Handle WASM crashes —
memory access out of boundsis recoverable; display a retry message
Related
LLM Generation
Text-only generation
Tool Calling
Function calling with LLMs
Best Practices
Performance optimization