install
npm install @caldrix-ai/caldrix

Try it in this tab before you install.

caldrix.js

caldrix.js runs a language model in the browser, in a worker, on WebGPU or WebAssembly. It is one npm package, @caldrix-ai/caldrix: the engine's compiled browser host (WebAssembly), the worker that drives it, and the typed API around them. The caldrix binary the rest of these docs describe is not involved.

To run an agent with tools on the engine, see aerix.js.

This page states only what the browser-gate record (kept in the private Caldrix repository) holds, what the package's own tests run in CI, and what the source does.

Install and quick start

npm install @caldrix-ai/caldrix
import { Caldrix } from "@caldrix-ai/caldrix";

const engine = await Caldrix.load("smollm2-instruct", {
  onProgress: ({ file, loaded, total }) => console.log(file, loaded, total),
});

for await (const delta of engine.chat([{ role: "user", content: "Say hello." }], { maxTokens: 32 })) {
  if (!delta.done) document.body.append(delta.text);
}

console.log(engine.doctor());
engine.dispose();

Caldrix.load fetches the model's files from the Hugging Face Hub, starts the engine's worker and resolves once the model is loaded. Inference runs only in that worker; the page's main thread never runs the model.

The API

The package exports Caldrix, Engine, probe and CaldrixError, the speech API (SpeechEngine, toWav and createSpeechPlayer; see Speech), and the types the signatures below name. As the package's declarations have them:

class Caldrix {
  static load(model: string, opts?: LoadOptions): Promise<Engine>;
  static check(model: string, opts?: CheckOptions): Promise<CheckResult>;
  static fit(facts: QuantFacts, opts?: FitOptions): Promise<FitResult>;
  static loadSpeech(model: string, opts?: SpeechLoadOptions): Promise<SpeechEngine>;
  static checkSpeech(model: string, opts?: SpeechCheckOptions): Promise<SpeechCheckResult>;
}
class Engine {
  chat(messages: ChatMessage[], opts?: GenerateOptions): AsyncIterable<Delta>;
  complete(input: string | { ids: number[] }, opts?: GenerateOptions): AsyncIterable<Delta>;
  doctor(): DoctorReport;
  dispose(): void;
}
function probe(): Promise<Capabilities>;

model is an alias this build ships (doctor().aliases) or a Hugging Face repo id, owner/name or owner/name@<revision>. A repo id is resolved once through the Hub's model API to its canonical id and commit sha, and every file is fetched and cached at that sha; doctor().model and doctor().revision are the canonical id and the sha, and the doctor line says (resolved from <id>) when the canonical id differs from the one asked (a rename, or a different letter case). The browser build sends no token: a gated repo is refused by name, a private one reads as not found (the Hub answers it as it answers a missing repo), and the caldrix CLI, which reads HF_TOKEN, loads both. A repo id loads a dense Llama-family checkpoint, a bitsandbytes nf4 checkpoint (dequantized to the plan dtype at import: it runs at its dense size, not its download size; doctor().note says both), a gptq, awq or compressed-tensors int checkpoint (dequantized at import the same way, as no browser tier has kernels for its blocks; the host's tests cover a tiny GPTQ checkpoint, and no browser run of these formats is recorded; an FP8 checkpoint is refused by name pending its verification), an mlx checkpoint (the safetensors headers of its weights, never adapters.safetensors, read by range before any weight byte; the load is routed and sized by them and expanded to the plan dtype at import, and doctor().provenance says (mlx, dequantized to <dtype> at import); one listing neither model.safetensors nor its index (its weights are never found by a glob), one with experts whose expansion would be f32, one with an nvfp4 global scale (declared by its config or stored beside a module), and dtype: "bf16" with one whose values bf16 does not hold are refused by name before any weight byte; the host's tests cover a tiny 4-bit checkpoint, whose expanded values equal the reference decode, and the browser tests load it on the wasm tier; no browser run of a Hub mlx repo is recorded), a Jlama Q4 checkpoint (its config names no quantization: the safetensors headers of its weights, read by range before any weight byte, say so; it is sized and expanded to the plan dtype at import, on the WebGPU tier from whole files, and doctor().provenance says (jlama, dequantized to <dtype> at import); a Q4 tensor the format does not define is refused by name before any weight byte; the browser tests load a tiny one on both tiers; no browser run of a Hub Jlama repo is recorded), a PEFT LoRA adapter repo (its base, named by adapter_config.json, resolved once through the Hub's model API, and the adapter folded into it tensor by tensor at import), or a LoRA adapter over an nf4 base. doctor().provenance is the caldrix CLI's model: line, naming both repos and shas; progress events name the repo each file comes from. Folded weights are never cached: a repeat load fetches nothing new and folds again. A gated base, an adapter over an adapter, a pickle-only adapter and a repo carrying both a model and an adapter are refused by name before any weight byte.

