Pi Jev Router

September 20, 2026 · View on GitHub

Select jev-router in Pi's /model picker. Jev answers suitable structured decisions; everything else streams through a separately selected backup model using Pi's existing login, tools, and conversation context. Selecting another model bypasses the router entirely.

Start

Requires Node 22.19+ and Pi 0.84.4 or compatible provider APIs.

cd ~/Documents/code/pi-jev-router
npm start

Then:

  1. Open /model and select jev-router (provider Jev Router).
  2. Run /jev-backup to choose an authenticated backup model. You can also run /jev-backup openai-codex/gpt-5.5.
  3. Send a prompt. The status bar reports whether Jev answered or the backup is handling it.

The model selected when the session starts becomes the initial backup. Selecting the router saves the backup in the current session; /jev-backup changes it without switching away from the router. Resumed sessions restore their backup. For a fixed backup across new sessions, export JEV_BACKUP_MODEL=provider/model before starting Pi. An invalid explicit backup produces an actionable error instead of silently choosing another model.

To load this model from any project, install the local extension once:

pi install /Users/marcolodico/Documents/code/pi-jev-router

Then restart Pi or use /reload. If /scoped-models limits your picker, include jev-router/jev-router in that selection. Ordinary pi launches will discover the installed extension. You can also load it explicitly with pi -e /Users/marcolodico/Documents/code/pi-jev-router/extensions/jev.ts.

Direct startup with an explicit backup:

JEV_BACKUP_MODEL=openai-codex/gpt-5.5 pi --model jev-router/jev-router --thinking high

Jev access

For OpenRouter, create a key in OpenRouter settings and enter it privately in your local zsh terminal:

read -rs 'OPENROUTER_API_KEY?OpenRouter key: '; echo
export OPENROUTER_API_KEY
export JEV_PROVIDER=openrouter
npm run check:live
pi

The hidden prompt keeps the key out of terminal output and shell command history. Never paste keys into chat or commit them. Revoke keys that have been shared. .env files are ignored by Git but not automatically loaded.

check:live makes one small billable Jev request using synthetic text and prints only the route, model and elapsed time. OpenRouter uses its alpha Decisions API at https://openrouter.ai/api/alpha/decisions with typesafe/jev-1.13, not chat completions.

Alternatively, export JEV_PROVIDER=typesafe and JEV_API_KEY or TYPESAFE_API_KEY for direct TypeSafe access. Only the selected provider's key is used. Missing keys and service failures fall back to the configured backup. The virtual router itself needs no additional Pi login; its internal placeholder credential never leaves the process.

No official local Jev model weights or supported self-host installation were found. The extension runs locally; Jev inference is hosted.

Routing behavior

The selected router evaluates a plain-text user request with two independent Jev questions in one call: is a direct decision sufficient, and what is the yes/no answer? Both routing confidence and answer probability must clear the configured threshold.

  • Does this message express urgency: "Production is down. Help immediately."? can receive a direct yes/no answer.
  • Fix the authentication bug and run the tests goes to the backup.
  • Can you refactor this? requests an action, so it should go to the backup.
  • /jev-choice {"choices":["bug","billing","other"],"text":"Charged twice"} explicitly classifies into supplied labels. An uncertain result submits the classification request to the selected Pi model.

Normal direct answers are native assistant messages, visible and persisted by Pi. Fallback streams preserve the backup's model identity, tool calls, reasoning and usage metadata. The model picker stays on jev-router. Once a turn escalates, its tool loop and steering stay with the backup until the next agent turn. Images and tool continuations bypass Jev. Slash commands retain native Pi behavior; expanded skill/template prompts reach the provider as ordinary context.

Only the latest user prompt goes to Jev, not the full session or files on disk. Requests needing prior context should escalate. The backup receives the full Pi transcript, system messages and tool declarations. Jev is not a coding model: most coding work necessarily escalates.

Controls

CommandPurpose
/modeljev-routerActivate routing
/model → another modelUse that model normally
/jev-backup [provider/model]Choose and save a backup in this session
/jev statusConnection, selection, backup and routing counts
/jev on / /jev offEnable Jev decisions or delegate directly to backup
/jev cancelCancel active router requests; normal Pi cancellation also works
/jev-choice <JSON>Classify into 2–32 unique labels
VariableDefault
OPENROUTER_API_KEYUnset
JEV_API_KEY / TYPESAFE_API_KEYUnset
JEV_PROVIDERTypeSafe if its key exists, otherwise OpenRouter if its key exists
JEV_MODELtypesafe/jev-1.13 on OpenRouter; jev-latest on TypeSafe
JEV_BACKUP_MODELSaved session backup or the model selected at startup
JEV_THRESHOLD0.95 (> 0.5 and <= 1)
JEV_TIMEOUT_MS5000 (100–60000)

The router advertises a conservative 32K context window and 4096 output-token budget. Choose a backup supporting at least that context. Pi's thinking setting is forwarded to the backup. Backup usage passes through; Jev routing tokens/cost are not yet included in Pi's usage totals. The threshold is an unvalidated starting policy, not a 95% accuracy guarantee. Test against real requests before relying on automatic decisions.

Validation

npm test
npm run demo

The demo uses canned responses and makes no network calls. Tests cover request contracts, provider/credential separation, uncertainty, errors, cancellation, model registration, session backup restoration, native stream events and tool-call forwarding. Real Pi registry and streaming smoke checks use mocked inference. Live model quality, latency and billing still require API access and evaluation.

References: TypeSafe API, confidence, OpenRouter Jev, OpenRouter example, and the custom-provider documentation shipped with Pi 0.84.4.