9router-pi

Dynamic 9router model discovery for Pi Coding Agent

Packages

Package details

extension

Install 9router-pi from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:9router-pi
Package
9router-pi
Version
0.2.0
Published
Sep 28, 2026
Downloads
191/mo · 15/wk
Author
luong.nguyen
License
MIT
Types
extension
Size
68.7 KB
Dependencies
0 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

9router-pi

Use models exposed by a local 9router OpenAI-compatible gateway in Pi Coding Agent. The extension discovers the gateway's current model list from /v1/models, including model limits, vision support, and reasoning capability.

What it provides

  • Pi provider: 9router
  • Dynamic discovery at startup
  • /9router-pi refresh to fetch the latest catalog without restarting Pi
  • /9router-pi status and /9router-pi help
  • Static models.json entries remain usable when startup discovery is unavailable or PI_OFFLINE is set

Prerequisites

  1. A 9router instance running at http://localhost:20128/v1 (or another configured URL).
  2. Pi API-key configuration for provider 9router.

The discovery endpoint is currently queried without authentication. The API key is used for model requests through Pi.

Configuration

Add the provider credentials to ~/.pi/agent/models.json:

{
  "providers": {
    "9router": {
      "baseUrl": "http://localhost:20128/v1",
      "api": "openai-completions",
      "apiKey": "$NINE_ROUTER_API_KEY"
    }
  }
}

Pi also supports a literal apiKey. Do not commit real keys to this repository.

Optional environment variables:

  • PI_9ROUTER_BASE_URL — overrides the models.json gateway URL and default.
  • NINE_ROUTER_API_KEY — supplies the request key and overrides the models.json key when set.
  • PI_9ROUTER_FREE_ONLY — when set (default: true), only models marked as free by the 9router gateway are exposed. Set to 0 or false to include paid models as well.

Install from this repository

From the repository root:

pi -e ./extensions/9router-pi

Or install it persistently:

pi install -l ./extensions/9router-pi

Then run /reload in Pi (or restart it).

Usage

List discovered models:

pi --list-models 9router

Select a model:

pi --provider 9router --model openrouter/stealth/ox-alpha

Refresh after changing the models enabled by 9router:

/9router-pi refresh

Use /9router-pi status to see the discovery count and last error, if any.

In the TUI, bare /9router-pi opens a read-only menu with provider status, non-secret configuration-source presence, registered model count and registry-availability count, navigation/help, and Close. The panel never refreshes the catalog, tests the gateway, logs in, selects a model, or edits environment/model-file configuration; API keys, URLs, stderr, and user emails are not displayed. Escape or Close exits the panel. Detail views show one short display segment per page (long records continue on the next page without losing text); use Previous/Next to navigate and Back to return to the sections. Non-TUI bare /9router-pi and every explicit subcommand keep their existing behavior.

Development

cd extensions/9router-pi
npm install
npm test

The extension uses Pi's openai-completions API adapter and registers models returned by the gateway. The repository intentionally contains no API keys.

License

MIT — same as pi-extensions.