@restranger/repi-model-fallback
Automatic model fallback and retry for pi-coding-agent
Package details
Install @restranger/repi-model-fallback from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@restranger/repi-model-fallback- Package
@restranger/repi-model-fallback- Version
0.0.1-1a48fc0- Published
- Nov 3, 2026
- Downloads
- 1,523/mo · 1,523/wk
- Author
- restranger
- License
- MIT
- Types
- extension
- Size
- 53.2 KB
- Dependencies
- 2 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
@restranger/repi-model-fallback
Automatic model fallback and retry for the primary Pi agent. When a model request fails (rate limit, quota exceeded, 403/5xx errors, network failure), this extension automatically switches the active session to the next configured fallback model and transparently resumes execution.
Installation
pi install npm:@restranger/repi-model-fallback
# or from this monorepo
pi --extension ./packages/model-fallback/src/index.ts
How it works
- Pi executes a turn. If the provider fails (e.g. 403 Forbidden, 429 Rate Limit, 500 Server Error), the turn ends with an error.
- Before the session settles,
@restranger/repi-model-fallbackinterceptsagent_before_settle:- Selects the next viable candidate from your
fallbackslist. - Activates the fallback model via
pi.setModel(nextModel). - Omits the failed assistant message via
context_editso the context is clean. - Shows a notification in the UI (
Model "..." failed: ... Falling back to "..."). - Returns
{ continue: true }to immediately prompt the new model.
- Selects the next viable candidate from your
- The fallback model produces the final answer without requiring user intervention.
Configuration
Configurations are loaded with project priority:
$PI_CODING_AGENT_DIR/extensions/repi-model-fallback.json(default~/.pi/agent/extensions/repi-model-fallback.json)<project>/.pi/extensions/repi-model-fallback.jsonor<project>/.repi/model-fallback.json(wins over user config)
{
"version": 1,
"enabled": true,
"fallbacks": [
"gemini-3.8-flash",
"anthropic/claude-3-5-sonnet",
"openai/gpt-4o"
],
"maxRetriesPerTurn": 3,
"notify": true
}
Options
| Field | Description | Default |
|---|---|---|
enabled |
Whether automatic model fallback is active. | true |
fallbacks |
Ordered list of models to try if the current model fails. Exact provider/id or fuzzy model name. |
[] |
maxRetriesPerTurn |
Maximum number of consecutive fallback attempts per user prompt before stopping. | 3 |
notify |
Whether to show an informative UI notification on fallback. | true |
Accepted aliases for compatibility: fallback_models, fallbackModels, max_retries_per_turn.
Slash command & TUI Menu
/fallback— Open the interactive menu to view and manage fallbacks for all agents. It renders the same way as Pi's own pickers (/models,/llama,ctx.ui.select): an inline frame in the editor slot, a→cursor, muted descriptions and a key-hint line, with no full-screen overlay.- Lists the primary agent (
Main Agent) and all declared subagents (Explore,Plan,general-purpose, etc.). - Shows the selected agent's primary model and fallback chain below the list.
- Press
aorEnterto open the model picker, then type to fuzzy-search the registry. - The picker works like
/scoped-models:Entertoggles the highlighted model,Ctrl+Aenables every model in the filtered list,Ctrl+Xclears it,Ctrl+Ptoggles the selected model's provider andAlt+↑/↓reorders the fallback chain. Enabled models are listed first, in chain order, with a#nrank; chain entries that are no longer available stay listed as[unavailable]so they can be removed. - Press
Ctrl+S(orson the agent list) to save. The fallback chain goes to the user config (<agentDir>/extensions/repi-model-fallback.json, normally~/.pi/agent/...) so it follows the user and works in an untrusted workspace; a trusted project that already owns a fallback config is updated in place. Subagent overrides are applied in memory and persisted by@restranger/repi-subagentswhen the workspace is trusted. Unsaved edits are markedunsavedin the subtitle. - Press
qorEscto close; in the pickerEscfirst clears the search, then returns.
- Lists the primary agent (
/fallback status— Print status overview in text mode./fallback list— List configured fallbacks and all available models in the registry./fallback on— Enable fallback for the current session./fallback off— Temporarily disable fallback./fallback reload— Reload configuration files from disk.
Typing /fallback and pressing Tab completes these subcommands; nothing is offered after a
subcommand because the rest of the argument is not a fixed slot.