pi-provimux 0.0.0-stage → 105.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,104 @@
1
+ # Changelog
2
+
3
+ ## 105.0.2
4
+
5
+ The extension is the same as in 105.0.1; what changes is how pi-provimux is released.
6
+
7
+ - **Published from GitHub, with provenance.** npm versions are published by the repository's `publish.yml` through
8
+ npm trusted publishing: no token, and each version on npm names the workflow run and the commit it was built
9
+ from. A version is published when `main` names one that npm does not have; its tag `v<version>` and GitHub release
10
+ are made by the same run.
11
+ - **Following the original.** A workflow takes each new release of
12
+ [pi-cliproxyapi-provider](https://github.com/router-for-me/pi-cliproxyapi-provider) once it has been public for
13
+ 24 hours. When it merges cleanly, passes a guard and passes every check, it is merged into `main` and released as
14
+ the next version (`105.1.1` for the original's 1.5.1). Anything else lands nothing and is reported in an issue.
15
+ Until it is switched on, it runs as a dry run: everything is checked, and it only says what it would land.
16
+ How it works, and what it accepts: [docs/FOLLOWING.md](docs/FOLLOWING.md).
17
+ - **Checked on pi 1.3.0 and pi 1.6.0** before anything lands and before anything is published, with the packed
18
+ package loaded by pi's own loader on both. The archive published to npm is that tested archive, byte for byte.
19
+
20
+ ## 105.0.1 - 2026-11-22
21
+
22
+ The extension is now **pi-provimux**, Provimux's pi extension, a fork of
23
+ [router-for-me/pi-cliproxyapi-provider](https://github.com/router-for-me/pi-cliproxyapi-provider). It works with
24
+ plain CLIProxyAPI too.
25
+
26
+ ### The name
27
+
28
+ - The package is `pi-provimux` (was `@router-for-me/pi-cliproxyapi-provider`): `pi install npm:pi-provimux`, or
29
+ from git, `pi install git:github.com/ngvoicu/pi-provimux`.
30
+ - Nothing your setup names changes: the provider id `cliproxyapi` (`cliproxyapi/<model>`), `/login CLIProxyAPI`, the
31
+ commands, the `CLIPROXYAPI_*` environment variables, `cliproxyapi.json`, `cliproxyapi-models.json` and the
32
+ `model-upstreams` events stay as they were. Remove the old package before installing this one, so that only one
33
+ registers the provider.
34
+ - Log lines start with `[pi-provimux]`.
35
+ - The README describes the extension as Provimux's, with credits to router-for-me. The LICENSE keeps
36
+ router-for-me's notice.
37
+
38
+ ### Changed
39
+
40
+ - **What answered names the credential, not only its kind.** `model-upstreams:answered` reports the one credential
41
+ Provimux names in `X-CPA-AUTH-PROVIDER` and `X-CPA-AUTH-HOST` (`cpa_auth_provider`, `cpa_auth_host` on the Codex
42
+ WebSocket's `response.created`), read from the response alone: a Claude login and a Devin login serving one model
43
+ are told apart, and a service not known is named by its host or provider. At most one report per answer, sent when
44
+ its headers or first event arrive, while the request is out, for the model the request was sent to (a virtual
45
+ model's routed one). Over HTTP and SSE only the headers count; over the WebSocket only `response.created`.
46
+ - **Each request is reported on its own.** Overlapping requests (pi's cache warmer next to the turn it warms, an
47
+ extension's own request with the session's callbacks, two requests to one model, a WebSocket turn next to an SSE
48
+ request) each report their own credential, once: a request's headers and its one report are kept by that request
49
+ alone, never in a slot shared with other requests.
50
+ - **`upstreams: []` for an answer that names nobody.** When Provimux leaves an answer without a name (plugin code
51
+ took part in it), the report says `upstreams: []`: answered, by something the proxy would not name, read as
52
+ "route not known". It is sent only once the proxy is known to name answers: such an answer is not reported while
53
+ the credential list is still loading (or could not be read) and nothing was named before in the session. Plain
54
+ CLIProxyAPI, which names no answer, still gets no report. Only the kind, from an older Provimux: the guess from the
55
+ credential list, as before, so such an answer is not reported until the list has loaded; it still shows that the
56
+ proxy names answers, so the next answer that names nobody is reported as `[]`.
57
+ [pi-cache-keeper](https://github.com/ngvoicu/pi-cache-keeper) reads `[]` as "route not known" from its next
58
+ release, 0.7.0, on; older versions ignore it.
59
+ - **More credentials map to pi's providers:** the kimi.com login to `kimi-coding`, xAI to `xai`, Vertex to
60
+ `google-vertex`, and API keys by host to `xai`, `meta`, `kimi-coding`, `moonshotai`, `moonshotai-cn`, `deepseek`,
61
+ `mistral`, `groq`, `cerebras`, `fireworks`, `together`, `nvidia` and `xiaomi`. A host or provider such as
62
+ `constructor` is named as given. The model id is the provider's own, as pi's catalog has it, in the routes and in
63
+ what answered: a prefix (the proxy's, or a configured one) is left out unless what is left is not in the catalog
64
+ and the id with it is (`openai/gpt-oss-120b` at Groq stays as it is; `openai/llama-3.3-70b-versatile` there is
65
+ `llama-3.3-70b-versatile`).
66
+ - **Needs pi 0.99.0 or newer** (was 0.82.0). On older pi, `model-upstreams:answered` was never sent for Codex
67
+ WebSocket turns, as pi only passes their events to extensions (`provider_stream_event`) from 0.99.0.
68
+ - **A hook's removal of the GPT system prompt is honoured, on pi before 1.6.0.** When an extension's
69
+ `before_provider_request` hook deletes `instructions` (or sets them to `undefined`), the base prompt is no longer
70
+ put back as the first developer message: the request goes as the hook left it, for example with only the hook's
71
+ own replacement. A hook that changes `instructions` still has its text moved, and without a hook the caching fix
72
+ from 1.5.0 is unchanged. On pi 1.6.0 there are no `instructions` to remove: pi puts the system prompt in the first
73
+ input item itself, before the hook runs, so a hook that wants it gone has to remove that item.
74
+ - **Claude Messages models keep their standard price under `/fast` and `/ultrafast`.** They are sent to
75
+ `/v1/messages` without a speed tier, so the Fast price from models.dev no longer applies to them.
76
+ - **A thinking level the model doesn't have is refused in `pi -p`, never changed silently.** `pi -p --thinking low`
77
+ (or `--model cliproxyapi/<model>:low`, `--models cliproxyapi/<model>:low`, or `--mode json`) on a model whose
78
+ levels don't include `low` now stops before sending anything, says which levels the model has, and exits with 1;
79
+ pi used to move it to the nearest level without a word. The model flags are read as pi reads them: a `:high` that
80
+ is part of a model's id (`--model cliproxyapi/local-assistant:high`) asks for no level, and a `--models` level counts
81
+ only where pi takes it (a new session, no `--model`). Interactive and RPC sessions keep pi's own move, and a
82
+ Codex-format request, an extension's own included, now names the level pi moves to, never one the model lacks, so
83
+ the proxy never picks a variant itself. That holds for a resumed conversation too: the first turn's level, which
84
+ the request keeps from the history, and later turns' levels are moved the same way when a catalog refresh took
85
+ them away.
86
+ - **A route lookup still out when its session ends is dropped.** On quit, `/reload` or a session change, the
87
+ `model-upstreams` lookup in flight is aborted and a late answer is ignored; nothing is emitted through a disposed
88
+ extension, so `pi -p` no longer exits with 1 after its answer, nor `/reload` ends the new session.
89
+
90
+ ### From pi-cliproxyapi-provider 1.5.0 (merged)
91
+
92
+ - **Ultra Fast mode**: `/ultrafast` sends `service_tier: "ultrafast"` on models that offer it. `/fast` and
93
+ `/ultrafast` exclude each other, and `fast` in `cliproxyapi.json` may now also be `"ultrafast"`.
94
+ - **GPT Responses prompt caching kept**: for `gpt-` models the base prompt is sent as the first `developer` input
95
+ message instead of top-level `instructions`, so the prompt cache keeps being read. This is for pi before 1.6.0;
96
+ pi 1.6.0 does it itself, for every model, and its request is sent as pi built it.
97
+
98
+ ### Already in this fork before 105.0.1
99
+
100
+ - Claude models in Claude's own Messages format, automatically where safe (`claudeMessages`).
101
+ - Where each model comes from, at the end of its name, from Provimux's model list.
102
+ - Where each model comes from and which kind of credential answered, for other extensions (`model-upstreams`,
103
+ `model-upstreams:request`, `model-upstreams:answered`), including over the Codex WebSocket.
104
+ - The package listed once in pi.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ngvoicu
4
+ Copyright (c) 2026 Router-For.ME
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,466 @@
1
- # Temporary Holding Version
1
+ # pi-provimux
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Provimux's extension for [pi](https://pi.dev).** It adds [Provimux](https://github.com/ngvoicu/provimux) as a
4
+ provider in pi, and works the same with plain [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI).
5
+
6
+ Every model your Provimux or CLIProxyAPI serves appears in pi's `/model`, under the provider `cliproxyapi`. With
7
+ Provimux, each model's name also says which accounts serve it (a subscription login or an API key, and whose), and
8
+ other pi extensions learn which one answered. With CLIProxyAPI, those parts stay quiet and everything else works.
9
+
10
+ ```bash
11
+ pi install npm:pi-provimux
12
+ ```
13
+
14
+ Then, in pi:
15
+
16
+ ```text
17
+ /login CLIProxyAPI
18
+ ```
19
+
20
+ and enter the server's address (for example `http://127.0.0.1:8317`) and your client key.
21
+
22
+ pi-provimux is a fork of [router-for-me/pi-cliproxyapi-provider](https://github.com/router-for-me/pi-cliproxyapi-provider),
23
+ see [Credits](#credits).
24
+
25
+ ## What it does
26
+
27
+ From the original extension:
28
+
29
+ - **Your models in pi.** It reads the model list from `{root}/v1/models?client_version=pi` and registers each model
30
+ with its context window, reasoning levels and, when [models.dev](https://models.dev) knows it, its price.
31
+ - **Setup by `/login`.** `/login CLIProxyAPI` asks for the address and the key, checks them, and saves them.
32
+ - **A model cache**, so pi starts at once when the server is slow; `/cliproxyapi-refresh` reloads the list.
33
+ - **`/fast` and `/ultrafast`**: faster service tiers on the models that offer them.
34
+ - **`/pause` and `/continue`**: hold every request to the provider until you continue.
35
+ - **GPT prompt caching kept**: the base prompt of `gpt-` models is sent so the prompt cache keeps being read (pi
36
+ before 1.6.0; pi 1.6.0 does it itself).
37
+ - **Thinking level changes that keep the cache**, for models that support them (from pi 1.6.0, pi's own).
38
+ - **Elapsed time and tokens per second** in pi's footer.
39
+ - **A fresh Codex WebSocket after compaction**, so the server's context matches the compacted one.
40
+
41
+ Added in pi-provimux:
42
+
43
+ - **[Claude Messages format](#claude-messages-format).** Claude models go to `/v1/messages` in Claude's own format,
44
+ automatically where safe. With pi's long cache retention, that brings Anthropic's 1-hour prompt cache.
45
+ - **[Where each model comes from, in its name](#where-each-model-comes-from-in-its-name).** With Provimux, a model's
46
+ name ends with what serves it: `Claude Opus 5.5 · Anthropic sub, fallback api`.
47
+ - **[Where each model comes from, for other extensions](#where-each-model-comes-from-for-other-extensions).** Over
48
+ pi's event bus, which accounts may serve each model and, with Provimux, which one answered each response, also over
49
+ the Codex WebSocket. [pi-cache-keeper](https://github.com/ngvoicu/pi-cache-keeper) uses it.
50
+ - **One package in pi's list.** The footer helper loads from the provider, so `pi list` shows a single extension.
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ # from npm
56
+ pi install npm:pi-provimux
57
+
58
+ # or from GitHub
59
+ pi install git:github.com/ngvoicu/pi-provimux
60
+
61
+ # from a local checkout
62
+ pi install /absolute/path/to/pi-provimux
63
+
64
+ # or temporarily for one run
65
+ pi -e /absolute/path/to/pi-provimux
66
+ ```
67
+
68
+ The version names the original release it is built on, then a count of its own: 105.0.1 is pi-provimux's first
69
+ release on the original's 1.5.0 (major × 100 + minor, then patch), 105.0.2 its second, and 105.1.1 would be the first
70
+ on the original's 1.5.1.
71
+
72
+ Versions on npm are published from this repository's `main` by GitHub Actions, with npm provenance. A workflow
73
+ follows the original's releases: once a day old, one that merges cleanly and passes every check is merged into `main`
74
+ and released. [docs/FOLLOWING.md](docs/FOLLOWING.md) says how, what that accepts, and whether it is switched on yet.
75
+
76
+ It needs pi 0.99.0 or newer: the Codex WebSocket reports which kind of account answered through pi's
77
+ `provider_stream_event`, which older pi does not have.
78
+
79
+ ### Coming from pi-cliproxyapi-provider
80
+
81
+ pi-provimux keeps everything your setup names: the provider id `cliproxyapi` (so `cliproxyapi/<model>` in your
82
+ settings still works), `/login CLIProxyAPI`, the commands, the `CLIPROXYAPI_*` environment variables, and the files
83
+ `cliproxyapi.json` and `cliproxyapi-models.json`. Remove the old package first, so that only one of them registers
84
+ the provider:
85
+
86
+ ```bash
87
+ pi remove npm:@router-for-me/pi-cliproxyapi-provider # or the source you installed it from
88
+ pi install npm:pi-provimux
89
+ ```
90
+
91
+ ## Login-style setup (recommended)
92
+
93
+ This plugin needs both **baseUrl** and **apiKey**. pi's built-in `/login` only supports multi-field prompts on the account/OAuth path, so CLIProxyAPI appears under **Sign in with an account** (not API key).
94
+
95
+ ### Preferred: /login shortcuts
96
+
97
+ ```text
98
+ /login CLIProxyAPI
99
+ ```
100
+
101
+ or:
102
+
103
+ ```text
104
+ /login cliproxyapi
105
+ ```
106
+
107
+ These shortcuts jump straight into CLIProxyAPI's multi-field baseUrl + API key prompts. The provider is registered as OAuth-only, so pi does not ask you to choose between API key and account first.
108
+
109
+ ### Menu path
110
+
111
+ ```text
112
+ /login
113
+ ```
114
+
115
+ Then choose:
116
+
117
+ 1. **Sign in with an account**
118
+ (required for multi-field baseUrl + API key prompts)
119
+ 2. **CLIProxyAPI**
120
+ 3. Enter:
121
+ - base URL — preferred form is host:port, e.g. `http://127.0.0.1:8317`
122
+ - API key
123
+
124
+ Final login validation calls `{root}/v1/models?client_version=pi` (this always bypasses the model cache and forces a fresh remote query):
125
+
126
+ - **HTTP 200** → login succeeds (empty model list is still OK) and the model cache is rewritten
127
+ - **non-200 / network error** → login fails and you are prompted to re-enter base URL + API key
128
+
129
+ On success:
130
+
131
+ - models are registered immediately in the current session (0 models is allowed)
132
+ - `baseUrl` / `apiKey` are written to `~/.pi/agent/cliproxyapi.json`
133
+ - pi also stores the returned credential in `~/.pi/agent/auth.json`
134
+
135
+ Re-run `/login CLIProxyAPI` or `/login cliproxyapi` anytime to reconfigure. The built-in `/logout` command only removes credentials saved in `auth.json`; it does not erase `cliproxyapi.json`. Remove or update that file if you also need to clear the provider configuration.
136
+
137
+ ## Non-interactive configuration
138
+
139
+ You can still configure without `/login`.
140
+
141
+ ### Config file
142
+
143
+ `~/.pi/agent/cliproxyapi.json`:
144
+
145
+ ```json
146
+ {
147
+ "baseUrl": "http://127.0.0.1:8317",
148
+ "apiKey": "12345",
149
+ "fast": false,
150
+ "pause": false
151
+ }
152
+ ```
153
+
154
+ Optional fields:
155
+
156
+ | Field | Default | Description |
157
+ | ------- | --------- | ------------- |
158
+ | `baseUrl` | `http://127.0.0.1:8317` | CLIProxyAPI address |
159
+ | `apiKey` | _(required unless set via /login or env)_ | Bearer token / CPA API key |
160
+ | `providerId` | `cliproxyapi` | Provider id shown in `/model` |
161
+ | `providerName` | `CLIProxyAPI` | Display name in `/login` and UI |
162
+ | `fast` | `false` | Persisted speed preference: `false` (off), `true` (Fast), or `"ultrafast"` (Ultra Fast) |
163
+ | `pause` | `false` | Persisted request-pause preference; provider requests wait until it is cleared |
164
+ | `tps` | `true` | Show the elapsed time footer and TPS summary in the TUI; see [Elapsed time and TPS](#elapsed-time-and-tps-tui) |
165
+ | `claudeMessages` | `"auto"` | When Claude models use Claude's own format: `"auto"`, `true` (always) or `false` (never); see [Claude Messages format](#claude-messages-format) |
166
+
167
+ ### Environment overrides
168
+
169
+ | Variable | Overrides |
170
+ | ---------- | ----------- |
171
+ | `CLIPROXYAPI_BASE_URL` | `baseUrl` |
172
+ | `CLIPROXYAPI_API_KEY` | `apiKey` |
173
+ | `CLIPROXYAPI_PROVIDER_ID` | `providerId` |
174
+ | `CLIPROXYAPI_PROVIDER_NAME` | `providerName` |
175
+ | `CLIPROXYAPI_FAST` | `fast` (`true` / `false`, also accepts `1`, `0`, `yes`, `no`, `on`, `off`) |
176
+ | `CLIPROXYAPI_CLAUDE_MESSAGES` | `claudeMessages` (`auto`, or the same values as `CLIPROXYAPI_FAST`) |
177
+
178
+ Resolution order for connection settings:
179
+
180
+ 1. Environment variables
181
+ 2. `cliproxyapi.json`
182
+ 3. `/login` credentials in `auth.json`
183
+ 4. Default baseUrl `http://127.0.0.1:8317`
184
+
185
+ At startup, `CLIPROXYAPI_FAST` overrides the persisted speed preference: a true value selects Fast, and a false value turns both modes off. The variable does not accept `ultrafast`. If unset, the provider uses `fast` from `cliproxyapi.json`, or defaults to off.
186
+
187
+ ### baseUrl normalization
188
+
189
+ Preferred form is **host:port only**:
190
+
191
+ | Input | Inference baseUrl | Models URL |
192
+ | ------- | ------------------- | ------------ |
193
+ | `http://127.0.0.1:8317` | `http://127.0.0.1:8317/backend-api/` | `http://127.0.0.1:8317/v1/models?client_version=pi` |
194
+ | `http://127.0.0.1:8317/backend-api` | `http://127.0.0.1:8317/backend-api/` | same models URL |
195
+ | `http://127.0.0.1:8317/v1` | `http://127.0.0.1:8317/backend-api/` | same models URL |
196
+ | `127.0.0.1:8317` | `http://127.0.0.1:8317/backend-api/` | same models URL |
197
+
198
+ pi then sends inference traffic to `{inference}/codex/responses`.
199
+
200
+ ## Fast and Ultra Fast modes
201
+
202
+ Both modes are **off by default**. They request faster processing for supported models and may use more credits or incur higher costs.
203
+
204
+ | Command | Model status label | Request field |
205
+ | ------- | ------------------ | ------------- |
206
+ | `/fast` | `fast` | `service_tier: "priority"` |
207
+ | `/ultrafast` | `Ultra Fast` | `service_tier: "ultrafast"` |
208
+
209
+ The modes are mutually exclusive. Run the active command again to turn it off, or run the other command to switch directly. Each change saves the global preference in `~/.pi/agent/cliproxyapi.json` and refreshes the provider's model pricing. The saved preference is restored at the next startup unless `CLIPROXYAPI_FAST` overrides it.
210
+
211
+ Both modes apply only to models whose CLIProxyAPI catalog entry has a non-empty `service_tiers` array. The provider ignores `additional_speed_tiers`. When a mode is effective, pi appends its yellow label to the bottom-right model status without a separate notification. On unsupported models, the commands still update the global preference and warn when enabling a mode, but the request and model status remain unchanged.
212
+
213
+ Both modes are independent of pi's reasoning level and use `experimental.modes.fast.cost` from `models.dev` when available. Otherwise, the registered model uses the standard price; the plugin does not guess prices from `-pro` or `-fast` model IDs.
214
+
215
+ ## Pausing provider requests
216
+
217
+ Pause provider requests with:
218
+
219
+ ```text
220
+ /pause
221
+ ```
222
+
223
+ Use `/continue` to clear the pause:
224
+
225
+ ```text
226
+ /continue
227
+ ```
228
+
229
+ Both commands persist the `pause` boolean in `~/.pi/agent/cliproxyapi.json`. Before every provider request, the extension rereads this setting. When it is `true`, the request waits asynchronously and checks again every 200 ms until `/continue` sets it to `false`. A pause issued during an active run lets that run finish before Elapsed stops; a run that starts while paused excludes its waiting time from Elapsed and TPS.
230
+
231
+ ## Model cache
232
+
233
+ The provider keeps a separate cache file so startup stays fast when CLIProxyAPI is slow or briefly unreachable:
234
+
235
+ `~/.pi/agent/cliproxyapi-models.json`
236
+
237
+ The cache stores only model metadata and derived endpoint URLs — the model list, Fast-capable IDs, `inferenceBaseUrl`, `modelsUrl`, and a `fetchedAt` timestamp. It **never** stores your API key or other credentials.
238
+
239
+ | Property | Value |
240
+ |----------|-------|
241
+ | Cache file | `~/.pi/agent/cliproxyapi-models.json` |
242
+ | Remote query timeout | 60 seconds |
243
+ | Scope | tied to the current `baseUrl` (a different base URL ignores the existing cache) |
244
+
245
+ ### Startup / resume behavior
246
+
247
+ When the provider loads (including session resume):
248
+
249
+ 1. If a cache exists for the configured `baseUrl`, its models are registered immediately. A remote query to `{root}/v1/models?client_version=pi` then runs in the background; on success, the cache is rewritten and the registered model list is refreshed. If the query fails, the existing cache remains active.
250
+ 2. If no matching cache exists, the remote query runs synchronously. On success, the cache is written and the fetched models are registered. If it fails, startup logs a warning and no models are registered until the proxy responds.
251
+
252
+ Use `/cliproxyapi-refresh` to force an immediate remote refresh of the model catalog.
253
+
254
+ ### Refresh commands
255
+
256
+ - `/cliproxyapi-refresh` — force an immediate remote refresh of the model catalog, rewrite the cache, and update registered models. Use this after adding or removing models on the proxy without restarting pi.
257
+ - `/login CLIProxyAPI` / `/login cliproxyapi` — re-entering credentials always forces a fresh models query and rewrites the cache.
258
+
259
+ Delete `~/.pi/agent/cliproxyapi-models.json` to clear the cache manually.
260
+
261
+ ## Model mapping
262
+
263
+ From CPA catalog entry → pi model:
264
+
265
+ | CPA field | Pi field |
266
+ | ----------- | ---------- |
267
+ | `slug` | `id` |
268
+ | `display_name` | `name`, followed by [where the model comes from](#where-each-model-comes-from-in-its-name) when CLIProxyAPI says |
269
+ | `context_window` | `contextWindow` |
270
+ | `input_modalities` | `input` (`text` / `image`) |
271
+ | `supported_reasoning_levels[].effort` | `thinkingLevelMap` + `reasoning` |
272
+ | `supports_reasoning_effort_updates` | `compat.supportsMidConvoEffort` |
273
+ | `visibility: "hide"` | skipped |
274
+
275
+ Unsupported pi thinking levels are set to `null` so they are hidden in the UI. A level the model lacks asked on the command line of a one-shot run (`pi -p --thinking low`, `--model cliproxyapi/<model>:low`, or `--models cliproxyapi/<model>:low` when that pattern selects the model; also `--mode json`) is refused: nothing is sent, the error names the levels the model has, and pi exits with 1. The flags are read as pi reads them: a suffix that is part of a model's id (`--model cliproxyapi/local-assistant:high`, for a model listed as `local-assistant:high`) asks for no level. Elsewhere (the level picker, a saved default level, `--thinking` in an interactive or RPC session) pi moves the level to the nearest one the model has, and the request names that level, never the missing one. When available, prices are matched against canonical model entries in `models.dev`; `cost.tiers[].tier.size` becomes pi's `inputTokensAbove`, including thresholds such as `272000`. The legacy `context_over_200k` field is used only when no explicit tiers are present. Ambiguous reseller prices are not selected arbitrarily and fall back to zero. These are catalog/list prices, not a guarantee of CPA's own markup or billing.
276
+
277
+ ## GPT Responses prompt caching
278
+
279
+ For `gpt-` model IDs (ignoring case and surrounding whitespace), the provider sends the base prompt as the first `developer` input message instead of top-level `instructions`. Nonblank text is kept verbatim; blank text defaults to `You are a helpful assistant.` Existing input items stay in order, tools and `prompt_cache_key` are unchanged, and other models keep their existing request shape. This applies to HTTP and WebSocket requests, including Pi background streams that use this provider. A changed developer prefix or model sends the full input instead of a WebSocket continuation delta. An extension's `before_provider_request` hook comes first: if it changes `instructions`, its text is the one moved; if it removes them (deleted or set to `undefined`), no base prompt is put back, and the request goes as the hook left it.
280
+
281
+ All of this is for pi before 1.6.0. **pi 1.6.0** does it itself, for every model: it builds no `instructions` and puts the system prompt, as given, in a leading `{ "role": "developer", "content": "…" }` input item, and the provider sends that as pi built it. A hook then finds no `instructions`; to drop or replace the base prompt it has to remove or change that first item. One thing the provider still does on pi 1.6.0: a `gpt-` request whose input does not start with a developer message (no system prompt, or a hook that put another item first) gets `You are a helpful assistant.` as a developer message in front, as on older pi.
282
+
283
+ ## Cache-preserving thinking level changes
284
+
285
+ Models whose catalog entry sets `supports_reasoning_effort_updates` (GPT-6 on CLIProxyAPI) get pi's cache-preserving mid-session thinking level changes, matching the behavior pi >=1.3.0 ships for the OpenAI provider, with placement following the OpenAI documentation: the effort of the first turn becomes the fixed request-level `reasoning.effort`, and each later change is carried by a `configuration_update` input item placed immediately before the user message it applies to, so switching levels mid-session keeps the prompt prefix — and the upstream prompt cache — intact instead of rewriting it. WebSocket `previous_response_id` continuation also survives level changes. Histories lacking initial recorded levels (for example, sessions started before this support landed) may still need one full-context request while the baseline is being established. The behavior requires a pi >=1.3.0 host (its shared Responses converter); on older hosts the plugin detects the missing support and falls back to the classic request-level effort. On **pi 1.6.0**, pi's Codex adapter carries these changes itself: the provider leaves pi's own code in place and only moves the items to the placement above. pi 1.6.0 also records the level it sent with thinking off, `none`, on the reply.
286
+
287
+ The raw `models.dev` response is cached for 24 hours at `~/.pi/agent/tmp/models-dev-cache.json`. A fresh cache avoids the network request; an expired cache is refreshed with a three-second timeout, and stale data is retained if refresh fails. If neither the network nor a previous cache is available, pricing safely falls back to zero. A small explicit alias table covers known CLIProxyAPI variants such as `gemini-pro-agent` → `gemini-3.1-pro-preview`; unknown variants are not guessed.
288
+
289
+ ## Claude Messages format
290
+
291
+ Claude models can be sent in Claude's own format to CLIProxyAPI's `/v1/messages`, using pi's built-in Anthropic client,
292
+ instead of the Codex Responses format every other model uses. This happens automatically; nothing needs configuring.
293
+
294
+ - **Which models:** those CLIProxyAPI lists with `owned_by: "anthropic"` (from its plain `/v1/models`) that pi's
295
+ built-in catalog also knows, **and** for which CLIProxyAPI reports an output limit (`max_tokens`). Their compat
296
+ flags and thinking levels come from that catalog. Every other model, Claude models pi doesn't know, and Claude
297
+ models without a reported output limit stay on the Codex format.
298
+ - **Setting:** `claudeMessages` in `cliproxyapi.json` (or `CLIPROXYAPI_CLAUDE_MESSAGES`) is `"auto"` by default.
299
+ `false` keeps every model on the Codex format; `true` also switches Claude models CLIProxyAPI reports no output
300
+ limit for (they then get pi's 16,384 default, see below).
301
+ - **Why:** Claude's format can carry Anthropic features the Codex format can't. The main one is the **1-hour cache**:
302
+ with `PI_CACHE_RETENTION=long`, pi marks the prompt with `cache_control` `ttl: "1h"`, CLIProxyAPI passes it through,
303
+ and Anthropic writes the 1-hour tier, on API keys too. One-hour cache writes cost 2× the input price instead of
304
+ 1.25×. The thinking levels offered are also the model's own, not a generic list.
305
+ - **Limits come from CLIProxyAPI:** the context window and output limit are what CLIProxyAPI reports, as for every
306
+ other model. Unlike the Codex format, Claude's format sends the output limit (`max_tokens`) on every request. In
307
+ `"auto"`, a Claude model CLIProxyAPI reports no output limit for stays on the Codex format, which sends no output
308
+ limit; with `true` pi would fall back to 16,384 output tokens.
309
+ - **Not available for these models:** Fast mode (a Codex service tier; they keep their standard price under `/fast`
310
+ and `/ultrafast`) and the Codex WebSocket transport. Thinking, tools, images and auto-compaction work as before.
311
+ - Changing the setting refreshes the model list (the cache records it). The first request of an ongoing session after
312
+ a model switches formats is a cache miss.
313
+
314
+ ## Where each model comes from, in its name
315
+
316
+ Through CLIProxyAPI pi sees one provider, so its model list does not say whether a model is served by a subscription
317
+ login or by a paid API key, nor by whom. [Provimux](https://github.com/ngvoicu/provimux), or a CLIProxyAPI that lists its credentials
318
+ ([router-for-me/CLIProxyAPI#7634](https://github.com/router-for-me/CLIProxyAPI/pull/7634)), is asked for them with the
319
+ plain model list (`GET /v1/models?include=accounts`, one request per model list refresh), and each model's name then
320
+ ends with where it comes from:
321
+
322
+ ```
323
+ Claude Opus 5.5 · Anthropic sub, fallback api
324
+ Claude Sonnet 4.6 · Anthropic sub, fallback Antigravity sub
325
+ anthropic/claude-opus-5.5 · OpenRouter api
326
+ ```
327
+
328
+ - **`sub`** is a subscription login, **`api`** an API key.
329
+ - **First** comes what CLIProxyAPI may answer with: the credentials at the highest priority, joined by `or` when they
330
+ differ (`Anthropic sub or api`). **After `fallback`** come the others, highest priority first: what may answer when
331
+ the first fail or cool down. A service is named again only when it changes.
332
+ - **The service** is the one behind CLIProxyAPI's provider (`claude` is Anthropic, `codex` is OpenAI …). An API key
333
+ goes by the host CLIProxyAPI names for it (`openrouter.ai` is OpenRouter whatever the entry is called; a host that
334
+ is not known is shown as it is). A provider that is not known keeps CLIProxyAPI's name for it.
335
+ - Everything is read from CLIProxyAPI's list; nothing is guessed from a model's id or owner. A CLIProxyAPI that does
336
+ not list its credentials, or a list that can't be read, leaves every name as it was.
337
+ - It says what the list said when it was fetched: after changing credentials or priorities in CLIProxyAPI, run
338
+ `/cliproxyapi-refresh` (the startup refresh also updates it). What answered a given request is a separate matter:
339
+ see the next section.
340
+
341
+ pi shows a model's name in `/model` beside its id and searches it, and its model patterns (`--model`, scoped models)
342
+ also match names: `openrouter` now matches every model that comes from OpenRouter, not only ids that contain the
343
+ word.
344
+
345
+ ## Where each model comes from (for other extensions)
346
+
347
+ Through CLIProxyAPI pi sees one provider, but each model is served by a subscription login or an API key of some lab,
348
+ and the two can differ in window, prompt-cache lifetime and price (a Claude login keeps a cache for an hour, a Claude
349
+ API key for 5 minutes by default). This package tells other pi extensions where each model comes from, over pi's event
350
+ bus (`pi.events`), so that they need to know nothing about CLIProxyAPI.
351
+ [pi-cache-keeper](https://github.com/ngvoicu/pi-cache-keeper) uses it to fill windows, cache lifetimes and prices
352
+ from providers.dev.
353
+
354
+ - **`model-upstreams:request`**: an extension that wants the routes sends this (any payload). This package then asks
355
+ CLIProxyAPI `GET /v1/models?include=accounts` again and answers. Without such an extension this adds no request;
356
+ the model list itself is always loaded with `?include=accounts`, for the names and the Claude Messages format.
357
+ The answer belongs to the session that asked: when it ends (quit, `/reload`, another session) before the list
358
+ arrives, the lookup is aborted and nothing is said.
359
+ - **`model-upstreams`**: `{ provider, models: { [modelId]: { upstreams, fallbacks? } } }`, the answer, and again after
360
+ `/cliproxyapi-refresh`. `upstreams` are what may serve the model (several: it is not known which), `fallbacks` what
361
+ may answer when those fail or cool down.
362
+ - **`model-upstreams:answered`** (Provimux): `{ provider, model, upstreams }`, what answered a request, at most once
363
+ per answer. `model` is the model the request was sent to (a virtual model's routed model, not the selection).
364
+ Over HTTP and SSE only the response headers count: the kind in `X-CPA-AUTH-KIND`, the credential's provider in
365
+ `X-CPA-AUTH-PROVIDER` and an API key's host in `X-CPA-AUTH-HOST`; fields in the body are not Provimux's (an inner
366
+ gateway's) and are ignored. Over the Codex WebSocket, which has no response headers per turn, only the
367
+ `cpa_auth_kind`, `cpa_auth_provider` and `cpa_auth_host` fields Provimux puts on the turn's `response.created`.
368
+ - **With the provider**, `upstreams` is that one credential, whatever its priority, read from the response alone:
369
+ its provider (whatever its letter case), its kind, and its host, where no host means the credential has none. The
370
+ credential list is not consulted (it may be older than the proxy's state) nor waited for. A Claude login and a
371
+ Devin login serving the same model are told apart. A credential that leads to a service not known is still
372
+ named, so a change of route is seen: by its host for an API key that has one (`api.example.test`), else by its
373
+ provider as the response gives it.
374
+ - **With only the kind** (an older Provimux that does not name the provider), a guess: the listed credentials of
375
+ that kind at their highest priority, possibly several; `[]` when none of them is known. The guess needs the
376
+ credential list: until it has loaded, such an answer is not reported at all, even after earlier answers were
377
+ named. It still shows that the proxy names answers: while the list is pending it is not reported itself, but the
378
+ next answer that names nobody is reported as `[]`.
379
+ - **`upstreams: []`**: answered, by something the proxy would not name. Provimux leaves an answer without the
380
+ three when plugin code took part in its bytes; from a proxy that names answers (it lists its credentials, or
381
+ named an answer before in this session) such an answer is reported as `[]`, so that a listener does not keep the
382
+ last named credential's values. Read it as "route not known". Whether the proxy names answers is known only once
383
+ its credential list has loaded or it has named one: an answer that names nobody while the list is still loading
384
+ and before anything was named in this session (with a provider, or only a kind) is not reported. A list that could not be read counts as still
385
+ loading.
386
+ - **Nothing** from plain CLIProxyAPI, which names no answer, nor before an extension asked for the routes.
387
+ - **When**: as soon as the answer's headers (or its `response.created` event) arrive and its stream's first event
388
+ says which model it is for, so before the answer ends, while the request is still out.
389
+ - **Each request on its own.** Requests overlap: pi's cache warmer refreshes the cache while the turn it warms is
390
+ still streaming, and an extension can send its own request with the session's callbacks. Each request keeps its
391
+ own response headers and its one report, so an answer is never reported with another request's credential or
392
+ model.
393
+
394
+ [pi-cache-keeper](https://github.com/ngvoicu/pi-cache-keeper) reads `upstreams: []` as "route not known" from its
395
+ next release, 0.7.0, on; older versions ignore an empty `upstreams` and keep what they had.
396
+
397
+ An upstream is `{ provider, model?, subscription? }`: the pi provider the model would come from if used directly
398
+ (`anthropic`, `openai-codex`, `openai`, `meta`, `openrouter`, `google`) or a providers.dev provider pi has none for
399
+ (`devin`, `antigravity`); the model's id there when it differs; `true` for a subscription login, `false` for an API
400
+ key, absent when not known.
401
+
402
+ How the routes are made:
403
+
404
+ - **Provimux, or a CLIProxyAPI that lists its credentials** ([router-for-me/CLIProxyAPI#7634](https://github.com/router-for-me/CLIProxyAPI/pull/7634)):
405
+ CLIProxyAPI uses the highest priority that is free in every routing mode and picks among the credentials sharing it
406
+ (round-robin by default; with no priority set, all share 0). So the `upstreams` are the credentials at the highest
407
+ priority, the `fallbacks` the others. An API key whose host CLIProxyAPI names goes by the host (`openrouter.ai`,
408
+ `api.openai.com`, `api.anthropic.com`, `generativelanguage.googleapis.com`, `api.x.ai`, `api.meta.ai`,
409
+ `api.kimi.com`, `api.moonshot.ai`, `api.moonshot.cn`, `api.deepseek.com`, `api.mistral.ai`, `api.groq.com`,
410
+ `api.cerebras.ai`, `api.fireworks.ai`, `api.together.ai`, `integrate.api.nvidia.com`, `api.xiaomimimo.com`;
411
+ another host is not known), whatever its entry is called; without a host, an OpenAI-compatible entry counts as
412
+ OpenRouter only when named `openrouter`. The model id is the provider's own, as pi's catalog has it (the
413
+ session's models, else the catalog pi-ai is built with): a prefix before it (CLIProxyAPI's own, or one configured
414
+ for the credential) is left out unless what is left is not in the catalog and the id with it is. So
415
+ `openai/gpt-oss-120b` at Groq stays as it is, and a prefix `openai` before Groq's `llama-3.3-70b-versatile` is left
416
+ out; `Qwen/Qwen3.6-Plus` at Together, `google/gemma-3-12b-it` at NVIDIA, `accounts/fireworks/models/…` at Fireworks
417
+ and `lab/model` at OpenRouter are kept whole. A model the catalog does not have keeps as many parts as nearly all
418
+ the provider's ids have, else its last. A credential at the top that leads somewhere not known makes the route not known
419
+ (`upstreams: []`).
420
+ - **A CLIProxyAPI that doesn't**: the lab its model list names as the owner (`owned_by`), by login or key
421
+ (`subscription` absent; for OpenAI the Codex login or an OpenAI key); `devin/…` (CLIProxyAPI's own prefix) is Devin;
422
+ any other name with a slash is not known.
423
+
424
+ ## Migration from static models.json
425
+
426
+ If you previously maintained a static provider such as `cpa-responses` in `~/.pi/agent/models.json`:
427
+
428
+ 1. Install this package and run `/login CLIProxyAPI` or `/login cliproxyapi` (or set `cliproxyapi.json`).
429
+ 2. Point `defaultProvider` / `enabledModels` at `cliproxyapi/<model-id>` (or set `providerId` to `cpa-responses` for a drop-in id).
430
+ 3. Remove the hand-maintained models array once the dynamic list looks correct.
431
+
432
+ ## Elapsed time and TPS (TUI)
433
+
434
+ The provider extension also loads `extensions/tps.ts` (so pi lists the package as a single extension), which only activates for the primary interactive TUI session (`ctx.hasUI && ctx.mode === "tui"`):
435
+
436
+ - While the agent is running, the footer shows `Elapsed …` (updates every second).
437
+ - When the agent settles, the footer keeps the final elapsed time and a notification reports approximate TPS plus token usage (`out` / `in` / cache r/w / total).
438
+ - Subagent and print-mode sessions do not own the timer, clear the parent footer, or emit TPS toasts.
439
+
440
+ Set `"tps": false` in `~/.pi/agent/cliproxyapi.json` to turn off just this helper (takes effect on the next start or `/reload`).
441
+
442
+ ## Failure behavior
443
+
444
+ - CLIProxyAPI `closed network connection` responses are normalized as transient network errors so pi's agent-level retry policy reconnects and restarts the interrupted assistant turn. Completed conversation and tool results remain available; token streaming does not resume from the exact interruption point.
445
+ - Before setup / without credentials: provider still appears in `/login`; no models are listed yet.
446
+ - After successful `/login`: models are registered; credentials are stored in `auth.json` and mirrored to `cliproxyapi.json`.
447
+ - The built-in `/logout` command removes only the matching `auth.json` credential; environment variables and `cliproxyapi.json` are unchanged.
448
+ - If a models request returns **HTTP 401** or CPA is unreachable during startup, an existing matching cache remains in use while the background refresh fails. Only when no cache is available is a warning logged; reconfigure via `/login CLIProxyAPI` or fix config/env.
449
+ - Login final step validates credentials by requesting models:
450
+ - HTTP 200 (including empty catalog) → credentials are persisted
451
+ - non-200 / network / invalid baseUrl → nothing is persisted; re-enter baseUrl + API key
452
+ - If CPA returns HTTP 200 with zero usable models: login still succeeds; re-run `/login CLIProxyAPI` later after models become available.
453
+ - If the selected model does not provide a non-empty `service_tiers` array: the request is left unchanged; `/fast` and `/ultrafast` still update the global preference and warn when enabling a mode.
454
+ - After `/compact`, threshold compaction, or overflow recovery, the provider closes the reused Codex WebSocket for the current session. CLIProxyAPI binds server-side context to the connection, so a reused socket would keep reporting a near-full `cacheRead` and retrigger proactive compaction even though the client context is now small. SSE is unaffected because it bills from the request body.
455
+
456
+ ## Credits
457
+
458
+ pi-provimux is a fork of [pi-cliproxyapi-provider](https://github.com/router-for-me/pi-cliproxyapi-provider) by
459
+ [Router-For.ME](https://github.com/router-for-me), released under the MIT license. Nearly everything it does is their
460
+ work: the provider, the login, the model mapping, the cache, the Fast modes and the Codex stream. pi-provimux adds the
461
+ Provimux parts above and merges the original's changes. Thank you to router-for-me for the extension and for
462
+ [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI).
463
+
464
+ ## License
465
+
466
+ MIT. See [LICENSE](LICENSE).