cortiq-pi-router
Automatically select models in Pi: inexpensive models for simple tasks, stronger models for complex work. Powered by AllaiGate.
Package details
Install cortiq-pi-router from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:cortiq-pi-router- Package
cortiq-pi-router- Version
0.1.1- Published
- Sep 9, 2026
- Downloads
- 302/mo · 302/wk
- Author
- infosave
- License
- MIT
- Types
- extension
- Size
- 75.4 KB
- Dependencies
- 0 dependencies · 0 peers
Pi manifest JSON
{
"extensions": [
"./dist/index.js"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
Automatic model selection for Pi
This extension automatically chooses a model for your tasks in Pi. Your rules can send routine requests to a lower-cost model and difficult coding tasks to a stronger one.
AllaiGate identifies the task type and estimates its complexity. The extension applies your rules to select among the models you have connected to Pi. You need an AllaiGate API key and a working model provider.
Example rules — you choose the models:
| Task and estimate | Your choice |
|---|---|
| Routine request, low estimated complexity | Your lower-cost model |
| Coding task, high estimated complexity | Your stronger coding model |
In a live test on 9 September 2026, the extension switched from DeepSeek V4 Pro to DeepSeek V4 Flash, and Pi completed one tool call and returned CORTIQ_LIVE_OK.
Install
Tested host: @earendil-works/pi-coding-agent 0.85.1. Requires Node.js 22.19.0+. Other Pi versions have not been verified. Install the published npm package, or use a Git/local checkout.
First configure your providers in Pi and verify that the intended models work with your account. Use pi --list-models to inspect available identifiers. Obtain a separate API key from AllaiGate.
pi install npm:cortiq-pi-router@0.1.1
As a Git alternative, use pi install git:github.com/infosave2007/cortiq-pi-router.
For a project-scoped installation, add -l; Pi may request trust for that project. Alternatively, install a local checkout:
git clone https://github.com/infosave2007/cortiq-pi-router.git
pi install /absolute/path/to/cortiq-pi-router
The package declares pi.extensions: ["./dist/index.js"]. Compiled JavaScript is committed, so no manual build or unpublished dependency is required. Pi manages package installation. Restart Pi after installation.
Set the key in the environment that starts Pi:
export CORTIQ_ROUTER_KEY='your-api-key'
pi
Keep real keys outside repository files. Provider credentials are configured separately in Pi.
Configure
Create .pi/cortiq-router.json in your Pi working directory, using cortiq-router.example.json as a starting point. CORTIQ_ROUTER_CONFIG can select another JSON file; relative paths resolve against the Pi working directory. The extension does not edit Pi's settings. Config is loaded for each user run and checked again before selecting a model; changes apply to subsequent runs without reloading the extension.
Replace the example models with exact identifiers from your configured Pi model catalog:
{
"globalTiers": {
"low": ["openai/gpt-4.1-mini"],
"medium": ["openai/gpt-4.1"],
"high": ["openai/gpt-4.1"]
},
"taskRules": {},
"defaultModel": "openai/gpt-4.1-mini"
}
Identifiers use provider/model. Only the first slash separates the provider: openrouter/anthropic/claude-sonnet-4.5 retains the complete model ID. Candidates must exist in Pi's available model registry, have configured authentication, and belong to the active scoped model list when one is set. Text support and current image attachments are checked. Registered/authenticated does not guarantee provider health, valid credentials, quota, or account access.
| Setting | Default / meaning |
|---|---|
enabled |
true; explicit false disables future routing |
apiKeyEnv |
CORTIQ_ROUTER_KEY |
routerUrl |
https://router.allaigate.com; /v1/route is appended |
taxonomyId |
data-assistant |
timeoutMs |
15000; integer 1–120000 ms |
maxChars |
12000; integer 1–1000000 UTF-16 code units |
routerProfile |
balanced, cost-saver, or quality-first |
complexityBands |
Omitted: use the router tier. Optional { "low": 0.35, "medium": 0.65 } overrides score thresholds |
globalTiers |
Empty; arrays for low, medium, high |
taskRules |
Empty; task label → model string/array or tier object with low, medium, high, any (models is an alias for any) |
defaultModel |
Unset; last candidate and classifier-error fallback |
echoRouting |
false; optional selected-model notification or stderr message |
Bands require 0 ≤ low < medium ≤ 1, with inclusive upper bounds. Use task labels from your configured taxonomy. Priority is the task's tier-specific models first. At high complexity, global high models precede task any models; at low/medium, task any comes before global models. defaultModel is last. Unavailable candidates are skipped.
Missing keys, timeout, HTTP/auth errors, redirects, or invalid classifier output use an eligible defaultModel, otherwise preserve the current Pi model. An absent default config file uses empty routing defaults. An explicitly selected missing file, unknown setting, or malformed config reports a concise error and leaves Pi in control.
Behavior, privacy, and limits
The extension uses Pi’s extension API. Pi handles provider authentication, generation, tools, and retries. No gateway is required.
The input hook captures interactive/RPC user text before skill/template expansion; extension-injected input is excluded. before_agent_start classifies that text once, capped at maxChars, and calls Pi's native setModel. Tool loops do not trigger repeated classification. Steering/follow-up messages queued inside an existing loop keep that loop's model. Expanded skill text, system instructions, history, and image bytes are not added to the classifier request.
The captured user text leaves your computer and is sent to the configured router. It may contain confidential information. No keys, full prompts, or provider credentials are logged. Remote endpoints must use HTTPS. HTTP is accepted only for localhost, 127.0.0.1, or [::1] fixtures. TLS verification remains enabled, and redirects are rejected.
The selected model becomes the current session model, is recorded in the session transcript, and remains selected until later routing or a manual change. Pi's global default provider/model are unchanged. Disabling or removing the extension does not restore the model that was selected earlier.
This is selection before a user agent run, not DSH's per-LLM-call delegation or failover before the first streaming chunk. Provider errors remain Pi's responsibility; the extension does not retry generation across its candidate list. Classification is bounded and honors the host signal where available; new input, manual selection, and session shutdown invalidate pending classification. Pending model changes are serialized and a later user choice is reconciled if an older setter completes late. Pi's asynchronous model setter has no AbortSignal and cannot be interrupted mid-flight.
Context-window suitability, historic attachments, provider reliability, and paid-provider behavior are not exhaustively checked. Other extensions can affect model selection and input ordering. Paid AllaiGate/provider end-to-end calls are available only through the separate opt-in live script.
Disable, uninstall, develop
Set "enabled": false in the dedicated JSON file to stop future routing. For the npm installation above, run pi remove npm:cortiq-pi-router@0.1.1. To uninstall a Git installation:
pi remove git:github.com/infosave2007/cortiq-pi-router
For a local installation, remove the same local source path with pi remove /absolute/path/to/cortiq-pi-router. Use -l for project-scoped removal. Restart Pi after removing the package. Your dedicated config and key environment variable can be removed separately.
npm ci
npm run check
check compiles against the published Pi SDK and runs fixture tests without paid generation. npm run compile regenerates the committed dist/ files.
node scripts/package-smoke.mjs --native
node scripts/native-smoke.mjs
npm pack --dry-run
The packaging smoke verifies the archive and offline tarball/Git installs, then runs the installed package in Pi. The native smoke uses Pi's actual Git/local installer, extension loader, prompt pipeline, and removal command with isolated settings and localhost classifier/provider fixtures. It verifies the selected generation model and unchanged global defaults. No paid services are called. CI runs these checks and verifies committed build freshness.
Upstream: Pi package installation, extension API, custom models.
MIT © 2026 Cortiq Team.