@samrito/pi-cliproxyapi-provider 0.16.0
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/LICENSE +28 -0
- package/README.md +298 -0
- package/data/models-dev-fallback.json +1 -0
- package/extensions/index.ts +40 -0
- package/package.json +68 -0
- package/src/auth.ts +11 -0
- package/src/cache.ts +33 -0
- package/src/catalog.ts +248 -0
- package/src/codex-compat.ts +43 -0
- package/src/commands.ts +213 -0
- package/src/config.ts +296 -0
- package/src/cpa.ts +68 -0
- package/src/discovery.ts +20 -0
- package/src/matching.ts +150 -0
- package/src/model-api.ts +26 -0
- package/src/model-capabilities.ts +65 -0
- package/src/model-ui.ts +373 -0
- package/src/models-dev.ts +58 -0
- package/src/network.ts +47 -0
- package/src/provider.ts +200 -0
- package/src/reasoning-levels.ts +59 -0
- package/src/registration.ts +43 -0
- package/src/runtime.ts +69 -0
- package/src/settings.ts +76 -0
- package/src/types.ts +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Richard Hao
|
|
4
|
+
Copyright (c) 2026 samrito (modifications to this fork)
|
|
5
|
+
|
|
6
|
+
This package is a fork of pi-cliproxyapi-provider
|
|
7
|
+
(https://github.com/0xRichardH/pi-cliproxyapi-provider) by Richard Hao,
|
|
8
|
+
distributed under the MIT License reproduced below. The original copyright
|
|
9
|
+
notice is retained as the license requires; the modifications in this fork are
|
|
10
|
+
copyright their respective author.
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# @samrito/pi-cliproxyapi-provider
|
|
2
|
+
|
|
3
|
+
> A fork of [pi-cliproxyapi-provider](https://github.com/0xRichardH/pi-cliproxyapi-provider)
|
|
4
|
+
> by Richard Hao (MIT). This fork adds model thinking levels sourced from
|
|
5
|
+
> models.dev. It is a drop-in replacement: the settings namespace, config paths,
|
|
6
|
+
> cache directory, and `/cliproxyapi` command are unchanged, so existing
|
|
7
|
+
> configuration keeps working. Do not install it alongside the original — both
|
|
8
|
+
> register the same provider and command, and pi rejects the duplicate.
|
|
9
|
+
|
|
10
|
+
`@samrito/pi-cliproxyapi-provider` registers one [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI) instance as a pi model provider. It discovers models from CLIProxyAPI's OpenAI-compatible `/v1/models` endpoint and enriches them with provider-specific metadata from [models.dev](https://models.dev/). Mixed catalogs use OpenAI Completions by default, while GPT-5.6 family models (including Codex variants) use the Responses API so pi can read their usage data. Canonical `/v1/models` owners such as `openai` select the matching provider metadata; aliases can override that selection when a proxy routes billing differently.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
Install from npm:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pi install npm:@samrito/pi-cliproxyapi-provider
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or install from GitHub:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pi install git:github.com/xiangsam/pi-cliproxyapi-provider@master
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You can omit `@master`, but pinning a branch, tag, or commit makes Git installs reproducible:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pi install git:github.com/xiangsam/pi-cliproxyapi-provider@a28f326
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Restart pi after installing, then run:
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
/cliproxyapi config
|
|
36
|
+
/login cpa
|
|
37
|
+
/model
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Install for local testing
|
|
41
|
+
|
|
42
|
+
From this repository:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pi -e .
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
List models without installing:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
CLIPROXYAPI_BASE_URL=http://localhost:8317/v1 \
|
|
52
|
+
CLIPROXYAPI_API_KEY=your-key \
|
|
53
|
+
pi -e . --list-models cpa
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Configure
|
|
57
|
+
|
|
58
|
+
Run the interactive command:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
/cliproxyapi config
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
It writes global connection/auth config to:
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
~/.pi/agent/pi-cliproxyapi-provider/config.json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Environment variables override config:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
CLIPROXYAPI_BASE_URL
|
|
74
|
+
CLIPROXYAPI_PROVIDER_NAME
|
|
75
|
+
CLIPROXYAPI_AUTH_REQUIRED
|
|
76
|
+
CLIPROXYAPI_AUTH_HEADER
|
|
77
|
+
CLIPROXYAPI_MODELS_DEV_ENABLED
|
|
78
|
+
CLIPROXYAPI_METADATA_FALLBACK_PROVIDER
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Set `CLIPROXYAPI_METADATA_FALLBACK_PROVIDER=none` to disable unresolved-model metadata fallback.
|
|
82
|
+
|
|
83
|
+
Project config supports `metadataFallbackProvider`, metadata aliases, and bounded per-model overrides. Set `metadataFallbackProvider` to `null` or `"none"` to disable fallback. Connection and auth settings such as `baseUrl`, `providerName`, `authRequired`, `authHeader`, and `headers` must be set in global config or environment variables.
|
|
84
|
+
|
|
85
|
+
### GPT-5.6 context window
|
|
86
|
+
|
|
87
|
+
The provider advertises a `272000`-token context window for GPT-5.6 models by default. This matches Pi's conservative canonical limit, keeps compaction behavior consistent with native model definitions, and avoids assuming that every CLIProxyAPI upstream account or route enables the provider's full long-context limit.
|
|
88
|
+
|
|
89
|
+
To opt into the full context limit reported by models.dev (currently `1050000` tokens for OpenAI GPT-5.6 models), add this package-specific setting to global `~/.pi/agent/settings.json`:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"pi-cliproxyapi-provider": {
|
|
94
|
+
"gpt56ContextWindow": "full"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The same setting can be placed in project `.pi/settings.json`; project settings override global settings. Supported values are:
|
|
100
|
+
|
|
101
|
+
- `"canonical"` (default): advertise `272000` tokens and compact at Pi's conservative boundary.
|
|
102
|
+
- `"full"`: advertise the models.dev context limit, allowing Pi to retain substantially more history before compaction.
|
|
103
|
+
|
|
104
|
+
Use `"full"` only when the selected CLIProxyAPI route and upstream account actually support that limit. Requests above `272000` input tokens also use the higher models.dev context-pricing tier where one is defined.
|
|
105
|
+
|
|
106
|
+
### Thinking levels
|
|
107
|
+
|
|
108
|
+
The provider derives each model's selectable thinking levels from the
|
|
109
|
+
`reasoning_options` field in models.dev metadata. When a model publishes an
|
|
110
|
+
effort list, exactly those levels appear in Pi's thinking selector:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
deepseek-flash reasoning_options: [{"type":"effort","values":["low","high","max"]}]
|
|
114
|
+
-> Pi offers off, low, high, max
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Two details make this more than cosmetic:
|
|
118
|
+
|
|
119
|
+
- **Absent levels are hidden, not defaulted.** models.dev publishes an
|
|
120
|
+
exhaustive list, so every level it omits is explicitly marked unsupported. This
|
|
121
|
+
matters because Pi otherwise offers levels up to `high` using the provider
|
|
122
|
+
default, and a proxy that validates the level rejects the request. CLIProxyAPI
|
|
123
|
+
does exactly that: an unsupported level comes back as
|
|
124
|
+
`400 level "medium" not supported, valid levels: low, high, max`.
|
|
125
|
+
- **`xhigh` and `max` only appear when the list names them.** Pi hides extended
|
|
126
|
+
levels unless a model maps them explicitly, which is why `max` was previously
|
|
127
|
+
unreachable for models that support it.
|
|
128
|
+
|
|
129
|
+
Only `type: "effort"` publishes levels. `toggle` and `budget_tokens` describe
|
|
130
|
+
other reasoning shapes and are ignored, so those models keep Pi's default. A
|
|
131
|
+
built-in rule for the GPT-5.6 family remains as a fallback for models whose
|
|
132
|
+
metadata carries no effort list; where models.dev publishes one, it wins, because
|
|
133
|
+
it tracks the model's current capability and the rule does not.
|
|
134
|
+
|
|
135
|
+
> **Levels describe the model, not your proxy.** models.dev publishes the
|
|
136
|
+
> canonical capability, and a CLIProxyAPI route can accept a different set. A
|
|
137
|
+
> mismatch that offers a level the proxy rejects makes Pi send a request that
|
|
138
|
+
> fails with `400`. Correct it with the override below.
|
|
139
|
+
|
|
140
|
+
#### Correcting a level list
|
|
141
|
+
|
|
142
|
+
When a proxy serves a model differently from its published metadata, or when
|
|
143
|
+
the models.dev match lands on a different provider, override the map in Pi's own
|
|
144
|
+
`~/.pi/agent/models.json`:
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"providers": {
|
|
149
|
+
"cpa": {
|
|
150
|
+
"modelOverrides": {
|
|
151
|
+
"deepseek-flash": {
|
|
152
|
+
"thinkingLevelMap": {
|
|
153
|
+
"off": "none",
|
|
154
|
+
"minimal": null,
|
|
155
|
+
"low": "low",
|
|
156
|
+
"medium": null,
|
|
157
|
+
"high": "high",
|
|
158
|
+
"xhigh": null,
|
|
159
|
+
"max": "max"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
This layer is applied by Pi after the provider registers its models, so it wins
|
|
169
|
+
over both models.dev and the built-in rules. Use `null` to hide a level the
|
|
170
|
+
proxy rejects. Replace `cpa` with your configured provider name.
|
|
171
|
+
|
|
172
|
+
### Model and display configuration
|
|
173
|
+
|
|
174
|
+
Run `/cliproxyapi config` in Pi TUI mode to edit every package-level `settings.json` value. The tabbed panel has `Connection`, `Models`, and `Display` sections; it controls the GPT-5.6 context-window mode and whether the model selector shows the published strict tool-schema capability.
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"pi-cliproxyapi-provider": {
|
|
179
|
+
"gpt56ContextWindow": "canonical",
|
|
180
|
+
"showStrictMode": false
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
`showStrictMode` defaults to `false` because the selector stays compact for normal use. Enable it when diagnosing tool-schema behavior; model details always show `Strict tool schema` explicitly. Saving through `/cliproxyapi config` reloads Pi. Select `Connection` to open the endpoint and authentication editor.
|
|
186
|
+
|
|
187
|
+
## Authenticate
|
|
188
|
+
|
|
189
|
+
Use pi's normal API-key login flow:
|
|
190
|
+
|
|
191
|
+
```text
|
|
192
|
+
/login cpa
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
If you changed the provider name, use that name instead:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
/login 0xdev
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
For non-interactive runs, set:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
export CLIPROXYAPI_API_KEY=your-key
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Commands
|
|
208
|
+
|
|
209
|
+
```text
|
|
210
|
+
/cliproxyapi config # interactive setup
|
|
211
|
+
/cliproxyapi status # show snapshots, capabilities, and enrichment counts
|
|
212
|
+
/cliproxyapi refresh # refresh models and metadata, then update pi immediately
|
|
213
|
+
/cliproxyapi refresh models # refresh CLIProxyAPI availability only
|
|
214
|
+
/cliproxyapi refresh metadata # refresh models.dev metadata only
|
|
215
|
+
/cliproxyapi aliases # show unmatched model IDs for metadata aliases
|
|
216
|
+
/cliproxyapi models # inspect effective model settings and set bounded overrides
|
|
217
|
+
/cliproxyapi config # tabbed connection, model, and display configuration
|
|
218
|
+
/cliproxyapi config connection # open endpoint and authentication editor
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Metadata aliases
|
|
222
|
+
|
|
223
|
+
Aliases affect metadata only. The package still sends the original CLIProxyAPI model ID to the proxy.
|
|
224
|
+
|
|
225
|
+
When `/v1/models` reports a canonical owner such as `openai`, the package uses that provider's metadata even if models.dev lists the model under several providers. Noncanonical owners can embed a provider hint, so `feedmob-opencode-go` resolves to `opencode-go` when that provider publishes the model. If ownership is still unresolved, the package uses OpenRouter metadata by default when there is exactly one matching OpenRouter entry. Set `metadataFallbackProvider` to another models.dev provider ID, or to `null`/`"none"` to disable this fallback. Legacy metadata caches without source-provider identity are ignored in favor of the bundled provider-qualified catalog until metadata is refreshed. Add an alias when CLIProxyAPI's reported owner or fallback does not match the provider whose limits and pricing apply to your setup.
|
|
226
|
+
|
|
227
|
+
Add global aliases to:
|
|
228
|
+
|
|
229
|
+
```text
|
|
230
|
+
~/.pi/agent/pi-cliproxyapi-provider/config.json
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Add project aliases manually to:
|
|
234
|
+
|
|
235
|
+
```text
|
|
236
|
+
.pi/pi-cliproxyapi-provider/config.json
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Project config reads `metadataFallbackProvider`, `modelAliases`, and `modelOverrides`; other fields are ignored.
|
|
240
|
+
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"metadataFallbackProvider": "openrouter",
|
|
244
|
+
"modelAliases": {
|
|
245
|
+
"claude-opus-4-6-thinking": "anthropic/claude-opus-4-6",
|
|
246
|
+
"gpt-5.6-sol": "openai/gpt-5.6-sol"
|
|
247
|
+
},
|
|
248
|
+
"modelOverrides": {
|
|
249
|
+
"gpt-5.6-sol": {
|
|
250
|
+
"contextWindow": 512000,
|
|
251
|
+
"maxTokens": 32768
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Model inspector and overrides
|
|
258
|
+
|
|
259
|
+
Run `/cliproxyapi models` in Pi TUI mode to inspect the models in the current CPA snapshot. The selector shows the effective API, reasoning mode, and context window. The detail view also shows input modalities, cost, thinking levels, and the compatibility values that Pi will publish.
|
|
260
|
+
|
|
261
|
+
Only `reasoning`, `contextWindow`, and `maxTokens` are editable. Values are constrained to safe presets; choose `auto` to remove an override and restore the derived value after reload. API routing and compatibility stay provider-owned: GPT-5.6/Codex models remain on `openai-responses`, while the CLIProxyAPI workaround publishes `supportsStrictMode: false`.
|
|
262
|
+
|
|
263
|
+
For CPA Responses requests, the extension also applies the Codex-compatible function-tool wire contract used by `pi-codex-conversion`: each function tool explicitly carries `strict: null`. This preserves optional tool arguments such as `interactive_shell.listBackground` without replacing CPA authentication, transport, discovery, or streaming with the ChatGPT-backed `openai-codex-responses` provider.
|
|
264
|
+
|
|
265
|
+
Saving writes to an existing project config when present, otherwise to the global provider config, then reloads Pi. Project overrides take precedence over global overrides field by field.
|
|
266
|
+
|
|
267
|
+
## Snapshots and startup
|
|
268
|
+
|
|
269
|
+
```text
|
|
270
|
+
CPA /v1/models: local snapshot at startup, then a background refresh
|
|
271
|
+
models.dev metadata: persistent local snapshot, refreshed manually
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Snapshots live under:
|
|
275
|
+
|
|
276
|
+
```text
|
|
277
|
+
~/.cache/pi-cliproxyapi-provider/
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Startup registers the provider immediately from the last-known-good local snapshots. It then refreshes CLIProxyAPI availability in the background with a short timeout and updates the provider dynamically if the model list changed. On a first run, Pi registers a placeholder until background discovery succeeds. Startup never fetches `models.dev`; it uses the persistent local metadata snapshot or `data/models-dev-fallback.json` when no snapshot exists.
|
|
281
|
+
|
|
282
|
+
Manual refreshes update the running provider immediately; `/reload` is not required. Failed refreshes retain the last-known-good data independently for each source.
|
|
283
|
+
|
|
284
|
+
A scheduled GitHub Actions workflow checks the bundled fallback catalog daily. When it changes, the workflow validates the package, bumps the patch version, commits the update, and starts the normal release workflow. Maintainers can also update the catalog locally with:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
npm run update:models-dev
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Test
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
npm test
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Release
|
|
297
|
+
|
|
298
|
+
Changing the `package.json` version on `master` automatically creates a matching Git tag and GitHub Release, generates release notes, and publishes the package to npm. Changed daily models.dev catalogs also produce automatic patch releases through the same workflow. See [RELEASING.md](RELEASING.md) for authentication, versioning, verification, and troubleshooting.
|