Skip to main content

ModelSaar

ModelSaar 0.3.0. Install the PyPI package, pull the container, or use the guided installer. The support matrix lists which capabilities have been exercised on real hardware.

ci

Intelligent routing for local AI models. One endpoint. Intelligent model selection.

ModelSaar is a small, local-first, OpenAI-compatible gateway. Your applications (Open WebUI, OpenClaw, OpenCode, Hermes Agent, anything that speaks Chat Completions) connect once and ask for a virtual model such as auto. ModelSaar inspects each request, keeps only the deployments that can actually satisfy it (tools, images, strict JSON schemas, context size, locality, health, capacity), ranks the rest on evidence, routes the request to the winner (the body passes through except documented client-compatibility translations), and records a decision you can inspect.

client ──/v1/chat/completions (model: auto)──▶ ModelSaar ──▶ ollama/qwen3.8:27b
                                                  │            ollama/gemma4:e4b
                                                  │            vllm/...
                                                  └─ X-ModelSaar-Deployment, /admin/explain

Validation history. Core routing, streaming, embeddings, probes, CLI, client config generation, evaluation harness and a fault-injection test suite are implemented and tested against controlled backends, and exercised live against a real Ollama server with eight models (discovery, probes, routing, streaming, tool calls, evaluation). Read the verification report before relying on any specific compatibility.

Why

  • Connect once. Clients can manage their own tools and history. Operators can also enable hosted tools and caller-owned conversations on the Responses API.
  • Never silently degrade. No truncated history, dropped images, weakened schemas, stripped tools, or hidden cloud fallback. If nothing qualifies you get a structured error with blockers and remedies.
  • Evidence over marketing. Capabilities are three-state (supported | unsupported | unknown) with provenance (runtime metadata, probe, operator). Quality estimates are labelled measured, prior or uncalibrated. Unknown required capabilities never qualify.
  • Local and private by default. Loopback bind, generated keys, no prompt logging, cloud-forwarded models excluded unless you opt in, backends only reachable at their configured hosts.
  • Small. Five runtime dependencies (Starlette, uvicorn, httpx, pydantic, PyYAML). No Docker, Envoy, Redis, Postgres, GPU toolkit or mandatory classifier model.

Release 0.3.0

Release notes cover the new opt-in features, the context and memory changes that can affect existing deployments, and rollback. Install from the tagged source, Python package or container:

# 1. From the tag (always available)
git clone https://github.com/gopalasubramanium/modelsaar.git && cd modelsaar && git checkout v0.3.0
python3 -m venv .venv && . .venv/bin/activate && pip install .

# 2. From PyPI or the public container registry
pip install modelsaar==0.3.0
docker run -v modelsaar-data:/data -v ./config.yaml:/data/config.yaml:ro -p 127.0.0.1:8484:8484 ghcr.io/gopalasubramanium/modelsaar:v0.3.0

The one-line installer on modelsaar.com installs the commit it pins (shown on the site), in its own environment, and upgrades or rolls back an existing installation (installation).

New in 0.2: POST /v1/responses, POST /v1/messages and the opt-in response store (protocols); POST /v1/guardrails, POST /v1/ocr, POST /v1/vote, audio/video input, multimodal embedding items (pipelines); exact token counts and served-context detection per runtime (routing); modelsaar lifecycle (lifecycle); cascades, replica scheduling and modelsaar learn (cascades and learning); modelsaar judge (evaluation). All of it is additive or opt-in: a 0.1 configuration runs unchanged. One table gives the evidence level of every item: docs/roadmap-matrix.md.

Release candidate: decision models (v0.1.0-rc.2; opt-in, experimental — not a stable release)

