jev-pi-model-router

pi extension: TypeSafe Jev picks the model for each turn, from pi's own models. No other CLI needed.

Packages

Package details

extension

Install jev-pi-model-router from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:jev-pi-model-router
Package
jev-pi-model-router
Version
0.3.2
Published
Sep 27, 2026
Downloads
143/mo · 143/wk
Author
damian87
License
MIT
Types
extension
Size
22.7 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./extensions/router.js"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

jev-pi-model-router

A pi extension. On every fresh user turn, TypeSafe Jev judges how hard the turn is, what kind of work it is and whether a mistake would be costly. The router then switches pi to the first model in that tier's pool that pi can actually use and that fits the turn (images, context size).

you type ─► Jev (one call, ~$0.0001): difficulty · kind · costly? ─► tier + specialty ─► pool ─► pi.setModel

Pure pi: it calls Jev's API directly and reads pi's own model registry. No other CLI or agent needed. Anything unsure, slow or broken keeps your current model. Routing never blocks a turn.

Companion to jev-pi-orchestrator, which uses Jev to supervise conductor workers. The two are independent.

Install

pi install npm:jev-pi-model-router

Jev key from the console, first match wins: TYPESAFE_API_KEY env, then TYPESAFE_API_KEY= in the nearest .env, then ~/.pi/agent/secrets/typesafe_api_key (chmod 600). Restart pi, then /jev routing on.

Use

/jev                  status and which pools are in use
/jev routing shadow   decide and notify, do not switch (default)
/jev routing on       switch models
/jev routing off

/jev routing on stays on. Only the model-cycle key pins your pick; runtime switches do not. State: ~/.pi/agent/jev-model-router/state.json.

Pools

Tiers are simple, medium, hard; specialties are general, coding, writing, research, vision. Names are pi's provider:model (see pi --list-models). The shipped pools.default.json:

tier models, in order
simple openai-codex:gpt-6-luna, openai-codex:gpt-5.6-luna
medium xai:grok-4.7, xai:grok-4.6
hard openai-codex:gpt-6-sol, then gpt-6-astra (general) or xai:grok-4.6 (coding)

To use your own, copy it to ~/.pi/agent/jev-model-router/pools.json and edit. The same file can override the thresholds (min_confidence, hard_needs_probability, simple_needs_probability, simple_needs_confidence, sticky_context_tokens, ask_chars).

On each turn the router walks the tier's specialty pool, then general, then higher tiers (never lower). It skips any model pi does not list as available, and names skipped entries once. It never picks claude-bridge, anthropic or github-copilot. A context above 32k tokens never switches to a cheaper model, because rebuilding the cache costs more than it saves.

Privacy

Jev reads a copy of the turn with keys, tokens, emails and card-like numbers masked, clipped to 2,500 characters (the opening and, mostly, the end). Nothing else from the session is sent. Risk words (production, migration, billing, auth…) are checked locally on the whole turn and keep it off the cheapest tier.

History

  • 0.3: talks to Jev directly and reads pi's registry. Earlier versions shelled out to a jev CLI that read pools written for a different agent host, with provider names pi does not use (openai:* instead of openai-codex:*) and models pi does not have. Two of three tiers ended in "not available".

Develop

npm test

MIT licensed.