# @velocirouter/pi

[Pi](https://pi.dev) package for [VelociRouter](https://velocirouter.site).
It registers VelociRouter as a provider and loads the model catalog from the
API.

Requires **Pi 0.86.1 or later** from `@earendil-works/pi-coding-agent`.
If you already have a supported version, install the package:

```bash
pi install npm:@velocirouter/pi
```

Then run `/login` inside pi, pick **VelociRouter**, and paste your `rt-…` key.
Pi refreshes the catalog right after login, so the models show up in `/model`
straight away.

## Install or update Pi (if needed)

If Pi is not installed, or your version is below 0.86.1, install the latest
version, then run the package installation command above:

```bash
npm install -g @earendil-works/pi-coding-agent@latest
```

### Migrating from the legacy npm package

Only if you installed Pi through `@mariozechner/pi-coding-agent`, replace it
with the current distribution using the commands below. The legacy distribution
does not support this package's catalog refresh. Then run the package
installation command above.

```bash
npm uninstall -g @mariozechner/pi-coding-agent
npm install -g @earendil-works/pi-coding-agent@latest
```

## What it registers

- **Provider** — `velocirouter`, an `openai-completions` endpoint.
- **Login** — pi's built-in API-key login under `/login`.
- **Models** — fetched from `/v1/models` and cached in pi's model store, so new
  models appear without upgrading this package. Image support and the
  reasoning-effort ladder come from the API; levels a model does not support
  are hidden from pi's thinking picker. The context window is the API's
  combined window minus the output reservation: pi compacts once accumulated
  tokens pass it, and those tokens are the next request's input, so the
  combined figure would let a long session overshoot the input ceiling.

Session costs use the billed USD total returned by VelociRouter in streaming
`usage.cost`. Enable **Cost in response** for your user in VelociRouter first.
This is reporting only; it does not add another charge. If the server omits cost,
the default model prices remain zero. Per-category cost breakdowns are not
available, and earlier turns recorded with zero cost are not updated.

The catalog is fetched when an interactive session starts, after `/login`, and
from the `/model` picker. `pi -p` and `pi --list-models` read the cached copy;
when the cache is empty they fetch it once with the stored key or
`VELOCIROUTER_API_KEY`, so CI needs no interactive start.

## Environment variables

| Variable | Effect |
| --- | --- |
| `VELOCIROUTER_API_KEY` | Used when no key was stored by `/login`. Set this in CI. |
| `VELOCIROUTER_BASE_URL` | Override the API host (default `https://api.velocirouter.site`). |

## Development checks

Run `npm test` with the Pi AI peer dependency available. To also check host
module resolution and streaming through Pi's actual extension loader, run:

```bash
JITI_FS_CACHE=0 PI_TEST_INSTALL_DIR="$(npm root -g)/@earendil-works/pi-coding-agent" \
  node --test loader.test.js
```

The loader check uses the host Pi installation and needs no local Pi AI install.
It is skipped when `PI_TEST_INSTALL_DIR` is unset.

## Publishing

```bash
npm publish --access public
```
