# MIT Parley Pi Extension

Use MIT Parley models in the Pi coding agent, with automatic model discovery, thinking settings, key switching, and a footer showing context usage and estimated cost.

For accounts, API keys, model capabilities, and billing, look at the Parley docs.

## Install

With Pi installed:

```bash
pi install npm:mit-parley-pi-extension
export PARLEY_API_KEY="your-parley-api-key"
pi
```

Use `/model` to choose an `MIT-parley` model and Shift+Tab to change the thinking level. Update the extension with `pi update`.

## Commands

| Command | Purpose |
|---|---|
| `/parley-models` | Show model catalog status and metadata sources |
| `/parley-models refresh` | Refresh models, prices, and token limits |
| `/parley-key` | Choose a configured key; `/parley-key personal` switches directly |
| `/parley-footer` | Toggle the extension's footer |

## Model discovery

The extension discovers supported chat models at startup, on `/reload`, and when switching keys. It checks documented prices and token limits daily. Network requests have a four-second deadline; failures fall back to cached or bundled data.

Models with inferred details are labeled `(estimated metadata)`. Unsupported model families are skipped. Footer costs are estimates, not invoices.

## Multiple keys

Give each key a nickname through its environment variable:

```bash
export PARLEY_PERSONAL_API_KEY="your-personal-key"
export PARLEY_COURSE_API_KEY="your-course-key"
```

Switch with `/parley-key personal` or `/parley-key course`. The selection is saved with the session and inherited by child processes. Switching keys resets the footer's cost counter.

## Options

| Environment variable | Effect |
|---|---|
| `PARLEY_KEY_PROFILE=personal` | Choose the startup key |
| `PARLEY_BASE_URL` | Use an alternative endpoint or credential proxy |
| `PARLEY_MODEL_DISCOVERY=0` | Use the bundled catalog without discovery requests |
| `PARLEY_DOCS_REFRESH=0` | Discover models but use bundled prices and limits |

## Development

```bash
npm install
npm run validate     # builds dist/ and runs tests and structural checks
pi --no-extensions -e ./dist/index.js
```

The last command loads only this extension for testing, avoiding a second npm-installed copy. Commit rebuilt `dist/` files with source changes.

Before publishing, bump the version in `package.json`, run `npm run validate`, and commit the release. Publish with `npm publish --access public`.
