README.md

pi CLIProxyAPI provider

The pi CLIProxyAPI provider is an extension for the pi coding agent that lets pi use every model on a CLIProxyAPI server. CLIProxyAPI is a local server that puts your Claude, Codex, Kimi, Grok, and other accounts behind one API key.

The extension sends each model through the API that suits it. Claude and Kimi models use the Anthropic Messages API, so cache marks and Anthropic options reach the model. Every other model uses the OpenAI Responses API.

What you get

  • A model list that comes from your CLIProxyAPI server, with the context windows and reasoning levels the server reports, and prices from models.dev
  • A web_search tool that runs searches through CLIProxyAPI and estimates what each search cost, when the server reports token usage
  • A footer that shows your accounts' quota left in each window with bars and reset countdowns, the context window fill, token and cost totals, and the run's elapsed time. Set "footer": false to go back to pi's stock footer
  • Commands for Fast mode, pausing requests, and adding upstream accounts

Requirements

  • Node.js 22.19 or later
  • pi 0.82 or later
  • A running CLIProxyAPI server and an API key for it

Install

Install the package from GitCafe with pi:

sh
1pi install https://git.cafe/dynd/pi-cliproxyapi-provider

Pi follows the main branch and updates the package on pi update. The package is not on npm.

Then start pi and run /login cliproxyapi. Pi asks for the server address and the API key, and the extension checks them by loading the model list. If you leave the address empty, the extension uses http://127.0.0.1:8317, which is the CLIProxyAPI default.

Connect without logging in

You can set the connection in environment variables instead, which is useful when you run pi in scripts or other programs that have no login screen:

sh
1export CLIPROXYAPI_BASE_URL=http://127.0.0.1:8317
2export CLIPROXYAPI_API_KEY=your-key

The extension looks for each value in the environment first, then in ~/.pi/agent/cliproxyapi.json, and then in the /login credentials. The address can be the server root or any of its API paths, e.g., https://host:8317/v1. The extension refuses plain http for any host other than this machine, so keys never cross the network unencrypted. An address without a scheme gets https, or http for localhost, 127.0.0.1, and ::1.

Commands

CommandWhat it does
/login cliproxyapiSaves the server address and API key
/cliproxyapi-statusReloads the model list, clears every CLIProxyAPI cooldown when a management key is set, then shows the connection, model count, prices, and settings
/fastTurns Fast mode on or off for models that support it
/pause and /continueHolds provider requests until you continue
/websearch-model [model-id|auto]Picks the model that web_search uses

The extension caches the model list for 10 minutes. It keeps the model list, prices, and usage in one file, ~/.cache/pi-cliproxyapi/cache.json (or under $XDG_CACHE_HOME), so ~/.pi/agent holds only cliproxyapi.json. It hides models that the server no longer lists, and models whose accounts have hit their usage limits.

Settings file

You can put settings in ~/.pi/agent/cliproxyapi.json. Every field is optional:

json
1{
2 "baseUrl": "http://127.0.0.1:8317",
3 "apiKey": "your-key",
4 "managementKey": "your-management-key",
5 "fast": false,
6 "footer": true,
7 "pause": false,
8 "searchModel": "<model-id>",
9 "thinkingDisplay": { "<model-id>": "summarized" },
10 "maxTokens": { "<model-id>": 262144 },
11 "imageInput": { "<model-id>": false },
12 "providerId": "cliproxyapi",
13 "providerName": "CLIProxyAPI"
14}

The fields work as follows:

  • managementKey is the CLIProxyAPI management key. It turns on the usage footer, and lets /cliproxyapi-status reload the server's model definitions and clear cooldowns. You can also set it with the CLIPROXY_MANAGEMENT_KEY environment variable. A value that starts with ! is a shell command, and its output is the key, as with keys in pi's auth.json.
  • footer turns the custom footer on or off. It defaults to true. Set it to false to restore pi's stock footer, with each account's quota left shown on one plain line with status emoji instead.
  • thinkingDisplay sets, per model, whether the model sends thought summaries. It applies to models that use the Anthropic Messages API with thinking turned on. The default is omitted, because Claude streams its answer only when summaries are off. Set a model to summarized to see its summaries.
  • maxTokens sets, per model, the most output tokens pi asks for. Use it for models that CLIProxyAPI lists without an output limit, such as API-key upstreams. Those models otherwise get 16,384. pi still trims each request to the context that is left.
  • imageInput sets, per model, whether pi may send images. Set a model to false when CLIProxyAPI lists image input for a text-only upstream, or to true for the reverse.
  • searchModel sets the model for web_search. When it's empty, the extension picks one.
  • providerId is the provider ID that pi uses in model names, e.g., cliproxyapi/<model-id>, and in /login. If you change it, pi looks for the login under the new ID, so you need to log in again. providerName is the name pi shows. The environment variables CLIPROXYAPI_PROVIDER_ID and CLIPROXYAPI_PROVIDER_NAME do the same.

Use the model mapping outside pi

The files in src/core don't import pi-coding-agent, and they don't read files or environment variables on their own. Programs built on pi-ai can import them to load the catalog, pick an API per model, and build a provider. src/core/provider.ts builds the provider, src/core/connection.ts resolves the address and key, and src/core/catalog.ts maps the catalog.

Development

Install the dependencies and run the checks:

sh
1npm install
2npm run typecheck
3npm run check
4npm test

The scripts in test/e2e call a live CLIProxyAPI server, and npm test doesn't run them. Run one by hand, e.g., node test/e2e/catalog.ts. They use CLIPROXYAPI_BASE_URL and CLIPROXYAPI_API_KEY, or your pi login if those aren't set.

License

MIT