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

pi-model-failover

v1.0.0

Published

Pi extension that provides failover to an alternative provider/model.

Readme

pi-model-failover

Auto-switches to a preconfigured failover model when the primary model fails with a transient or connection error. Inspired by the "AI resilience" pattern in OpenAI-failover setups and operational runbooks for unreliable upstream APIs.

Features

Context replay — On model failover, captures the most recent user message from the session and re-queues it as a followUp after the swap. The failed turn is not lost, and prior assistant context upstream of the switch is preserved.

Modeled on the primary's failure — Inspects the last assistant message's errorMessage for shape and only switches when it matches a configured pattern. A successful primary never triggers a failover.

Reason surfacing — Distinguishes no target registered (model not in models.json), no API key for failover (setModel refused), and no prior user message to replay. Each gets its own level (error/error/warning) so they show up differently in the UI.

Two pattern sets —

  • transient (default) — delegates to pi-ai's isRetryableAssistantError: connection, 5xx, 429, timeout, fetch failed, etc.
  • connection — narrow /connection error/i regex for tunnels and proxies that bubble up as plain strings. Note: transient deliberately does not switch on hard quota/billing errors (insufficient_quota, quota exceeded, out of budget, billing, Monthly usage limit reached, available balance, OpenCode GoUsageLimitError / FreeUsageLimitError). Those signal the user needs to top up, not that the network is flaky, and silently falling back would hide the real problem.

Installation

Install from npm:

pi install npm:pi-model-failover

Install into the current project only:

pi install npm:pi-model-failover -l

Or install from GitHub:

pi install git:github.com/eiei114/pi-model-fallback

Try it without permanently installing:

pi -e npm:pi-model-failover

Configuration

Copy model-failover.example.json to: <cwd>/.pi/model-failover.json (project) or ~/.pi/agent/model-failover.json (global):

{
  "failover": { "provider": "providerID", "model": "modelID" },
  "patterns": "transient"
}
  • failover.provider / failover.model — required. Must resolve in your models.json or the failover is skipped with an error.
  • patterns — "transient" (default) or "connection".

Usage

Activates automatically. No slash command; tuning is by config file.

Notification levels in Pi's UI:

  • info — config active on session start (model-failover: → provider/modelID)
  • warning — failover engaged, or switched model with no prior user message to replay
  • error — failover model not found in registry, or setModel refused the switch (e.g. missing API key)

Links

  • npm: https://www.npmjs.com/package/pi-model-failover
  • GitHub: https://github.com/eiei114/pi-model-failover

License

MIT