AndreiTelteu/pi-models-refresh

★ 0Forks 0TypeScriptGitHub ↗Compare

README

pi-models-refresh

A pi extension that adds a /models-refresh slash command.

What it does

When you run /models-refresh inside a pi session:

  1. Resolves the current provider. It reads the active model from the session (ctx.model) to get the provider id and its base URL, and pulls the provider's API key from pi's auth via ctx.modelRegistry.
  2. Calls <baseUrl>/models with Authorization: Bearer <apiKey> and reads the catalogue (handles { data: [...] }, { models: [...] }, and bare arrays).
  3. Converts to pi's format. Each entry becomes { id, name, input: ["text"], reasoning: <heuristic> }. The reasoning flag is detected from id/name hints (e.g. *-reasoning, -r1, o1–o4, deepseek-reasoner, …).
  4. Writes ~/.pi/agent/models.json. Only the current provider's models array is replaced; every other provider in the file is preserved, along with the provider's name/api/baseUrl.
  5. Reloads pi. It calls ctx.modelRegistry.refresh(), which re-reads models.json from disk so the refreshed catalogue is available immediately in the running session.

Install

The folder is already registered in ~/.pi/agent/settings.json:

{
  "extensions": ["~/pi-models-refresh"]
}

(Equivalent: drop this folder into ~/.pi/agent/extensions/ — pi auto-discovers a directory with an index.ts.)

Usage

  1. Make sure a model is selected (so the provider/URL/key can be resolved).
  2. Run:
/models-refresh
  1. You'll get a notification with the number of models written. Use /model to pick one of the refreshed models.

Notes & limitations

  • Heuristic metadata. input is always ["text"] and reasoning is a best effort guess from the model id/name. Most /models endpoints (v1/models) only expose id/object/owned_by, so pi can't derive context window, token limits, or pricing from them — those fields are left unset for pi to default.
  • Lots of models. The endpoint may return hundreds/thousands of entries (the OmniRoute gateway here returned ~1900). That is intentional — the command mirrors everything the provider exposes.
  • If the provider uses OAuth instead of a plain API key, getApiKeyForProvider still resolves the current credential for the request.

Contributors

AndreiTelteu

Issues