pi-model-fallback
v0.3.3
Published
Pi extension that switches to a fallback model after provider failures such as 429 rate limits.
Maintainers
Readme
pi-model-fallback
Pi extension that switches to a fallback model after provider failures such as 429 rate limits.
What this does
pi-model-fallback watches provider failures and automatically moves Pi to a safer fallback model when a matching rule fires.
Current default:
- source provider:
zai - matching statuses:
429,500,502,503,504 - fallback model:
deepseek/deepseek-v4-flash
When a failure matches, the extension also stores persistent fallback state so future sessions can preselect the fallback model until the cooldown expires.
Install
Install from npm:
pi install npm:pi-model-fallbackInstall into the current project only:
pi install npm:pi-model-fallback -lOr install from GitHub:
pi install git:github.com/eiei114/pi-model-fallbackTry it without permanently installing:
pi -e npm:pi-model-fallbackCommands
/model-fallback:status
/model-fallback:resetstatus: shows whether fallback is enabled, active persistent entries, and current pathsreset: clears persistent fallback state and switches back to the remembered original model when possible
Configuration
The extension exposes the model_fallback_config tool for reading, validating, and saving config JSON.
Default config shape:
{
"version": 1,
"enabled": true,
"rules": [
{
"name": "zai-to-deepseek-flash",
"matchProviders": ["zai"],
"statuses": [429, 500, 502, 503, 504],
"fallback": {
"provider": "deepseek",
"model": "deepseek-v4-flash"
}
}
]
}Rule fields:
matchProviders: match all models from a providermatchModels: match specificprovider+modelpairsstatuses: optional; defaults to429, 500, 502, 503, 504cooldownMs: optional persistent fallback windowfallback: target model Pi should switch to
State and paths
The extension stores:
- config:
model-fallback/config.json - state:
model-fallback/state.json
If the package is installed project-locally and the current project references it from .pi/settings.json, those files live under the project .pi/ directory. Otherwise they live under the user agent directory.
Behavior notes
- Successful responses do nothing.
- Matching failures from
after_provider_responsecan trigger fallback immediately. - Assistant error messages parsed at
turn_endcan also persist fallback state for SDK/provider failures that do not emit the normal response hook. - The failed request is not automatically replayed.
Development
npm install
npm run ciRun locally in Pi:
pi -e .Links
- npm: https://www.npmjs.com/package/pi-model-fallback
- GitHub: https://github.com/eiei114/pi-model-fallback
- Issues: https://github.com/eiei114/pi-model-fallback/issues
- Usage notes:
docs/usage.md
License
MIT