A repo id of a model converted to multi-head latent attention (an mha2mla block in its config.json) loads on both tiers in two forms: a Qwen3 under the uniform selection from start point 0, and a Qwen2-family model under the 2-norm selection when its weights are one of the two conversions this build carries a frequency selection for (recognised by a fingerprint of the weights, never by name; one of the two selections is inferred, not confirmed by the conversion's authors). The block alone admits it at the precheck; any other block is refused there by name before a weight is fetched, a Qwen2 or Qwen3 without the block is refused as an unsupported architecture, and weights of a carried shape whose fingerprint is not a carried conversion's are refused as not loadable once the weight file is in, before anything runs. Such a model is read whole on the wasm tier and streamed into the device's buffers on the WebGPU tier, each row the converted attention assembles built as its source arrives and the fingerprint taken from the stream, checked at its end. In headless Chromium a tiny random-weight uniform model gave its reference's tokens on the wasm tier and on the WebGPU tier on a software adapter, a CPU, and the three published conversions gave the CPU lane's tokens on the wasm tier and, at f32 storage, on the WebGPU tier on that software adapter, the two 2-norm ones admitted by their fingerprint; no GPU has run one.

A generation stops on the model's end-of-sequence ids: the tokenizer's, config.json's eos_token_id, and, for a Hub repo whose listing has a generation_config.json, that file's eos_token_id too (a number or a list), on both tiers. The file is fetched once, with the tokenizer files; one that is not a JSON object adds nothing, and a repo without it loads as before. An alias and a GGUF file read none: a GGUF file's stop ids are its metadata's.

  • chat formats the messages with the model's chat template; complete continues a plain-text prompt, or a prompt given as token ids. Both yield deltas until one has done: true. When a model's chat template refuses a system message, chat puts the system text at the top of the first user message instead, and the last delta has systemFolded: true.
  • doctor() reports the load: the tier that runs (backend), device, dtype, storage, adapter, maxContext and contextClamp, where each model file came from and whether its digest was checked (source), where the package's own files came from (assets: bundle, cdn or page, with the URL), aliases (every alias this build loads, each with its name and its format, safetensors or gguf), provenance (a densified load's model: line, null for a model read as it lies), note (an nf4 repo's 4-bit note, null otherwise), images (whether the tier takes image parts; see Images), and why the tier was chosen.
  • dispose() releases the worker and everything in it. Every later call throws request.
  • probe() reports what this page can run, without loading anything: the WebAssembly features, the WebGPU adapter if there is one, which tiers are available, the tier "auto" would choose (chosen) and why.
type ChatMessage = { role: "system" | "user" | "assistant"; content: string | ContentPart[] };

interface Delta {
  text: string;
  token?: number;
  done: boolean;
  finishReason?: "stop" | "length" | "abort";
  usage?: { promptTokens: number; completionTokens: number; cachedTokens: number };
  logprobs?: { token: number; logprob: number }[];
  systemFolded?: true;
}

interface GenerationOptions {
  constraint?: { json: Record<string, unknown> } | { oneOf: string[] };
  logprobs?: number;
  temperature?: number;
  topK?: number;
  topP?: number;
  minP?: number;
  repetitionPenalty?: number;
  seed?: number;
  maxTokens?: number;
}

type GenerateOptions = GenerationOptions & {
  signal?: AbortSignal;
  onImageProgress?: (p: { tilesDone: number; tilesTotal: number }) => void;
};

Generation is greedy unless a sampling option is set. Aborting the signal ends the generation with finishReason: "abort". constraint limits what the model may write, on both tiers: json takes a JSON Schema subset and oneOf a list of strings, and a schema outside the subset is refused with kind: "request"; the package README's "Constrained decoding" section states the subset and what has run under it.

A generation starts from the context the previous one on the same engine left, when the new prompt begins with the same tokens; usage.cachedTokens on the last delta says how many prompt tokens that reused. logprobs: n (at most 20, otherwise refused with kind: "request") adds up to n candidates (fewer under a constraint) as { token, logprob } to each token's delta as its logprobs.

Errors

The package's errors are CaldrixErrors, whose kind says which stage refused:

type Kind = "probe" | "fit" | "architecture" | "fetch" | "digest" | "validate" | "lowering" | "backend" | "request";

Images

A quantized Qwen3.5 GGUF file loads by its Hub repo id and file name on the WebAssembly tier only (Caldrix.load("unsloth/Qwen3.5-0.8B-GGUF", { file: "Qwen3.5-0.8B-Q6_K.gguf" }); there is no alias for it). The WebGPU tier has none of this model's kernels: backend: "auto" uses the WebAssembly tier and backend: "webgpu" is refused by name, as is a safetensors Qwen3.5 checkpoint on both tiers. Checked once, in headless Chromium on a CPU, on that one Q6_K file: its reference's eight tokens, at a 64-row context and at the default context, which is lowered to fit the browser's memory (the browser-gate record, entry 68). No device, no other file and no speed has been measured.

A NemotronH GGUF file (general.architecture nemotron_h or nemotron_h_moe) loads on the wasm tier by its repo id and file, at the f32 plan: its matmuls in their stored kind where the tier reads it, its expert stacks decoded to f32 as they fill. The precheck judges it from the header range before any weight byte, refusing by name a kind the tier does not read and a file past its memory. NemotronH GGUF files load on the WebGPU tier when every tensor is F32 or in a kind a real adapter has run (Q8_0, Q4_K, Q5_0, Q5_K, Q6_K; expert stacks Q8_0); any other is refused by name, and backend: "auto" then loads it on the wasm tier where that tier reads it. An all-F32 file is refused by both tiers. A safetensors or MLX NemotronH checkpoint is refused on each tier by name with the f32 bytes it would expand to, naming the GGUF route. Checked once, in headless Chromium on a CPU, on two files: the Lightning model with experts converted to Q8_0 at the desk, and Nano-4B's published Q4_K_M file, each giving its reference's 16 tokens at a 64-row context and at the default context, and a later request over the prompt extended by two ids equal to a fresh load's (the browser-gate record, entry 106; the reuse of the prompt's rows, read from usage.cachedTokens, was observed on the Lightning file and a tiny one, not on Nano-4B's). On the WebGPU tier the same two files gave their reference's 16 tokens at both contexts, a later request equal to a fresh load's, on one real adapter: an Apple M1 Max's GPU in headless Chromium. No other device, no other file and no speed has been measured.

smolvlm-256m (SmolVLM-256M-Instruct, a vision-language model) runs in the browser on both tiers: chat takes images as well as text, and backend: "auto" no longer falls back to the wasm tier for it. On the wasm tier it has run in Playwright's headless Chromium on Linux (the browser-gate record, entries 59 and 60); on the WebGPU tier on the operator's Apple M1 Max in Playwright's Chromium, on the Mac's own adapter, vendor apple, architecture metal-3 (entry 63). Both runs were on a test build of the browser host that admitted the model on that tier ahead of the version that ships it; see What has run, and where.

A message's content is a string or an array of parts:

type ContentPart =
  | { type: "text"; text: string }
  | { type: "image_url"; image_url: { url: string | Uint8Array; detail?: "low" | "high" | "auto" } };

An image is a PNG or a JPEG: a data: URL string (data:image/png;base64,, data:image/jpeg;base64, or data:image/jpg;base64,) or the image file's own bytes as a Uint8Array; the engine never fetches a URL. A WebP is refused by name in this build, as a URL or as bytes. doctor().images says whether the tier takes image parts, in the caldrix CLI's words: "yes (SmolVLM, 64 tokens per 512-px tile)" on both tiers. On a text-only model an image part is a request refusal.

onImageProgress is called on the page after each image tile is encoded, before the prefill; a throw from it aborts the call as signal would, then, once the call has ended, the call rejects with the callback's own error (not a CaldrixError) and the engine stays usable. A call aborted while its images are being encoded ends with one done delta, finishReason: "abort", usage.completionTokens 0 and no token; the engine stays usable.

A malformed image request is a CaldrixError of kind request, in the caldrix server's words (i the message, j the part), and leaves the engine usable:

InputMessage
a remote URLmessages[i].content[j].image_url.url: remote URLs are not fetched; send a data: URL
a WebP (a data:image/webp URL, or a WebP's bytes under any label or as a Uint8Array)messages[i].content[j].image_url.url: WebP images are not accepted in this build; send a PNG or a JPEG
another media typemessages[i].content[j].image_url.url: unsupported media type; send data:image/png;base64, data:image/jpeg;base64 or data:image/jpg;base64
a detail outside the threemessages[i].content[j].image_url.detail: must be "auto", "high" or "low"
more than 8 imagesmessages: a request may carry at most 8 images; this one has {n}
bytes over the limit (8 MiB)messages[i].content[j].image_url.url: the image is {n} bytes, over the limit of {limit} bytes
bytes that are not a PNG or JPEGmessages[i].content[j].image_url.url: unsupported media type: the bytes are not a PNG or JPEG
a Blob or any other object as urlmessages[i].content[j].image_url.url: must be a string or a Uint8Array

Speech

A speech model (a Gepard checkpoint: its listing has gepard_config.json) loads by its Hugging Face repo id with Caldrix.loadSpeech, on the wasm tier (its codec on WebGPU when the page asks), in a worker of its own; SpeechEngine.speak streams the audio a text makes, piece by piece, as the frames are made. toWav writes the pieces as a WAV file and createSpeechPlayer plays them back to back on a Web Audio context.

Caldrix.loadSpeech and Caldrix.checkSpeech are listed under The API; the rest:

class SpeechEngine {
  speak(text: string, opts?: SpeakOptions): AsyncIterable<AudioChunk>;
  doctor(): Promise<SpeechDoctorReport>;
  dispose(): Promise<void>;
}
function toWav(chunks: Iterable<AudioChunk> | AudioChunk[]): Uint8Array;
function createSpeechPlayer(ctx: AudioContext): SpeechPlayer;

interface SpeechLoadOptions {
  backend?: "auto" | "wasm";
  codecBackend?: "auto" | "wasm" | "webgpu";
  offline?: boolean;
  hubBaseUrl?: string;
  maxContext?: number;
  threads?: number;
  codecWorkers?: number;
  signal?: AbortSignal;
  assets?: LoadOptions["assets"];
  onProgress?: LoadOptions["onProgress"];
}

interface SpeechThreads {
  used: number;
  asked: number | null;
  reason: string | null;
}

interface SpeechCodecWorkers {
  used: number;
  asked: number | null;
  reason: string | null;
}

interface SpeakOptions {
  seed?: number;
  temperature?: number;
  topK?: number;
  repetitionPenalty?: number;
  maxFrames?: number;
  signal?: AbortSignal;
  onFrames?: (framesSoFar: number) => void;
}

interface AudioChunk {
  samples: Float32Array;
  sampleRate: 22050;
  index: number;
  seed: number;
  framesSoFar: number;
  done: boolean;
  finishReason?: "stop" | "max_frames";
}
  • loadSpeech takes backend "auto" (the default) or "wasm"; any other value is refused (request) naming backend. A text model given to loadSpeech is refused (architecture) naming Caldrix.load, and a speech model given to Caldrix.load is refused naming Caldrix.loadSpeech. It fetches the model's listing, config.json, gepard_config.json, the weights and the tokenizer at the listing's commit, and the codec file the speech module pins, from that file's own repo, at its pinned commit, held to its pinned size and sha256 before it is read: other bytes are refused (digest) and not kept. maxContext is the context the model is lowered at; without it the default is clamped to fit the memory the load runs in (one wasm32 memory, or on threads each of two), and doctor().contextClamp says so. assets.hostWasm names the speech module's .wasm (host/caldrix_speech_bg.wasm by default).
  • threads is how many threads a speech runs on: absent, the core count the browser reports, at most 8 and at least 1; given, a whole number in 1..=64 (anything else is refused, request, naming threads). Threads run only on a cross-origin isolated page: the page that loads caldrix.js is served with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: credentialless (or require-corp), and the browser has SharedArrayBuffer and WebAssembly threads. Without one of them the load runs on one thread exactly as it does with no threads asked, and is not an error. On threads the model loads over two memories, the speech module's own and one shared by every thread, so the default context can be larger than on one thread; set maxContext for the same context on both. The extra threads are workers the page starts from the same dist/worker.js as the engine's own; a thread worker that fails ends the engine (the speech under way and every later call fail with backend, naming the thread worker), and dispose() ends every one. If a thread worker stops taking part without reporting an error (the browser ended it quietly), the page notices within bounded limits: a thread worker that has not taken up a call within 10 s, or no thread making progress for 120 s while a call is in flight, ends the engine with the same backend error (load the model again), and cancelling returns within the same limits (an abort during a hung call is read only after the watchdog has ended the call, not at once). The page checks about once a second, and later in a background tab, whose timers the browser slows. What stays unnoticed is the speech worker itself ending between calls.
  • codecWorkers is how many extra workers turn a speech's frames into samples while the engine's worker makes the next frames, on a load that runs on one memory: a whole number in 0..=8 (anything else is refused, request, naming codecWorkers); 0 runs everything in the engine's worker. Absent, it is automatic: none when the load runs on the shared-memory path (a cross-origin isolated page that can run threads, threads: 1 included), none when the browser reports under 8 GiB of device memory, else the reported core count less one, at most 2 (none when the browser reports no core count; a browser that reports no device memory gets this core-count rule, not the memory one). So a load with no codecWorkers on a page without shared memory may start two codec workers, each needing codecMemory beside the engine's worker's memory (for the real Gepard checkpoint checkSpeech answered 894,875,520 B, 853 MiB, at the desk: a reading); pass codecWorkers: 0 to keep to one worker. A count of 1 or more beside a load that would run on more than one thread is refused (request) naming both options; threads: 1 with codec workers runs on one memory. Each codec worker is the package's dist/worker.js again, holding the codec alone in a memory of its own (checkSpeech's codecMemory each), runs the speech module's .wasm from the URL the engine's worker loaded it from (the bundle's, the page's assets.hostWasm or the CDN's after a warned fallback; a codec worker never falls back on its own, and one that cannot fetch it fails to start), and reads the model's configs and the codec file from the browser's cache the load has just filled (no second download), checking them as the engine's worker does. The audio is the same, byte for byte, at 0, 1, 2 and 3 codec workers by test (each piece is the same decode at any count), and the pieces arrive in order. The first piece is not sooner by design (it needs the backbone's first frames and one codec window whatever the count); later pieces can be. A codec worker that fails to start or load, or has not loaded within 120 s, only lowers the count (down to none: the engine's worker then loads everything), and doctor().codecWorkers says why; one that ends after it loaded and before the load returns lowers it too, and when none is left the load runs once more without codec workers (its progress is reported again). So does a load whose model does not fit beside the codec workers (the speech module refuses the fit, or its memory cannot grow, while the engine's worker loads its part): the codec workers and that worker are ended and the load runs once more without codec workers, doctor().codecWorkers.reason saying so. A load runs again at most once. During a speech, a codec worker that fails, returns no samples for a piece within 120 s, or answers with a piece it was not given, ends the speech and the engine with backend, naming it (no piece is retried; load the model again). Cancelling returns at once; a codec worker in the middle of a window finishes it, and its samples are dropped. While the codec workers load, the engine's worker holds the downloaded weights, so the page's memory then is the engine worker's and theirs together. dispose() ends every codec worker.
  • codecBackend is where a speech's frames are turned into samples: "auto" (the default) and "wasm" are the paths above ("auto" is "wasm"); "webgpu", an opt-in, runs the codec in one more worker (the package's dist/worker.js again) on the browser's WebGPU device, while the engine's worker runs the backbone alone on one memory (threads absent then means one thread, on a cross-origin isolated page too). Any other value is refused (request), and so are codecWorkers 1 or more and threads above 1 beside "webgpu", naming both options. The GPU's audio is not byte-equal to the wasm path's: the frames and pieces are the same, and every sample is held within a bound on the f32 wave that was measured at the desk and fixed with headroom (observed, not derived). When the browser has no WebGPU, or the GPU codec worker fails, refuses its device or has not loaded within 120 s, the same load falls back: codec workers on the CPU at the automatic count of a load on one thread (none with an explicit codecWorkers: 0), else the engine's worker decodes; a load never fails because the GPU codec was asked for, and doctor().codec says where the codec runs and why. During a speech the GPU codec worker is under the codec workers' rules (a failure, or no samples for a piece within 120 s, ends the speech and the engine with backend); a device lost during a speech ends it the same way ("the GPU device was lost"), and one lost between speeches is reopened once, at the next speech's first piece and inside that piece's 120 s. At the desk only software adapters have run it (SwiftShader in headless Chromium). One real GPU has: on an Apple M1 Max, in Chromium on the Mac's own adapter, the small test model's cases and one speech of the real model passed, once each, every sample within the bound. On SwiftShader one window of the published codec took longer than that 120 s limit, and a speech of the real model under the package's limits ended with backend after its first piece.
  • checkSpeech answers before any weight byte: the download a load makes (the weights and the codec file, bytes), the memory it needs (memory; on threads the two memories' sum), the context and the clamp, the threads it would run on (threads), the speech module's own memory (heapMemory) and the shared one (sharedMemory, null on one thread's path), the codec workers a load would start (codecWorkers) and one codec worker's memory (codecMemory; each codec worker has its own, beside memory, not counted in it), where the codec would run (codecBackend, "webgpu" when it was asked and the page has a usable WebGPU adapter), why not on the GPU when it was asked (codecBackendReason) and the bytes the GPU codec creates on the device (codecDeviceMemory, 0 when it would not run there; 507,798,740 B for the published codec, its weights and both window programs' buffers), or the refusal by kind.
  • speak yields AudioChunks in index order from 0, each mono samples at the codec's sampleRate; the last is done with finishReason stop (the model's stop) or max_frames. The pieces concatenated are one whole decode of the frames. The knobs are the caldrix CLI's, with its defaults and ranges; seed is reported on every piece (a greedy speech, temperature: 0, reports 0). One speech at a time per engine: a second while one runs is refused (request). Leaving the loop early or aborting signal stops it, and the next speak starts at piece 0. onFrames is called with the frames made so far after each frame; a throw from it stops the speech, which then rejects with that error. The text goes to the engine's worker and nowhere else: it is never logged and never in an error.
  • doctor() reports the model and commit, the context the load ran at, the codec file and its pin, the download and the memory, where each file and the package's own files came from, and why the tier. threads (SpeechThreads) is used, the threads the speech runs on (the engine's worker counts as one; the load may settle fewer than asked so that each memory fits), asked, the threads option as given (null when absent), and reason, why it runs on one thread where threads were asked or automatic and could not run: "this page is not cross-origin isolated", "this browser has no SharedArrayBuffer", "this browser does not run WebAssembly threads" or "the shared memory could not be created", else null (threads: 1 on a page that can run threads runs the threaded path on one thread, with no reason). codecWorkers (SpeechCodecWorkers) is used, the codec workers the speech runs with, asked, the codecWorkers option as given (null when absent), and reason, why used is not simply the count asked: "this page runs wasm threads", "this device reports under 8 GiB of memory", "the shared memory could not be created after the count was chosen", "a codec worker could not be started: …" with the first failure's text, or "the model did not fit beside the codec workers" (the load ran again without them), else null; beside the GPU codec used is 0 with "the GPU codec decodes the speech in their place". codec names the codec file and its pin, where the pieces are decoded (backend, "wasm" or "webgpu"), the codecBackend asked (asked), why the codec is not on the GPU when "webgpu" was asked (reason: "this browser has no WebGPU" or "the GPU codec could not be started: …", else null) and on the GPU the adapter (webgpu (<adapter>)).
  • toWav writes the pieces as a 16-bit PCM mono WAV file at their sample rate, converting each sample as the caldrix CLI's writer does, byte for byte; no samples, a sample that is not finite, or pieces of two sample rates are refused (request).
  • createSpeechPlayer schedules each piece on the page's AudioContext where the previous one ends, or now if that has passed; stop() stops what plays and ignores later pieces, and onState reports the seconds queued and whether one is playing. The page resumes the context after a user gesture; the player never closes it.

A published speech model has run in a browser at one desk: nineninesix/gepard-1.0 at its pinned commit, with its pinned codec file, in headless Chromium on a CPU, on one memory, on threads and with codec workers (the browser-gate record). Its files were a local copy held to the Hub's listing and served at the real repo ids by a test server, not downloaded from huggingface.co; no other browser or device has run it, and no one has judged the sound. The package's browser tests run a tiny random-weight test model and a tiny test codec in headless Chromium: their frames equal the reference's, and the pieces equal one whole decode.

Options

interface LoadOptions {
  backend?: "auto" | "webgpu" | "wasm" | "webgl";
  offline?: boolean;
  onProgress?: (p: { file: string; loaded: number; total: number | null; repo: string; revision: string; provenance?: string }) => void;
  hubBaseUrl?: string;
  file?: string;
  dtype?: "f32" | "bf16";
  maxContext?: number;
  memory?: "single" | "split";
  weightMemoryBytes?: number;
  storage?: "auto" | "f32";
  signal?: AbortSignal;
  assets?: { worker?: string | URL; hostWasm?: string | URL; fallback?: boolean; cdn?: string | URL };
}
  • backend: "auto" (the default) probes the browser and picks WebGPU when an adapter is present and requestDevice succeeds, wasm otherwise; a bf16 plan goes to wasm on the page, before the worker starts. "webgpu" and "wasm" force a tier. "webgl" is declared and refused: the backend is not built. Under "auto", a load WebGPU then refuses (a larger explicit context, a limit, a device that fails to open) is served by the wasm tier, and doctor().why says so. A quantized GGUF alias under "auto" is placed as any alias: WebGPU is probed first, and a refusal of the same kinds falls back to wasm.
  • Quantized aliases: smollm2-instruct:q4_K_M and smollm2-instruct:q8_0 are one GGUF file each. A load reads the file's header with a range request first (and rope_freqs.weight's small extent as a second range when it lies past the header), then verifies the whole file against the alias's pinned sha256 before parsing it. Both tiers have their kernels; on the WebGPU tier the weights stay in their blocks and doctor().storage is "blocks". What has run with them is under "What has run, and where" below.
  • onProgress: called with each model file's progress: the file, the bytes loaded and the total (null when the size is not known), repo and revision (the repo and commit it is fetched from: for an adapter, its own or its base's) and, once the tier that serves is settled, provenance (the model: line of a densified load).
  • dtype: the plan's dtype, "f32" or "bf16".
  • storage: the WebGPU tier's weight storage. "auto" stores the block GEMM weights as f16 when the adapter has shader-f16; "f32" keeps them f32 on any adapter. storage: "f32" on a quantized alias is satisfied: nothing is narrowed, and the weights stay in their blocks. doctor().storage reports it ("blocks" for a quantized alias, null on wasm). storage: "f32" with backend: "wasm" is refused.
  • maxContext: the context length to load at; see the default context.
  • memory: where the wasm tier places a GGUF file's weights. Absent (the default), they go in the one memory whenever the model fits it; a single GGUF file that does not fit one memory has its weights placed in several memories (up to four) when the browser has multi-memory, and is refused before its body is downloaded when it does not (the message says the browser lacks multi-memory when the model's total is what does not fit). "single" asks for the one memory. "split" places the weights in several memories beside it, created before the file's body is requested; it needs a browser with multi-memory, and a weight memory the browser cannot create is a fit error naming it. Only a single GGUF file on the wasm tier can be split: any other load given "split" is a request error naming it; under backend: "auto" the WebGPU tier's refusal moves the load to the wasm tier, as its other refusals do (this ran on a software adapter, not a GPU). A split load's doctor().line ends with , memory: split, and the number of weight memories; a one-memory load's line is unchanged. Placing weights in several memories has run in headless Chromium on a small test file (the browser-gate record, entry 71) and on one real 8B model file past 4 GiB, served by the loopback hub under a test repo id and loaded with no memory option into 2 weight memories (entry 72). In the browser test session that ran it, the file was not kept in the browser's cache and a second load downloaded it again. The package keeps a file past 64 MiB in the cache as parts of that size and an index (a browser may refuse one entry past a size it does not announce), and in the same session the file was kept and a second load read it from the cache (entry 73). The same file was kept and read back the same way in that browser over a profile directory and in Firefox 155, one test run each (entry 74), and in both a second visit, the browser closed and opened again over the same profile, read it from the cache (entry 76). Not run past 4 GiB: any browser but those two, any device, the WebGPU tier, the default context, a real Hub download, a file needing more than 2 weight memories, a weight memory of the full 4 GiB.
  • weightMemoryBytes: for diagnosis, the bytes each weight memory of a memory: "split" load may hold (a multiple of 64 from 128 bytes to 4 GiB; the default is 4 GiB). Refused without memory: "split".
  • file: the GGUF file to load from a repo id, by its name at the repo's top level ("model-Q4_K_M.gguf"). A repo whose listing has no config.json with safetensors weights, and a GGUF file at its top level, is a GGUF repo, and loading it without file is a request error that names the candidate files (mmproj* files and sharded -NNNNN-of-NNNNN.gguf files are never candidates). The file is fetched at the listing's resolved commit and checked against the listed size and, when the listing carries one, its LFS sha256 (else the Hub's X-Linked-Etag); the config, tokenizer and chat template come from the file's own metadata, and a config.json in the repo is ignored. The weights stay in their blocks. A dense GGUF (F32, F16, BF16) defaults to an f32 plan. file on an alias or a safetensors repo is a request error.
  • hubBaseUrl: where the model files and, for a repo id, the Hub listing (/api/models/…) are fetched from (default https://huggingface.co); a mirror serving only files loads aliases but not repo ids. offline uses only the browser's cache and fails with fetch for a file it lacks.
  • signal: cancels the load. Before the model is loaded, an abort terminates the engine's worker and the load rejects with fetch; after the load resolves the signal is ignored.
  • assets: where the package's own files come from; see Network.

Checking a model before loading it

type CheckOptions = Pick<LoadOptions, "backend" | "dtype" | "maxContext" | "storage" | "hubBaseUrl" | "file" | "signal" | "assets">;
type CheckResult = { ok: true; backend: "webgpu" | "wasm" } | { ok: false; kind: Kind; message: string };

const r = await Caldrix.check("smollm2-instruct");
if (r.ok) console.log(`a load would run on ${r.backend}`);
else if (r.kind !== "fetch") console.log(`a load would be refused: ${r.message}`);

Caldrix.check says which tier a load of the model would end on in this tab, or why the load would be refused, without loading it. It takes the same model and the same tier-deciding options as load, and assets, so it starts the same worker and .wasm the load would, under the same fallback rule; it runs the same option checks, the same probe and the same tier choice. Its worker then runs the load only until the tier is settled: for a repo id the Hub listing (for a LoRA adapter repo, its adapter_config.json and its base's Hub listing too), then config.json and the safetensors index (for a GGUF file, an alias's or one named by file, the file's header range instead, and rope_freqs.weight's extent, at most 512 bytes, as a second range when it lies past the header), the same precheck as load, and on the WebGPU tier the device open, after which the device is destroyed. It never fetches a tokenizer file or a weight, sends no onProgress events, and is never offline.

A check or fit that answers ok leaves its worker open for five seconds, and the next check or fit with the same assets takes it: a list of models checked one after another starts one worker and compiles the .wasm once. A refusal, an abort and a load each end that worker, as does a second check answering beside one already left open.

Under backend: "auto" the answer is the tier the load would end on: a WebGPU refusal of the kinds load falls back on (a limit, a larger explicit context, a device that fails to open) answers { ok: true, backend: "wasm" }, and a bf16 request answers wasm as load places it. An explicit "webgpu" or "wasm" answers that tier or its refusal.

check never rejects. Every refusal is { ok: false, kind, message }, with the kind and message load would give: an option it refuses (an unknown backend, a hubBaseUrl that is not an absolute http(s) URL, an empty model, storage: "f32" with backend: "wasm") is request, a model past this tab's limits is fit, and a worker that cannot start or answers out of protocol is backend. kind: "fetch" means the answer is unknown: a file could not be fetched, or the check was aborted through signal (checking <model> was aborted), so a load might still succeed. The CDN fallback for the package's own files applies as on a load (off with assets.fallback: false), warned once per check on the console. The files a check fetches are written to the cache, and a later load reuses them.

Fitting a GGUF file from its recorded facts

type FitOptions = Pick<CheckOptions, "backend" | "maxContext" | "signal" | "assets">;
type FitResult = { ok: true; backend: "webgpu" | "wasm"; maxContext: number | null; contextClamp: NonNullable<DoctorReport["contextClamp"]> | null } | { ok: false; kind: Kind; message: string };

// `facts` is a `QuantFacts`: what the nightly records for one GGUF file of a repo.
const r = await Caldrix.fit(facts);
if (r.ok) console.log(`a load would run on ${r.backend} at context ${r.maxContext}`);
else if (r.kind !== "fetch") console.log(`a load would be refused: ${r.message}`);

Caldrix.fit says whether a GGUF file would load in this tab, on which tier and at what context, from the facts recorded for it (QuantFacts: the file's name, size and digest, its architecture and dimensions, the element count per tensor type, the base model (base_model), general.file_type, and the tensor table, each tensor's name, type and dims), and it fetches nothing: no Hub listing, no range and no file. It takes check's tier and context options and assets, runs the same option checks, probe and tier choice, and in its worker the same precheck a load of the file runs, with the file's header replaced by the facts; on the WebGPU tier it opens the device and destroys it again, and under backend: "auto" a WebGPU refusal answers wasm as check's does. { ok: true } carries the tier, maxContext (the context a load would plan) and contextClamp (the clamp's line when the default context was clamped, else null), as a load's doctor() reports them.

A caller holding a larger record (the nightly's web-quants.json entry, say) passes only these keys: an unknown key is refused as validate, so a page projects each entry onto them. fit answers the default weight storage for the tier; FitOptions has no storage, so a page that loads a dense file with storage: "f32" gets fit's answer for the default storage (quantized files are unaffected).

The tensor types fit admits are the ones this build runs: a tensor of any other type is { ok: false, kind: "architecture" }, its name and type in the message. Facts that are not a plain object, or are past the size a fit takes once serialised, are request; facts the host refuses (an unknown or missing key, a table past the GGUF reader's caps) are validate; a file past this tab's limits is fit, and a worker that cannot start or answers out of protocol is backend. fit never rejects; kind: "fetch" (an abort through signal, the fit was aborted) leaves the answer unknown.

fit judges one memory only: it can refuse a GGUF file that load would place in several memories (see memory under "Options"); check agrees with a load that names no memory.

A facts admit is never a load guarantee. check and load judge the file's own header at the commit the listing pins, and the facts cannot show what only the file holds: the values of rope_freqs.weight, a missing attention.layer_norm_rms_epsilon, or a tensor whose bytes or element count disagree with the table. Facts recorded from an older commit of a repo answer for that file.

What has run, and where

Only these runs are recorded (the browser-gate record: entries 5, 8 and 9 in the browser, and for the quantized aliases entries 10 and 11 off-browser and entries 12 and 14 in the browser, and for the adapter and nf4 repos entry 16 off-browser and entry 17 in the browser, and for Caldrix.check entry 20 in the browser, and for the Try page entry 21 in the browser, and for a GGUF file in a repo entry 22, and for Caldrix.fit entry 24, and for images entries 59, 60 and 63, and for weights in several memories entries 71 and 72); nothing else is claimed.

  • Model: SmolLM2-135M-Instruct, one prompt, 8 greedy tokens; the adapter and nf4 repos below add a LoRA adapter over it and SmolLM2-360M-Instruct's nf4 repo, on their fixtures' prompt. No other model or prompt.
  • Browser: Chromium driven by Playwright, headless only: the headless shell 153.0.8010.12 on Linux (entries 5 and 8) and on an Apple M1 Max (entry 9), and on that Mac Playwright's full Chromium (new headless mode, userAgent HeadlessChrome/153.0.0.0) for the WebGPU tier (entry 9). No other browser.
  • wasm tier (entry 5 on Linux, entry 9 on the Mac, with the same lines): both plan dtypes, f32 and bf16. The tokens equal the references' tokens. The f32 logits stayed inside the 1e-2 bound on every row, worst 7.796401e-4. The bf16 result rests on token equality alone; the logits were recorded, not gated.
  • WebGPU tier on a real adapter (entry 9): the Mac's own, vendor apple, architecture metal-3 (its own strings; device and description empty), with shader-f16. The f32 plan at f32 weight storage, token-exact, logits worst 6.6792103e-4 against the same 1e-2 bound; at f16 weight storage, a diagnostic gated by no bound, every row finite, worst 5.0272985e-4, token-exact. The product path's tokens equal the test worker's at both storage forms.
  • WebGPU tier on SwiftShader (entry 8): Dawn on SwiftShader, Google's CPU Vulkan implementation, which is a CPU and not a GPU. The f32 plan at f32 weight storage, token-exact, logits worst 5.874168e-4 against the same bound.
  • quantized aliases: off-browser at the desk on both tiers (the browser-gate record, entries 10 and 11); in headless Chromium through Caldrix.load on both tiers on the pinned files, WebGPU on Dawn/SwiftShader, a CPU (entry 12); on the operator's Mac through Caldrix.load on both tiers, WebGPU on the Mac's own adapter, vendor apple, architecture metal-3, token-exact (entry 14).
  • adapter and nf4 repos by id (a LoRA adapter over SmolLM2-135M-Instruct, and SmolLM2-360M-Instruct's bitsandbytes nf4 repo, each at a pinned sha): off-browser at the desk on both tiers (the browser-gate record, entry 16: wasm both pairs and WebGPU the LoRA pair token-exact, the f32 plan at f32 weight storage; the WebGPU nf4 pair stopped at lavapipe's storage-buffer binding limit); in headless Chromium through Caldrix.load by repo id on both tiers, both pairs token-exact, the f32 plan at f32 weight storage, WebGPU on Dawn/SwiftShader, a CPU (entry 17).
  • Caldrix.check: in headless Chromium against the loopback hub (the browser-gate record, entry 20): on a repo id, check and load agreed on the wasm tier and, with WebGPU enabled in the browser, on the WebGPU tier on Dawn/SwiftShader, a CPU, and the check fetched no tokenizer file and no weight; an index past the wasm ceiling checked as fit, an unknown repo id as fetch.
  • the website's Try page: in Brave on an Apple M1 Max, headed, every model on its list loaded by repo id from the real Hub on the WebGPU tier, answered one chat message and ran the agent's first chip, as the operator reported it (entry 21).
  • a GGUF file in a repo by name (file): in headless Chromium through Caldrix.load against the loopback hub's tiny fixtures, on the wasm tier and on the WebGPU tier on Dawn/SwiftShader, a CPU, token-exact to the test harness's own tokens, with the name selecting the file, a digest mismatch refused as digest, and a header context past the wasm32 heap clamped and reported by doctor; off-browser, a rope-scaled quantized model token-exact on both tiers and the quantized row kernels past the grid dimension limit on lavapipe, a CPU (entry 22).
  • Caldrix.fit: in headless Chromium against the loopback hub's tiny fixtures, on the wasm tier and on the WebGPU tier on Dawn/SwiftShader, a CPU: the committed facts of the hub's Q8_0 file and of its long-context copy answered ok with the tier, and the maxContext and contextClamp a load of that file reported in doctor(), with no request to the hub; the facts with one tensor's type changed to one this build lacks answered architecture naming it; off-browser, the fit from facts equals the fit from the header on every tiny fixture (entry 24).
  • images on the WebAssembly tier (the browser-gate record, entries 59 and 60), in headless Chromium on Linux. SmolVLM-256M-Instruct's browser check ran on a test build of the browser host that admitted the model ahead of this version. Its first run stopped where a JPEG's image rows, from the package's own decode of the file, were further from transformers' than the check's bound allows (entry 59). The owner then amended the JPEG check to hold to that bound the rows of the reference's own decode of the file, the real file's tokens still checked, and the second run passed (entry 60): on the test page at f32, four low-detail images, the reference decode and a 13-tile high-detail image gave transformers' tokens, with every checked tile's image rows within the bound, in tile order; at bf16, two low-detail images gave transformers' tokens; through Caldrix.load in its worker, the four low-detail images and a Uint8Array gave the test page's tokens. On the build the package ships: a tiny test vision model through Caldrix.load on the WebAssembly tier, token-exact to transformers' tokens at both details, with tile progress, a Uint8Array image, a mirrored image giving other tokens, a second turn, a cancel during the tiles and the request refusals (its tokens do not show the order of the tiles or of the rows within one), and the same model on the WebGPU tier on Dawn/SwiftShader, a CPU, token-exact at both details, backend: "auto" serving it there.
  • images on the WebGPU tier (the browser-gate record, entry 63), on the operator's Apple M1 Max in Playwright's full Chromium (new headless mode), on the Mac's own adapter, vendor apple, architecture metal-3. SmolVLM-256M-Instruct's browser check ran on a test build of the browser host that admitted the model on WebGPU ahead of this version; the version that ships it differs from that build in where the admission comes from. At f32 weight storage, checked: in the test worker three low-detail images, the reference's decode of the JPEG and a 13-tile high-detail image gave transformers' tokens, with every checked tile's image rows within the check's bound, and a WebP was refused by name; through Caldrix.load the three low-detail images and a Uint8Array gave the test worker's tokens, a call aborted at tile 2 of 13 ended with one abort delta, and the engine was usable after. At f16 weight storage the Caldrix.load cases ran as a diagnostic: their tokens were recorded, not compared.
  • Not run: images on any other WebGPU adapter, browser or device, or at f16 weight storage as a checked form; backend: "auto" on a real vision model; a multi-tile image of a real model through Caldrix.load; any other high-detail image or a bf16 high-detail image; any real GGUF repo by id in a browser; Llama 3.2 or any model with a 128k vocabulary in a browser; a 2D-grid dispatch on a real adapter (the WebGPU row kernels past the grid dimension limit ran on lavapipe only); the WebGPU heap clamp in a browser; any other WebGPU adapter or GPU; the WebAssembly tier in a headed browser; the scalar (non-SIMD) wasm build in a browser; real-Hub digest behaviour (the runs used a loopback Hub stand-in); a real Hub listing for a repo id (the loopback hub served the pinned snapshots) beyond the Try page's own loads (entry 21); any browser other than Playwright's Chromium and Brave (entry 21); any model beyond SmolLM2-135M-Instruct and the ones in entries 12, 16, 17, 18, 19, 21, 59 and 60; Caldrix.check against a real adapter's buffer limit (its unit tests only), against the real Hub, or in any other browser or on any other device; Caldrix.fit on facts the nightly recorded for a real repo, or on a real adapter. No performance figure is recorded or claimed.

The default context

On both tiers, a default context whose fit does not stay 64 MiB under the wasm32 heap's 4 GiB ceiling is clamped to the largest multiple of 256 whose fit does (a margin for the fit's stated, unmeasured terms; the margin itself is not yet measured; an explicit maxContext is held to the ceiling itself), and on WebGPU the smaller of that and the grid bound applies (doctor() reports it as above). The heap clamp ran in a browser on the wasm tier only, on a tiny fixture with a very large header context; on the WebGPU tier that run printed only the grid clamp (entry 22).

Without maxContext, the WebGPU tier clamps the context so the attention kernel's grid stays within maxComputeWorkgroupsPerDimension. At the standard 65535 workgroups per dimension, SmolLM2's 8192 default context loads at 7282 (entries 8 and 9); doctor() reports the clamp in contextClamp and the value in maxContext. A larger maxContext that the adapter's limits cannot hold is refused by WebGPU, and "auto" then serves the load on wasm.

Network

No telemetry. The network is the Hub, for the model files you asked for (for a speech model, also its pinned codec file), and jsdelivr, for the package's own assets when the bundle's copy fails.

  • When the fallback fires: the worker falls back if it fails before it is ready (its script, a chunk or the host glue did not load, or the page refused to construct it); the .wasm falls back, inside the worker, if its fetch fails. Each asset is tried locally first and falls back independently.
  • What it fetches: https://cdn.jsdelivr.net/npm/@caldrix-ai/caldrix@<installed version>/dist/worker.js and .../host/caldrix_web_bg.wasm (for a speech model, .../host/caldrix_speech_bg.wasm), at the version you installed, so the .wasm matches the glue.
  • It is never silent: it is warned once per load on the console, and doctor().assets reports the source and URL of each asset.
  • Opt out: assets: { fallback: false }. An explicit assets.worker or assets.hostWasm is used as given, with no fallback for that asset. assets.cdn points the fallback at your own mirror.
  • What it trusts: the fallback runs jsdelivr's copy of that version with your page's origin (the worker can fetch your origin with its credentials and read its IndexedDB and caches), and no integrity check is possible for a worker's module import, so a page that cannot accept that sets assets.fallback: false.
  • What has been checked: jsdelivr serves the published package's worker, glue and WebAssembly files byte-identical to the npm tarball, with CORS open to any origin. After the first release was published, the browser fallback ran once against jsdelivr itself in headless Chromium, with the default cdn: a page whose bundle lacked the worker, and one whose bundle lacked the .wasm, each chatted to done with doctor() naming the jsdelivr URLs and one warning on the console. That was a one-off check at the desk; the committed tests point assets.cdn at a loopback origin and never reach jsdelivr.
  • Content-Security-Policy: a page that uses the fallback needs worker-src blob: (a cross-origin worker starts through a same-origin module shim), script-src and connect-src for the CDN origin, and 'wasm-unsafe-eval' for any WebAssembly.

Bundlers

What ran: Vite 8.3.5 and Next.js 16.4.6 (Turbopack and webpack) with output: "export", a minimal app each, on the wasm tier with a tiny Llama fixture served from a loopback Hub, in headless Chromium. The package's own bundler test installs the packed package into those apps and runs in CI. Those apps needed no bundler configuration. Nothing else is claimed: other versions, other bundlers and the WebGPU tier under a bundler have not been run. Production builds only (vite build, next build); vite dev and next dev were not run.

  • Each app ships an unused copy of the worker and (Next only) an unused copy of the host glue. The worker copy comes from the package's new URL("./worker.js", import.meta.url) literal, which it keeps so bundlers find the worker; the glue copy comes from wasm-bindgen's own .wasm URL literal inside the glue, which the package does not control.
  • By the package's design, not run: with assets on another origin (Vite base, Next assetPrefix) the bundle try is cross-origin, the shim imports the raw copy of the worker whose ../host/ is not beside it, and every load falls back to jsdelivr. Set assets.worker and assets.hostWasm instead, serving the package's dist/ and host/ together on that origin.
  • Next pages that import the package are client components.

License

The npm package @caldrix-ai/caldrix (caldrix.js) is under Apache-2.0; the package carries LICENSE and NOTICE. The compiler itself is not open source; the package ships its compiled browser host under the package's license. Third-party components compiled into the host remain under their own licenses; see THIRD_PARTY_NOTICES.md in the package.