Stable contract, upgrading, evidence
Rendered from docs/stable-contract.md at commit 18614e438388. The repository file is authoritative.
Three things an operator needs before depending on a release: what will keep working, what changes on upgrade, and what each claim in these docs is actually based on.
1. The contract
"Stable" means: within a major version these keep their meaning. Fields, endpoints, commands and configuration keys may be added; none of the ones listed is removed, renamed or given a different meaning without a new major version, and every change in behaviour is called out as Behaviour change in the changelog. Clients and scripts should ignore fields they do not know.
Stable
| surface | what is covered |
|---|---|
| Authentication | Authorization: Bearer <key>; API keys for /v1/*, the admin key for /admin/*; a missing or wrong key is 401 before anything else is evaluated; /healthz and /readyz need no key and return only service identity, version and readiness counts |
POST /v1/chat/completions |
the fields documented in routing and protocols, non-streamed and SSE; exactly one data: [DONE]; model is an alias (auto, auto-*, your own) or backend/model |
POST /v1/embeddings, GET /v1/models, GET /healthz, GET /readyz |
request and response shapes; /healthz identifies the service (service: modelsaar, version) |
| Response headers | X-ModelSaar-Request-Id on every routed response; X-ModelSaar-Deployment and X-ModelSaar-Profile when a deployment was chosen |
| Request hints | session identity through affinity.session_headers (default X-ModelSaar-Session) or modelsaar.session; modelsaar.profile (quality, balanced, fast); modelsaar.budget, which is validated strictly — a malformed budget is 400. Other keys inside modelsaar are ignored, as in 0.3.x; do not rely on that |
| Errors | the envelope {"error": {"message", "type", "param", "code", "modelsaar"?}}; the meaning of each HTTP status and code below |
| Decision record | the fields in routing § F and the load, budget, timing objects; GET /admin/decisions[/{id}], modelsaar decisions, modelsaar explain |
| Configuration | version: 1 files; every documented key and its default; unknown keys are refused at load, not ignored; modelsaar config validate / migrate |
| CLI | the commands init, discover, serve, status, doctor, test, explain, decisions, keys, config, client-config, probe, uninstall, their documented options, and exit status 0 for success, non-zero for failure |
| Defaults that protect you | loopback bind; key authentication always on; local-only routing unless security.locality_mode says otherwise; no prompt or response logging; no download, model load, eviction, tool execution or remote fetch that the configuration did not opt into; an unknown required capability never qualifies a deployment |
| Routing guarantees | hard requirements are filters, not preferences; nothing is silently truncated, dropped or weakened to make a model fit; a request bound to a deployment (tool round trip, continuation, pinned session, explicit deployment) is not moved; failover only before the response is committed; no fallback to a service you did not configure |
Error codes with a stable meaning on the core endpoints:
| status | code |
meaning |
|---|---|---|
| 400 | invalid_request_error, unsupported_capability, unsupported_semantics, unsupported_routing_hint |
the request is malformed, or asks for something this path cannot honour exactly |
| 401 / 403 | authentication_error / permission_error |
key missing or wrong / not allowed for this key |
| 404 | model_not_found |
neither an alias nor a known deployment |
| 422 | no_eligible_deployment |
no deployment satisfies the request; modelsaar.blockers and remedies say why |
| 429 / 503 | admission_rejected |
queue full / no slot within the queue timeout; nothing was dispatched |
| 503 | wait_budget_exceeded, latency_budget_unmeetable |
the request's own time budget; nothing was dispatched |
| 5xx | upstream_error, upstream_bad_response, upstream_timeout |
the backend failed, answered with something that is not a completion, or timed out; the code tells them apart |
Stable where you turn it on
These are off (or inert) until configured. Their wire formats are documented on their own pages and
follow the same additive rule: Responses and Conversations, Anthropic Messages
(protocols); /v1/decisions; guardrails, OCR, audio and video inputs
(pipelines); /v1/vote, /v1/ensemble, cascades and learning
(cascades and learning); managed lifecycle, eviction and downloads
(lifecycle); hosted tools (hosted tools); cluster jobs and placement
(expanded roadmap); routing.load.mode: prefer and time budgets
(routing).
Not a contract
- The wording of human-readable output: CLI text, log lines,
reasons,why,queue, errormessage. Parse the structured fields. - The numbers in estimates, scores and observed latency, and therefore which deployment a given request lands on when several qualify. The rules are the contract; the outcome depends on your evidence and load.
/admin/ui, the SQLite state file's schema, the Python modules (modelsaar.*is not a library API), the fixture backend (modelsaar.testing),scripts/.- Values labelled as heuristics or priors (
size-heuristic,uncalibrated,prior:*).
2. Upgrading from 0.3.x
No configuration change is needed and none is made for you. Upgrade as before
(installation); your config.yaml, key files and state are kept — CI checks
exactly that on Linux, macOS and Windows by installing 0.3.0, initialising it, and installing the new build
over it (platforms).
What is different after the upgrade, without touching the configuration:
| area | 0.3.x | now |
|---|---|---|
| Routing choice | ranking | unchanged. routing.load.mode defaults to observe: latency is measured and estimates are recorded; no request goes anywhere else |
Decision records, /admin/status, modelsaar status |
— | new load, budget, timing, per-candidate timing; latency.observed |
429 / 503 admission_rejected on chat |
fixed Retry-After: 2 |
same status and code; Retry-After is the estimated wait (1–60 s) and the body adds estimated_wait_ms, queue, tried |
"modelsaar": {"budget": …} on a request |
not a known key | validated and applied; malformed is 400; on POST /v1/cluster/jobs it is 400 budget_not_supported |
CLI when server.host is 0.0.0.0 or :: |
used that address as the destination (fails on Windows) | talks to the gateway over loopback; serve prints and client-config writes the loopback URL. A specific address is used as it is |
Offline probe, live eval: "is a gateway on the configured port?" |
an HTTP request with a 2 s timeout; a refused connection meant "free" | the port is free only if the system lets ModelSaar bind it exclusively; while another socket holds it, a connection that times out or is refused stops the command (override: --allow-concurrent). On Windows these commands no longer stop for a port that is simply closed. On Windows and macOS they may stop for up to a minute after a gateway on that port was stopped (platforms) |
| CLI output on a console that is not UTF-8 | could end with UnicodeEncodeError |
prints ? for characters the console cannot show |
doctor on Windows |
warned that key files are "readable by other users (chmod 600)" | reports where the key files are and warns only when they are outside the user profile |
| A hosted-tools or ensemble deadline on Windows | one that ended during the admission wait could be reported as a 503 queue timeout; after a call was cut at the deadline the next one could still be dispatched and cut at once |
reported as the deadline, and nothing is dispatched in the last clock tick before it (as on Linux and macOS) |
To use the new routing: read modelsaar decisions for would_move entries, then set
routing.load.mode: prefer and, if you want bounded waiting, aliases.<name>.budget
(routing). Restart the gateway.
Rolling back to 0.3.x. Reinstall it (installation). If you added
routing.load or an alias budget, remove them first: 0.3.x refuses configuration keys it does not know.
Nothing else needs undoing — observed latency is kept in memory only and the state file's schema is unchanged.
3. What the evidence covers
Every claim in these docs has one of four kinds of evidence, and they are not interchangeable:
| kind | what it is | what it establishes | what it does not |
|---|---|---|---|
| Fixture | the test suite against the repository's controlled backend over real HTTP, on every push | the gateway's own behaviour: routing rules, limits, errors, accounting, protocol translation | anything about a real runtime, a real model's speed or the quality of its answers |
| Installed entry point | the built wheel or the installer, driven as a user would, against the fixture | packaging, paths, sockets, signals, upgrade, per operating system | the same limits as fixture |
| Live | a dated run on named hardware with real models (verification report, docs/live-runs/) |
that the thing worked there, then, with those versions | other hardware, other versions, typical traffic |
| Not run | a procedure exists; nobody executed it | nothing | — |
For what this release adds:
- Latency- and load-aware selection, budgets: fixture (
tests/test_load_aware_routing.py): what is measured, where requests go, that waiting is bounded, that capability, privacy, affinity, quality and capacity limits hold, for streams and cancelled streams, and for cluster jobs. The latencies in those tests are produced by the fixture on purpose. Whetherpreferimproves response times on your machines is not established by them;observeis the default so that you can see it first. Live runs are listed in the acceptance matrix, including a two-host comparison. - Estimates are computed from recent requests through this gateway and the admission state at one instant. They are not guarantees, not benchmarks, and reset on restart.
- Windows, macOS, Linux: installed entry point plus the full fixture suite on GitHub-hosted runners (platforms). A separate workflow also generates and streams text with real llama.cpp on each operating system.
The acceptance matrix keeps this per feature, including a comparison of the original design with the code as it is.