POST /v1/decisions (typed questions answered by a decision model such as Ollama's nimble, clef or laya through its native /v1/systemone API) and the routing classifier's mode: decision were merged on main at commit 6075cdcf3b0952d4213a7899438f5fe546e95d19 and are available as the GitHub pre-releases v0.1.0-rc.2 (https://github.com/gopalasubramanium/modelsaar/releases/tag/v0.1.0-rc.2 — rc.1 plus the continuation capability probe, modelsaar probe <id> --which continuation, and a corrected 422 remedy) and v0.1.0-rc.1 (unchanged). They are fixture-tested in CI and were exercised once live with three requests (docs/live-runs/2026-10-28-decision-preview-smoke/); nothing about answer quality or routing benefit is claimed. The continuation probe establishes protocol acceptance of reasoning_content in the assistant history, not semantic continuity; it was run live once from v0.1.0-rc.2 against ollama/qwen3.8:latest (Ollama 0.40.5) and reported supported (docs/live-runs/2026-10-29-rc2-continuation-probe/; one deployment, no override, nothing about other models or a real client's follow-up turn). A candidate is GitHub-only: no PyPI package, no container image, and the package version stays 0.1.0 (docs/release.md, "GitHub-only pre-releases"). The one-line installer now installs version 0.3.0, which includes these features. To try the candidate side by side with a stable install, use the ordinary source install at the tag with its own home:

git clone https://github.com/gopalasubramanium/modelsaar.git modelsaar-preview && cd modelsaar-preview
git checkout v0.1.0-rc.2
python3 -m venv .venv && . .venv/bin/activate && pip install -e .
export MODELSAAR_HOME=~/.modelsaar-preview        # separate config, keys and state
modelsaar init --port 8485                         # or --endpoint http://host:11434 --type ollama
modelsaar discover                                 # a decision model shows role "decision"
modelsaar serve

Contract and limits: docs/routing.md ("Decisions"); classifier configuration: docs/extending.md; the web page with the tester instructions and the smoke-test record: https://modelsaar.com/preview/decision-models/.

Quickest working setup

Prerequisites: Python 3.10+, and a running local inference server with at least one model (Ollama is the first-class path; any OpenAI-compatible server works with declared models).

# 1. install from the release source
git clone --branch v0.3.0 https://github.com/gopalasubramanium/modelsaar.git && cd modelsaar
python3 -m venv .venv && . .venv/bin/activate      # or: uv venv && . .venv/bin/activate
pip install -e .                                   # or: uv pip install -e .

# 2. initialise: finds Ollama on 127.0.0.1:11434 (or pass --endpoint), writes config + keys, discovers models
modelsaar init

# 3. check and verify
modelsaar doctor            # reachability, context assumptions, unknown capabilities, cloud aliases
modelsaar probe --all       # live checks: streaming, tools, JSON schema, vision, continuation, latency (uses local compute)

# 4. run
modelsaar serve             # http://127.0.0.1:8484/v1 ; keys in ~/.modelsaar/keys/

# 5. first request (in another shell)
modelsaar test              # identifies the gateway (GET /healthz), GET /v1/models, one routed completion through `auto`

Example request:

curl -s http://127.0.0.1:8484/v1/chat/completions \
  -H "Authorization: Bearer $(head -1 ~/.modelsaar/keys/api_keys)" \
  -H "Content-Type: application/json" \
  -d '{"model":"auto","messages":[{"role":"user","content":"Write a Python function that parses ISO dates"}]}' \
  -D - | grep -i x-modelsaar      # X-ModelSaar-Deployment tells you what was selected

Then connect a client. One command per client (pick yours; these are separate commands, not a pipeline): modelsaar client-config open-webui, modelsaar client-config openclaw, modelsaar client-config opencode (or opencode-v2), modelsaar client-config hermes. Each prints verified configuration; --apply merges file-based configs with a backup. For a GUI field that asks for an API key, print the key in a terminal with head -1 ~/.modelsaar/keys/api_keys and paste the value it prints (a line starting with msk_) — the $(...) form above is shell syntax, not a key. See docs/clients/.

No models yet? modelsaar demo starts a clearly labelled simulated backend so you can try the CLI, the status page and route explanations without downloading anything.

Virtual models (aliases)

alias profile notes
auto quality default: best expected quality within limits; effectively tied candidates resolve to the lower-overhead one
auto-quality quality same as auto
auto-balanced balanced more weight on latency and residency
auto-fast fast prefer resident, low-latency deployments
auto-code quality only deployments tagged code
auto-vision quality only deployments with verified image input

Aliases are advertised in GET /v1/models only when at least one usable deployment backs them, with a truthful contract (context_length_min, tools/vision/json_schema = supported/partial/unsupported). Any concrete deployment id (e.g. ollama/qwen3.8:27b) can be requested directly; it still passes the same hard checks.

How a route is chosen

  1. Requirements – structural analysis of the whole request: roles, images/audio, tools and tool_choice, response_format, outstanding tool-call ids, reasoning_content, conservative token accounting (input + output allowance + reasoning budget for thinking models).
  2. Hard filters – role, health, locality policy, capability tri-state, effective context, backend field support, admission feasibility. A score can never override a failed filter.
  3. Classification – deterministic multi-label task signals; an optional local classifier is consulted only for ambiguous cases, under a strict contract with timeout and fallback — either a small chat model answering JSON or, with routing.classifier.mode: decision, a decision model (Ollama /v1/systemone: nimble, clef, laya) answering one choice question with probabilities.
  4. Ranking – transparent score per profile: evidence-based quality (measured > prior > uncalibrated, with uncertainty) minus latency, residency/load and overhead costs, plus a switching penalty for session affinity.
  5. Decision record – request id, config hash, inferred task, requirements, exclusions with reasons, candidate breakdown, chosen deployment, evidence level, overhead. No prompt content.

Inspect: modelsaar explain -m "..." [--tools --image --json-schema], modelsaar decisions, GET /admin/decisions/<id>, or the status page at /admin/ui. Details: docs/routing.md.

Tested support matrix

Legend: F fixture-tested over real HTTP with a controlled fake backend (CI); L executed live against real models (owner's GX10 via Tailscale, 2026-10-11); D documented from primary sources (config keys verified 2026-10-11); NOT RUN needs your hardware/client.

area status
GET /v1/models, POST /v1/chat/completions (non-stream + SSE), POST /v1/embeddings, /healthz, /readyz F
POST /v1/decisions — typed questions answered by a decision model (Ollama /v1/systemone); contract in docs/routing.md F and L: two real decision models answered the decision preview smoke test
Ollama adapter: /api/tags, /api/show, /api/ps, /api/version, OpenAI-compat forwarding, cloud-alias detection F + L (Ollama 0.32.13 on an ASUS GX10, 8 models, 2026-10-11)
Generic OpenAI-compatible adapter (/models, /chat/completions, /embeddings, vLLM /tokenize) F; L for llama.cpp and vLLM discovery, tokenization and chat
Tool round trips, streaming tool deltas, strict schema routing, image routing F
Failover before commitment / termination after commitment F
Admission limits, queue rejection, uncertain occupancy on disconnect F
Probes, fingerprint invalidation (endpoint + identity), embedding contracts (verified identity, output validation), local-only policy F
Privacy before payload operations (no /tokenize/classifier traffic to policy-excluded deployments), continuity (no failover inside tool round trips / pinned sessions), timeout holds, pool memory budgets, probes under gateway admission F (tests/test_hardening_2026_10_11.py)
Open WebUI / OpenClaw / OpenCode V1+V2 / Hermes configuration D for the configuration guides; Open WebUI native tool execution was observed during RC testing. Other clients need their own live checks.
Several real deployments routed by auto (chat → qwen3.6, code/tools → qwen3-coder, vision → qwen3.6, agent → gemma4) L — see docs/verification-report.md
Live evaluation vs fixed/rules/random/oracle baselines (3-deployment subset) L (2026-10-11, pre-hardening evaluator: auto 0.875 vs fixed-strong 0.906, overlapping CIs, 0 capability violations — historical; a rerun with the repaired evaluator is recorded in docs/verification-report.md when complete)
POST /v1/responses (stateless subset) and POST /v1/messages (Anthropic Messages), fail-closed translations onto the chat path — docs/protocols.md F; S: official openai and anthropic Python SDKs against the installed modelsaar serve with simulated models (scripts/protocol_sdk_check.py); L: official SDKs and local real-model requests during the 0.2.0 release checks
Opt-in MP4 frame sampling for vision models, with the actual frame count in the response and decision (guide) Two real MP4 clips with reversed frame order returned the corresponding colors on a GX10 vision model.
Stateful Responses via the opt-in local response store; POST /v1/vote and guardrail ensembles (closed choices); optional OCR layout stage; inline video input; replica scheduling across hosts — docs/protocols.md, docs/pipelines.md, docs/cascades-and-learning.md F; L for the Responses store, a closed-choice vote and two physical replicas. Native vLLM video returned the first and last colors of a short clip. The page segmentation and pinned ONNX layout trials are recorded in the hardware checks.
POST /v1/guardrails, POST /v1/ocr, audio input (audio_in probe), multimodal embedding items — docs/pipelines.md F; L for GLM-OCR recognition and a gemma4:e2b chat identifying a number from a spoken WAV. Two image inputs and two audio inputs also produced distinct vectors on the native Ollama API. The 0.2.0 gateway restricts that path to text. A separate vLLM video embedding check returned a unit-norm 2,048-D vector. The 0.3.0 gateway also passed real image, audio and mixed-batch embedding tests and four Granite Guardian criterion controls across user and assistant turns.
Exact chat-template token counts and served context for vLLM / llama.cpp; Ollama served-context options — docs/routing.md F; L for llama.cpp per-slot context and exact token counts. L for vLLM: discovered 2,048 tokens and matched completion usage on three English and Chinese prompts.
Managed lifecycle (opt-in), llama-swap composition — docs/lifecycle.md F; L for managed Ollama load, protected unload and release. L for llama-swap v279 startup on the first chat and confirmed per-model unload.
Cascades, adaptive learning (both opt-in) — docs/cascades-and-learning.md; LLM judge (separate report) — docs/evaluation.md F; no benefit claim on real traffic

Limitations

What is a limit of the current code, what is a limit of the runtime, and what is only a limit of the evidence so far. These notes apply to 0.3.0 unless an earlier version is named.

Context length. Ollama does not expose its default context for a model that is not loaded, and that default depends on the machine (4k, 32k or 256k by available VRAM). The gateway assumes the smallest (4096) until it has something better: a Modelfile num_ctx, an operator override, backends[].default_context_length, the value /api/ps reports while the model is loaded, or — opt-in — the last such observation (remember_served_context). A served value below a configured one always wins, so a wrong declaration cannot cause silent truncation. vLLM and llama.cpp report their served context directly. doctor names the source for every deployment.

Token counts. Exact, with the runtime's own chat template, on vLLM (/tokenize) and llama.cpp (/apply-template + /tokenize) — on a real llama.cpp server the counts matched prompt_tokens for English and Chinese prompts (hardware checks, 2026-12-05). Media is never counted by a tokenizer: images and video use a fixed allowance. Ollama documents no tokenizer endpoint, so its counts are a conservative estimate (chars/3, one token per wide character, overheads, +5 %). modelsaar probe --which token_estimate compares that estimate with the runtime's own usage.prompt_tokens on fixed synthetic prompts and raises it per deployment when the runtime counted more; it never lowers it.

Memory budgets. A resident model is counted at what the runtime itself reports (Ollama /api/ps: size for unified-memory pools, size_vram for GPU pools), which includes the context allocation that the 0.2.0 weights-file estimate missed. A model that is not resident is counted at the larger of its estimate and its last observation and is never loaded to be measured; resident models the gateway does not know are counted too. Still a budget, not an out-of-memory guarantee: a never-observed model has only its estimate, an observation is up to one refresh interval old, and nothing reads physical memory (docs/routing.md).

Ollama request fields. Only what Ollama documents, or what was measured on a named version, is forwarded. Refused with a reason rather than altered: tool_choice required/named, logit_bias, n > 1, output audio, remote image URLs. logprobs/top_logprobs are forwarded to Ollama ≥ 0.40.16, where they were measured to work, and refused on older or unknown versions; max_completion_tokens is sent under the documented name max_tokens; neutral values such as n: 1 no longer cause a refusal. For a field Ollama cannot serve, configure a deployment on a runtime that documents it — the gateway does not substitute one silently (table). On llama.cpp, required and named tools and a single-token bias were verified on real requests. Development builds also support multiple choices via backends[].max_chat_choices; two alternatives completed in streaming and non-streaming mode.

Evidence for the 0.2 features. Per feature, not blanket (docs/roadmap-matrix.md). Run on real models on the owner's hardware (2026-12-05, small synthetic inputs, protocol behaviour only): Responses and Messages, stored Responses, a closed-choice vote, a cascade escalation, a feedback policy build, activation and rollback, a judge pass, a small calibration run with isolated code tasks, OCR recognition with a real GLM-OCR model, managed load / leased unload on a real Ollama, llama-swap per-model unload, exact llama.cpp token counts, tool_choice required/named and logit_bias on a real llama.cpp deployment, and least-loaded routing across two physical hosts. On the GX10, a real vLLM deployment identified the first and last colours of a synthetic video. A second deployment returned a 2,048-dimensional embedding for that clip. An external layout detector and GLM-OCR read all four lines of a synthetic two-column page. Granite Guardian passed four user and assistant scoring controls. These checks cover the specified models and inputs. Representative-document accuracy, retrieval quality and performance on user traffic remain unmeasured. Video and embeddings · Layout and recognition.

Code evaluation. The harness executes model-written code inside bubblewrap, Docker or the opt-in macOS sandbox-exec backend. It reports code tasks as skipped when no verified isolation backend is available. In 0.3.0, modelsaar sandbox check checks the current host and prints the activation command when available. Mac isolation test.

Quality numbers. Catalogue priors are hypotheses. modelsaar eval --mode live --save-measurements replaces them with measurements on your hardware, per deployment fingerprint. modelsaar measurements shows, per deployment and task, whether routing is using a measurement (and on how many samples), a prior, or nothing.

Features added in 0.3.0. Image and audio embeddings through Ollama's native API, automatic eviction of idle models, a Conversations API, free-text ensembles (POST /v1/ensemble), a built-in page segmentation for the OCR layout stage (blocks and reading order on clean pages), an optional pinned ONNX detector for labelled OCR regions, explicit frame sampling for inline video, admin-only model downloads from a per-backend allowlist, and cluster placement and recoverable jobs. Fixture-tested; the roadmap matrix says which of them the owner has also run on real models.

Also available in 0.3.0, off by default: hosted tools on the Responses API — a catalogue the operator declares (document search over registered text, fixed HTTP calls on allow-listed hosts, tools of MCP servers on loopback addresses) with per-key allowlists, hard limits and an audit. Live checks cover a real model using all three tool types and a streamed file search through the OpenAI SDK.

Not built, and not planned as such: a code interpreter, a shell, computer use, image generation and open web search. docs/roadmap-expanded.md records what each expanded-roadmap item delivered and what it left out.

Fixed by design (the trust model, not a to-do): the gateway never fetches remote media, never runs model-written code on the host, never executes arbitrary commands, never substitutes a backend silently, never loads, evicts or downloads a model unless the operator has switched that on, and never connects anywhere on a model's request except to a tool endpoint the operator declared for that key.

Documentation

Creator

Created by Gopala Subramanium. An independent open-source project. Say thanks if ModelSaar has been useful to you.

Licence

Apache-2.0 for the gateway code (see LICENSE, NOTICE). Model weights are licensed by their publishers; ModelSaar neither bundles weights nor accepts any model terms on your behalf.

Metadata

Release files for modelsaar 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modelsaar 0.3.0
File Size Uploaded Provenance Actions
modelsaar-0.3.0.tar.gz 447.5 kB With provenance Details for modelsaar-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for modelsaar 0.3.0
File Interpreter ABI Platform Actions
modelsaar-0.3.0-py3-none-any.whl Python 3 none any Details for modelsaar-0.3.0-py3-none-any.whl

Total release size: 776.0 kB

Release files / modelsaar-0.3.0.tar.gz

Download URL modelsaar-0.3.0.tar.gz
Size 447.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9be4e067badf48a3fe1b5ca443c965eb40f535281a3bf13a8f8276cd959765cc
BLAKE2b-256 checksum
How to use checksums
f36bdb4d0c19f86847ff001e03f2ef827232fd534477aa81a4027b36fc925ccb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / modelsaar-0.3.0-py3-none-any.whl

Download URL modelsaar-0.3.0-py3-none-any.whl
Size 328.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29080fbc4ad2553043e6cce445fc5abe41ba8c737ba5dac42664e35baa457f69
BLAKE2b-256 checksum
How to use checksums
071d8a57d57c46e1b598a8c01aba1658749d9ef8269e1ed3ed939cf785168381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for modelsaar 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for modelsaar-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page