pi-anyrouter-dev0.1.7
AnyRouter (anyrouter.dev) provider for the pi coding agent - a thin layer over pi's built-in OpenAI-compatible client with a dynamically fetched model catalog
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-anyrouter-dev
AnyRouter provider for the pi coding agent. Adds AnyRouter (anyrouter.dev) as a provider using pi's built-in OpenAI-compatible client with a dynamically fetched model catalog.
Install
# Required: registers the extension with pi so the provider is available
pi install npm:pi-anyrouter-dev
Note:
npm install pi-anyrouter-devalone only adds the package to your project. You must runpi install npm:pi-anyrouter-dev(or use--extension) to register the provider with pi.
Quick Start
# Set your AnyRouter API key
export ANYROUTER_DEV_API_KEY=sk-...
# Use the anyrouter-dev provider explicitly with a specific model
pi --provider anyrouter-dev --model gpt-4o -p "Hello, world!"
What It Does
This extension registers anyrouter-dev as a provider in pi. It:
- Uses pi's native OpenAI-compatible client for provider requests — no custom HTTP/SSE code for chat/completions
- Fetches the live model catalog from AnyRouter at startup (online) or restores persisted models (offline)
- Maps AnyRouter models to pi's model format — pricing, context, reasoning, vision
- Persists the catalog so it works offline and restores instantly on next start
- Handles API keys via
ANYROUTER_DEV_API_KEY(owned by this package) with fallback toANYROUTER_API_KEY
Configuration
API Key
| Variable | Priority | Notes |
|---|---|---|
ANYROUTER_DEV_API_KEY |
1st (owned) | This package's own variable |
ANYROUTER_API_KEY |
2nd (fallback) | AnyRouter's documented name |
Keys can also be stored in pi's credential store under provider anyrouter-dev.
Model Selection
The extension fetches the full model catalog from AnyRouter dynamically. To use a specific model, pass it explicitly:
pi --provider anyrouter-dev --model gpt-4o -p "Your prompt"
Or select it in pi's model picker after the catalog loads. The extension does not read static model lists from models.json — the catalog is always fetched from AnyRouter (or restored from pi's persisted store offline).
How It Works
- Startup (online): Extension loads, resolves API key, fetches live catalog from AnyRouter
- Startup (offline): Restores persisted models from pi's store without contacting AnyRouter
- Mapping:
catalog.tsconverts AnyRouter models → pi model configs (cost, context, reasoning, compat) - Registration: Provider registered with pi using
api: "openai-completions" - Refresh:
refreshModelsre-fetches the catalog when pi requests a refresh (e.g., model picker) - Persist: Catalog saved to pi's store; restored on next start (works offline)
Architecture
src/index.ts— Extension entry point, provider registration, refresh logicsrc/catalog.ts— Model mapping, cost parsing, reasoning/compat computationsrc/fetch-catalog.ts— HTTP fetch with auth, timeout, error handling (custom HTTP for catalog)src/api-key.ts— Key resolution priority, credential templatessrc/provider-info.ts— Provider constants (id, name, base URL)
Requirements
- pi ≥ 1.3.0
- Node.js ≥ 22.19
- Bun ≥ 1.2
- AnyRouter API key (free at anyrouter.dev)
License
MIT