Mental model
A client-side query router scores a request before invoking a model, then selects a local, remote, or no-execution path under explicit quality, latency, cost, privacy, and consent rules. The router is a policy boundary, not a way to infer permission from text: a high-confidence classification cannot authorize disclosure or silently move sensitive content off device.
Theory
A browser router usually combines a compact classifier with deterministic policy. The classifier estimates features such as task type, whether a local model can answer, or the chance that a local response will miss a quality threshold. It runs before the larger model and does not need to send the original query anywhere. The policy then checks user preference, sensitivity rules, network availability, and the measured limits of each candidate. Its result can be local, remote, or defer. Defer is a real outcome for offline requests, low confidence, unsupported languages, or requests that need a user decision.
RouteLLM studies routing between stronger and weaker language models using preference data to balance response quality and cost. That paper supports the quality-cost routing idea; it does not demonstrate that a browser classifier can safely choose between a local model and a cloud service. A client-side implementation must evaluate that specific choice with its own model versions, users, languages, and failure costs. The local model can run through browser libraries such as Transformers.js or ONNX Runtime Web, using a supported WebAssembly or WebGPU execution provider. WebGPU support and operator coverage depend on the browser, device, model, and runtime build, so a production route needs an availability and fallback check.
A router should keep permission separate from prediction. A private query stays on device unless the user has been clearly told what will be transmitted and has affirmatively chosen that route; even then, product rules may prohibit remote processing for some data. If the user has not consented, the system can run the local model, ask whether the user wants a remote option, or defer. It must never interpret a low local-confidence score as permission to upload.
For requests eligible for remote inference, compare the expected loss from a local miss with the incremental remote call cost:
Here, is the calibrated probability that the local route fails the quality criterion for request ; is the USD cost of such a failure; and is the USD cost per remote request, including the assumed service charge. Both sides have units of USD per query. This inequality is useful only after hard privacy, consent, and product-policy gates pass.
Worked routing example
An evaluation set contains 1,000 queries. The router sends 250 ambiguous but cloud-eligible queries to a candidate fallback. For that subset, a held-out evaluation estimates a 0.32 probability that the local model misses the defined quality criterion. If the cost of a miss is USD 0.12 per query and the remote call costs USD 0.002, then expected local miss loss is USD per query, above the remote charge. Across 250 queries, that is USD 9.60 of estimated miss loss versus USD 0.50 in remote calls, before accounting for remote errors or latency. The calculation does not permit a route when the user has not consented.
Measure these terms on a time-separated validation set and refresh them when prompts, model versions, task mix, or service prices change. Do not treat classifier confidence as a guarantee of answer quality. The router's threshold should include an uncertainty band that returns defer when the estimate is poorly calibrated or far outside the evaluation distribution.
Request path
Tokenization and route features should remain local until the policy chooses an allowed destination. The application can extract coarse features such as input length, selected task, local model availability, and a calibrated local-failure probability. It should avoid logging the raw prompt to route telemetry by default. Record the route reason, router version, model version, and aggregate outcome where the user has been informed and the retention policy permits it.
A route is not complete when a classifier emits a label. The chosen runtime must load, have enough memory, and support the model's operators. ONNX Runtime Web can use WASM for CPU execution and WebGPU where supported, but a GPU path can fail during session creation or have unsupported operators. If a local model cannot start, re-evaluate policy: do not silently send the query to a remote service. If remote consent and policy allow it, offer that route; otherwise defer with a clear explanation.
Implementation example
The classifier supplies a calibrated local-failure probability. This pure policy function never transmits the query; the caller dispatches only after checking the returned route and the user's explicit remote permission.
typescripttype RouteInput = {localFailureProbability: number;missCostUsd: number;cloudCostUsd: number;privateInput: boolean;remoteConsent: boolean;localAvailable: boolean;cloudAvailable: boolean;};type RouteDecision = {target: "local" | "remote" | "defer";reason: string;};export function chooseRoute(input: RouteInput): RouteDecision {const probability = input.localFailureProbability;if (probability < 0 || probability > 1) {throw new RangeError("failure probability must be in [0, 1]");}if (input.missCostUsd < 0 || input.cloudCostUsd < 0) {throw new RangeError("costs must be non-negative");}if (input.privateInput || !input.remoteConsent) {return input.localAvailable? { target: "local", reason: "remote route is not permitted" }: { target: "defer", reason: "no permitted model is available" };}if (!input.localAvailable) {return input.cloudAvailable? { target: "remote", reason: "local runtime is unavailable" }: { target: "defer", reason: "all runtimes are unavailable" };}const expectedMissUsd = probability * input.missCostUsd;if (input.cloudAvailable && expectedMissUsd > input.cloudCostUsd) {return { target: "remote", reason: "expected miss cost exceeds call cost" };}return { target: "local", reason: "local route meets the cost policy" };}const decision = chooseRoute({localFailureProbability: 0.32,missCostUsd: 0.12,cloudCostUsd: 0.002,privateInput: false,remoteConsent: true,localAvailable: true,cloudAvailable: true,});if (decision.target === "remote") {console.info("Remote route allowed by consent and measured policy");}
Failure modes and misconceptions
A router trained on short English support questions may misclassify multilingual, code, or long-context requests. Evaluate each route class on representative, consented examples and include confidence calibration, not just overall accuracy. If the route model is uncertain or sees an out-of-distribution request, defer rather than pretending its label is authoritative.
A second failure is policy leakage: a high local-failure estimate causes a remote request even though the user selected local-only mode. Keep permission as a hard gate checked after scoring, and test it with sensitive examples. Telemetry can undo the privacy benefit if it stores raw text or unique prompt details; log only the minimum route metadata needed for monitoring.
Trade-offs
Local inference reduces the need to transmit query text, but it has costs: model download, device memory, battery, thermal throttling, and slower startup. A remote model may return faster on a high-end server, but adds network delay, service cost, and a data boundary. Benchmark complete user-perceived latency from input to rendered result, not just model kernel time. Keep a local-only path usable when the network disappears and make a remote fallback visible rather than automatic.
Decision scenario
A personal-finance assistant classifies a user's pasted transaction history as difficult for the small local model. The user's settings say local processing only, while the browser is online and the cloud model has passed the quality threshold. Keep the request local if the small model can return a clearly limited result; otherwise defer and ask the user whether they want to change the route. Do not send the history to the cloud merely because the router predicts better quality.
Learning outcomes
- Explain how an on-device classifier and explicit policy divide query routing responsibilities.
- Calculate when expected local-miss cost exceeds a remote call cost, while preserving consent as a separate gate.
- Design local, remote, and defer outcomes for unsupported, sensitive, offline, or uncertain requests.
- Evaluate route quality and user-perceived latency across model, device, and task cohorts.