webslm has 5,375 recorded weekly downloads on npm, ranking #1500 of 3,247 tracked listings.
About webslm
webslm
Run small language and vision-language models (and small embedding, speech recognition and text-to-image models) in the browser and in Node, straight from their original Hugging Face checkpoints. A Rust engine compiled to WebAssembly reads config.json, tokenizer.json, the chat template and the *.safetensors weights as published, with no conversion step.
npm install webslm
import { ask } from "webslm";
console.log(await ask("Write a haiku about the sea"));
The first call downloads the default model (LFM2.5 350M, about 710 MB) into a local cache; later runs load it offline. The same code runs in browsers, Node 20+ and Bun, with no bundler or setup in Node.
- Runs in a dedicated module Worker in browsers (
worker_threadsin Node), so the page stays responsive. - Downloads a checkpoint once into the Origin Private File System (a directory in Node), resumes interrupted downloads, checks the Hub's SHA-256 and loads offline afterwards.
- Streams answers, keeps conversations, and exposes a low-level session API (teacher-forced scoring, step-wise decoding, logits and hidden states as
Float32Arrays). - Searches the Hub for models it can run.
- Answers about images and video, embeds texts, transcribes speech, generates images and trains LoRA adapters on the device.
Supported architectures: Llama-style (SmolLM2, Mistral), Qwen2, Qwen3, Qwen3.5 (Gated DeltaNet hybrid, with its vision encoder), LFM2 / LFM2.5 and LFM3; the vision-language models SmolVLM / SmolVLM2 and LFM2-VL / LFM2.5-VL; the encoders BERT / MiniLM, ModernBERT and model2vec; Whisper; and Stable Diffusion style UNets (SDXS) and Sana-Sprint for image generation. Models run on WebGPU or on the CPU through WebAssembly (SIMD, and Web Worker threads where the page allows): with device: "auto" (the default), WebGPU for models above ~100M parameters when the browser has an adapter, the CPU otherwise; ModelInfo.backend says which one runs. In Node and Bun, the native engine runs instead (downloaded once from the release, checked, and cached): native SIMD kernels on every core, and the GPU through Metal, Vulkan or DX12. ESM only; browsers with WebAssembly SIMD (every current browser). Demo: https://maxgfr.github.io/webslm/.
Ask
import { ask } from "webslm";
const text = await ask("What is the capital of France?"); // DEFAULT_MODEL
const fact = await ask("What is 2 + 2?", { model: "Qwen/Qwen3-0.6B", think: false });
ask and stream load their model on first use and share it between calls (concurrent calls wait for the same load). unloadAll() frees them. A Node script exits on its own when it is done; no cleanup is needed.
Options, all optional:
| Option | Default | |
|---|---|---|
model | DEFAULT_MODEL | Hub repository id or a source (module-level calls only) |
maxTokens | 512 | Largest number of new tokens (reasoning included) |
temperature | the model card's for the curated models, else the checkpoint's generation_config.json, else 0.7 | 0 is greedy, deterministic decoding |
system | System prompt | |
think | the template's default | enable_thinking for models that reason first (Qwen3, LFM3, and Qwen3.5 when asked); ignored by the others |
stop | Strings that end the answer (never emitted, not even in part) | |
seed | Seed of the sampler: same seed, same answer | |
topK, topP, minP | the checkpoint's | Sampling filters |
repetitionPenalty, presencePenalty, frequencyPenalty | Penalties on repeated tokens | |
json | false | Answer with a JSON object (constrained decoding) |
schema | Answer with JSON following this JSON schema (see Generation controls) | |
thinkingBudget | Most reasoning tokens before the model must answer | |
loopDetection | false | Stop when the answer starts repeating itself |
contextShift | false | When the context is full, drop the oldest turns (the system prompt stays) |
speculative | "off" | "auto", a number of tokens to guess per forward pass, or "mtp" / "mtp:N" (Qwen3.5's own draft head, loaded with mtp: true): same answer, faster when it repeats the prompt (see Generation controls) |
templateKwargs | Extra chat template variables | |
signal | AbortSignal; ask then rejects with code "ABORTED" | |
onToken | Called with each piece of the answer | |
onReasoning | Called with each piece of the reasoning | |
withReasoning | false | ask resolves to { text, reasoning } |
Reasoning
Models such as Qwen3 and LFM3 write their reasoning in a <think>…</think> block before the answer. ask, stream and chats return the answer without it; ask for it explicitly:
const { text, reasoning } = await ask("Is 97 prime?", { model: "Qwen/Qwen3-0.6B", withReasoning: true });
The split is generic: a <think> block at the start of the output (or one the chat template opens in the prompt) is reasoning, whatever the model. splitReasoning(output, opened?) applies it to text you already have (opened: the prompt opened the block, as Qwen3.5's and LFM3's do when thinking; inferred when left out). A reasoning model can spend its maxTokens thinking, leaving an empty answer: raise maxTokens or pass think: false.
Stream
import { stream } from "webslm";
const answer = stream("Tell me a story");
for await (const text of answer) process.stdout.write(text);
await answer.text; // the whole answer
answer.stop(), or leaving the loop early, stops the generation; the stream then ends normally and answer.text holds what was generated. answer.reasoning resolves to the reasoning, if any.
Load a model and chat
import { load } from "webslm";…
Description from the npm listing.
- llm
- slm
- wasm
- webassembly
- safetensors
- huggingface
- browser
- worker
- opfs
- language-model
- chat
- inference
- node
- bun
- ai-sdk
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (121)Similar npm AI SDKs plugins
All 20 webslm alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/webslm. First seen Dec 5, 2026; last successful collection Dec 6, 2026. See the methodology.