npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mikhaben/pi-model-router

v0.2.0

Published

Ordered model fallback for pi: a chain you define, advanced automatically when a model hits a provider limit or error, with SQLite failure history and a /model-router command.

Readme

pi-model-router

License: MIT

Ordered model fallback for pi. You define a chain of models; when the one you're on stops working, the router moves to the next and picks the task back up.

It is always loaded but engages only on demand — run /model-router on to arm it. While armed, a settled run that ends in a provider limit or error switches to the next eligible model in your chain and sends Continue.. Failures on models outside the chain are ignored, so sessions on a model you chose deliberately are never redirected. Every failure and switch is recorded in SQLite.

Rate-limited free tiers are the obvious case, but nothing here is free-tier specific: any model pi can reach can sit in the chain, in whatever order you want.

Features

  • Ordered provider/model-id chain, armed with /model-router on or pi --model-router
  • Automatic advance on provider limits and errors, with a resume nudge
  • Daily cooldowns for hard limits, so an exhausted quota is skipped until it resets
  • Per-minute throttles advance without burning a model for the day
  • SQLite history of every failure and switch
  • Footer status line showing the routed model and cooling count
  • Zero runtime dependencies

Install

pi install npm:@mikhaben/pi-model-router

From a local checkout, symlink it into pi's extension directory:

ln -s "$PWD" ~/.pi/agent/extensions/pi-model-router

Configuration

Create ~/.pi/agent/extension-settings/pi-model-router.json with your chain, best choice first:

{
  "chain": [
    "vercel-ai-gateway/poolside/laguna-s-2.1-free",
    "openrouter/poolside/laguna-s-2.1:free",
    "opencode/hy3-free"
  ]
}

Each entry splits at its first /, so model ids may contain more slashes. Confirm an id with pi --list-models before adding it; unknown entries are reported at startup and skipped when routing.

An entry may pin a thinking level by appending ::<level>. The level is applied right after switching to that model; entries without one leave the session level untouched:

{
  "chain": [
    "openrouter/poolside/laguna-s-2.1:free",
    "openai-codex/gpt-5.6-luna::max"
  ]
}

Levels are off, minimal, low, medium, high, xhigh, and max, clamped to what the model supports; an unrecognised one is reported at startup and the model still runs. The separator is doubled because a single colon already belongs to model ids such as laguna-s-2.1:free, which is why …:free::high reads correctly.

A hard limit (quota exhausted, billing, payment required) cools that model until the next UTC midnight. Ordinary errors and per-minute throttles advance to the next model without a cooldown, so a short-lived 429 never costs you a model for the rest of the day.

History lives in ~/.pi/agent/pi-model-router.db, an append-only event log that seeds cooldowns at startup and backs /model-router status.

Commands

| Command | Action | | --- | --- | | /model-router | Show armed/off state and the command list | | /model-router on | Arm routing and switch onto a usable chain entry | | /model-router off | Disarm routing | | /model-router next | Manually advance to the next eligible entry | | /model-router status | Show chain order, current/cooling markers, and today's limit counts | | /model-router config | Show the configured chain with pinned thinking levels |

Launchers can arm routing at session start with pi --model-router, equivalent to /model-router on. Put the flag last on the command line (or write --model-router=true): pi parses unregistered flags before it knows their type, so a prompt written right after the flag is swallowed as its value.

Every listing ends with the paths to the config file and the history database, so you can open them without looking anything up.

While armed, the footer shows router:<model> when the session is on a chain model and router:armed otherwise, with a (n cooling) suffix when cooldowns are active. Arming resets on /reload, /new, /resume, and /fork — run /model-router on again.

Development

npm install
npm run typecheck
npm test
npm run build

Requires Node.js 24 or newer for node:sqlite. TypeScript source is in src/, tests in test/, and the extension entry point is src/index.ts.

License

MIT