Choose a model for the task. Keep it for the session.
jev-router is a self-hosted model router for coding agents and OpenAI-compatible clients. It uses TypeSafe’s Jev to assess a new task, then applies your YAML rules to choose a model and reasoning effort from your upstream’s model pool.
The default auto entrypoint binds each session to one model, provider, and set
of limits. It does not switch models halfway through a tool loop—or silently
move a session to a cheaper model when quota gets tight.
Get started · Documentation · Pi integration · Configuration
- One entrypoint for different tasks. Let a policy choose between fast and stronger models rather than choosing manually for every new session.
- Stable coding sessions. Resolve the model before the client sizes its history. Context overflow and provider failures are explicit errors, not reasons to change the binding.
- Rules you can inspect. Providers, models, questions, routes, client floors, and effort limits live in YAML. Decisions can be replayed from their logs.
- Quota-aware admission. Optional quota sources can steer new work within configured quality lanes, in whichever direction relieves the busy subscription: to a model measured as equally good on another provider, or to a cheaper one on the same provider. Missing or stale telemetry contributes no pressure.
- Your existing upstream. The router forwards to an OpenAI-compatible API or proxy and preserves streamed response bytes. It does not host models.
Client / coding agent
│
├── resolve a fresh session ──► jev-router ──► Jev assessment
│ │ + YAML policy
│◄── model, effort, limits ────────┘
│
└── execute with binding ────► jev-router ──► your upstream
same model for the session
Status: early-stage software (0.1.0). Strict auto and fixed effort are the
shipped path. Adaptive effort is experimental and off by default. The repository
contains deployment-specific model names and evaluation evidence, not a promise
of quality equivalence or cost savings for your own pool.
You need Python 3.12+, uv,
and an upstream that serves an OpenAI-compatible Chat Completions API.
The HTTP walkthrough also uses curl and jq.
git clone https://github.com/hyspacex/jev-router.git
cd jev-router
uv sync --lockedStart with the single-model demo. It needs no Jev key and makes no external classification calls; generating a reply still uses your upstream’s quota. This proves the session contract works, not that routing improves quality.
cp examples/quickstart.yaml quickstart.local.yamlEdit quickstart.local.yaml: set models.demo.upstream_id to a model ID your
upstream serves, and check its context/output limits. The demo advertises neither
tools nor vision. Do not advertise capabilities your deployment has not tested.
In the terminal that will run the server:
export JEV_ROUTER_UPSTREAM="http://127.0.0.1:8317" # your upstream, without /v1
export JEV_ROUTER_ADMIN_TOKEN="$(uv run python -c 'import secrets; print(secrets.token_urlsafe(32))')"
uv run jev-router -c quickstart.local.yaml check-config
uv run jev-router -c quickstart.local.yaml serveKeep the control token private. In a second terminal, set
JEV_ROUTER_ADMIN_TOKEN to the same value and set UPSTREAM_API_KEY to your
upstream’s credential. These are different credentials: the first authorizes
router sessions; the second is forwarded to the model API. The CLI reads the
process environment; it does not automatically load a .env file.
A strict alias is not a drop-in model: "auto" request. Resolve it first:
export SESSION_ID="demo-$(uv run python -c 'import uuid; print(uuid.uuid4())')"
BINDING=$(curl --fail-with-body -sS http://127.0.0.1:8318/router/resolve \
-H "X-Router-Admin-Token: $JEV_ROUTER_ADMIN_TOKEN" \
-H 'Content-Type: application/json' \
-d "$(jq -n --arg id "$SESSION_ID" '{
schema_version: "1", intent: "new", session_id: $id,
request_id: "resolve-1", alias: "auto", client: "quickstart",
client_contract: {
dynamic_metadata: true, protocols: ["openai-chat"],
fresh_execution_context: true
},
request: {messages: [{role: "user", content: "Say hello in one sentence."}]},
limits: {max_output_tokens: 256}
}')")
printf '%s\n' "$BINDING" | jq .A successful response has state: "prepared", a binding_revision, and an
execution object with the selected model and limits. If the command fails,
fix the reported error before continuing.
curl --fail-with-body -sS http://127.0.0.1:8318/v1/chat/completions \
-H "Authorization: Bearer $UPSTREAM_API_KEY" \
-H "X-Router-Admin-Token: $JEV_ROUTER_ADMIN_TOKEN" \
-H "X-Router-Session: $SESSION_ID" \
-H "X-Router-Binding: $(printf '%s' "$BINDING" | jq -r .binding_revision)" \
-H 'X-Router-Request-Id: execution-1' \
-H 'Content-Type: application/json' \
-d "$(jq -n --arg model "$(printf '%s' "$BINDING" | jq -r .execution.wire_model)" '{
model: $model, max_tokens: 256,
messages: [{role: "user", content: "Say hello in one sentence."}]
}')"You should receive your upstream’s Chat Completions response. Use a new execution request ID for each subsequent request; resending a completed ID never calls the provider again. Start a new session for independent work.
uv run jev-router -c quickstart.local.yaml sessions list
uv run jev-router -c quickstart.local.yaml decisions -n 5
uv run jev-router -c quickstart.local.yaml sessions close "$SESSION_ID"See troubleshooting if admission works but execution fails.
The demo has only one model. For Jev-based selection:
- Copy
router.yamlto your own configuration. Its model IDs and effort suffixes describe a particular proxy; they are not universal API IDs. - Configure your providers, model capabilities, routes, and alias permissions. Review the quality-lane evidence before using or replacing its model pairs.
- Set
TYPESAFE_API_KEYto your TypeSafe API key. - Validate with
jev-router -c <your-config> check-config, then serve that file.
Jev receives a bounded state containing request excerpts and computed facts—not
just anonymous counts. If Jev fails, strict admission uses the alias’s explicit
admission_fallback, or refuses with NO_SAFE_ADMISSION. It never revisits an
existing binding when the classifier recovers.
Setup and configuration choices · How the policy selects a model · Model admission evidence
| Client | Path |
|---|---|
| Pi | The Pi extension resolves fresh work and uses the negotiated metadata. Start /new, then select jev-router/auto. |
| Your own client | Implement resolve and managed execution; the HTTP example above shows the minimum flow. |
| Ordinary chat client | Define a legacy alias if the client cannot resolve sessions. It has different pin and fallback semantics. |
| Codex | The experimental adapter is for a separately configured deployment, not the default onboarding path. |
The shipped config exposes strict auto. It also keeps the retired
auto-conserve, which routes as auto, only for sessions bound under it.
Older auto-fast, auto-code, and auto-session examples require custom
configurations.
- Operations: the dashboard at
/dashboardon the router's own address, with an Overview (quota, router overhead against upstream latency, routing quality), a searchable Sessions list, a page per session that explains each user turn's route and effort, and a Rules view that previews a router.yaml edit against recent admissions before applying it. Also feedback, storage and privacy, and retention. - Deployment: service setup, upgrades, backup, and rollback.
- API and CLI reference: endpoints, headers, environment variables, and commands.
- Configuration reference: extend the pool and policy through YAML; use Python only for new builders, deciders, or quota sources.
- Evaluation guide: distinguish offline replay, live model results, and simulated quota behavior.
Run the offline test suite without spending provider quota:
uv run pytest -q
uv run jev-router check-config- Run one service process per SQLite database. Strict execution claims are in memory, not coordinated across processes.
- A strict session does not fail over to another model on 429, timeout, or context overflow. The client must handle the error and decide what to do next.
- Keep the router on loopback unless you have authenticated ingress and HTTPS or a trusted encrypted tunnel. Upstream authentication alone does not protect Jev quota.
settings.log_stateis on by default, so the database keeps message text: session titles, each user turn's prompt, the state Jev was shown, and a short summary of each turn's tool calls. All of it is scrubbed first (API keys and tokens, private keys,KEY=valuesecrets, image data and long encoded blobs) and capped atturn_text_max_chars. The scrubber is a filter, not a guarantee; setlog_state: falseto store no text. API keys and theAuthorizationheader are never stored. Request excerpts go to Jev when classification is on. This is a single-owner tool, not a multi-tenant authorization system.- Live evaluations and model replies spend quota. Existing benchmarks do not establish savings or equivalent quality for another deployment.
Known issues · Full documentation
MIT.