pi-cliproxyapi-native 0.1.8 → 0.2.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/README.md CHANGED
@@ -4,17 +4,38 @@ Use [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI) for chat, image
4
4
 
5
5
  Chat uses Pi's native API adapters and model metadata, with availability from your proxy. Image and video tools have separate model selections, so you can generate media without switching your chat model.
6
6
 
7
+ ## Contents
8
+
9
+ - [Install](#install)
10
+ - [Connection](#connection)
11
+ - [Images and videos](#images-and-videos)
12
+ - [Choose a media model](#choose-a-media-model)
13
+ - [Generate media](#generate-media)
14
+ - [Resolution and aspect ratio](#resolution-and-aspect-ratio)
15
+ - [Supported media models](#supported-media-models)
16
+ - [Files, status, and limits](#files-status-and-limits)
17
+ - [Chat models](#chat-models)
18
+ - [Refresh](#refresh)
19
+ - [Wait for quota reset](#wait-for-quota-reset)
20
+ - [Compaction](#compaction)
21
+ - [Aliases and model limits](#aliases-and-model-limits)
22
+ - [Backend routes](#backend-routes)
23
+ - [OAuth and API-key routes](#oauth-and-api-key-routes)
24
+ - [Thinking and child sessions](#thinking-and-child-sessions)
25
+ - [Protocol notes](#protocol-notes)
26
+ - [License](#license)
27
+
7
28
  ## Install
8
29
 
9
- The extension targets Pi 1.1.0 and CLIProxyAPI 8.0.22, with Node.js 22.19 or newer. Run CLIProxyAPI with your upstream accounts configured before connecting Pi. The extension uses Pi's host-provided packages, adds no runtime dependencies, and needs no compilation.
30
+ The extension targets Pi 1.3.0 and CLIProxyAPI 8.0.30, with Node.js 22.19 or newer. Run CLIProxyAPI with your upstream accounts configured before connecting Pi. The extension uses Pi's host-provided packages, adds no runtime dependencies, and needs no compilation.
10
31
 
11
32
  If you installed `pi-cliproxy-native`, remove it before installing the renamed package. Both register the same `cliproxyapi` provider.
12
33
 
13
34
  ```sh
14
- pi install npm:pi-cliproxyapi-native@0.1.8
35
+ pi install npm:pi-cliproxyapi-native@0.2.0
15
36
  ```
16
37
 
17
- For Git installation, use `pi install git:github.com/hawkff/pi-cliproxyapi-native@v0.1.8`. For a local checkout, use `pi install /path/to/pi-cliproxyapi-native`.
38
+ For Git installation, use `pi install git:github.com/hawkff/pi-cliproxyapi-native@v0.2.0`. For a local checkout, use `pi install /path/to/pi-cliproxyapi-native`.
18
39
 
19
40
  The default proxy address is `http://localhost:8317`. For another address, set the [connection](#connection) before logging in. Restart Pi, then run:
20
41
 
@@ -135,9 +156,9 @@ Your proxy must advertise the exact ID for a model to be available.
135
156
  | Google models | `gemini-2.5-flash-image`, `gemini-3.1-flash-image`, `gemini-3-pro-image`, `gemini-3.1-flash-lite-image` |
136
157
  | xAI models | `grok-imagine-image`, `grok-imagine-image-quality`, `grok-imagine-image-2.0`, `grok-imagine-video`, `grok-imagine-video-1.5`, `grok-imagine-video-1.5-preview` |
137
158
 
138
- The listed Gemini image models also support advertised `vertex/` and `antigravity/` routes. Those prefixes do not enable OpenAI or xAI media execution; the picker shows those entries as disabled. Other prefixes, media aliases, unknown media IDs, Google Veo, and editing endpoints are unsupported.
159
+ Supported media IDs can also use advertised `api/` and `oauth/` credential routes. Gemini image models also support `vertex/` and `antigravity/` backend routes. Those backend prefixes do not enable OpenAI or xAI media execution; the picker shows those entries as disabled. Other prefixes, nested prefixes, media aliases, unknown media IDs, Google Veo, and editing endpoints are unsupported.
139
160
 
140
- The extension disables these retired Imagen IDs, including their `vertex/` and `antigravity/` forms:
161
+ The extension disables these retired Imagen IDs, including their supported prefixed forms:
141
162
 
142
163
  - `imagen-3.0-generate-002`
143
164
  - `imagen-3.0-fast-generate-001`
@@ -199,6 +220,8 @@ Invalid management credentials, rejected account access, invalid usage data, or
199
220
 
200
221
  Management requests stay on the configured proxy and reject redirects. Account access tokens stay in CLIProxyAPI. The extension reads account metadata and proxies usage GETs; it does not reset quotas, change credentials, or clear proxy cooldowns. Management keys grant broader access than chat keys, so keep them private. Live lookup supports up to 100 active Claude subscription accounts.
201
222
 
223
+ Explicit `api/` routes skip live Claude subscription lookup, even with a management key. `oauth/` routes keep the lookup for matching OAuth accounts. Retries keep the selected route's full model ID.
224
+
202
225
  Other chat routes retain the response-based fallback: `Retry-After` on HTTP 429 or a recognized quota HTTP 403, or `reset_seconds` in a `model_cooldown` error. Google's native adapter exposes only the structured error body. Those waits share the same seven-day deadline but cannot inspect live weekly usage. Image and video generation still do not retry.
203
226
 
204
227
  ### Compaction
@@ -225,9 +248,11 @@ To describe a proxy alias, add a canonical metadata reference to `~/.pi/agent/pi
225
248
 
226
249
  Replace `<canonical-model-id>` with an ID from Pi's Anthropic catalog. References can also use `openai/`, `openai-codex/`, or `google/`. Aliases select metadata; requests retain the original proxy ID.
227
250
 
228
- A `vertex/` or `antigravity/` route can reuse its unprefixed ID's alias if that reference resolves to one metadata entry. An alias for the full prefixed ID takes precedence. Custom prefixes need an explicit chat alias. Arbitrary aliases may lack ID-specific adapter behavior; canonical Gemini IDs and the two recognized prefixes retain native thinking and tool-turn handling.
251
+ The recognized prefixes are `vertex/`, `antigravity/`, `api/`, and `oauth/`. Each can reuse its unprefixed ID's alias if that reference resolves to one metadata entry. An alias for the full prefixed ID takes precedence. Other prefixes need an explicit chat alias. Arbitrary aliases may lack ID-specific adapter behavior; canonical Gemini IDs and the recognized prefixes retain native thinking and tool-turn handling.
229
252
 
230
- For Antigravity IDs `claude-opus-5-5-high` and `claude-sonnet-5-5-high`, the extension falls back to `anthropic/claude-opus-5-5` and `anthropic/claude-sonnet-5-5` metadata. This applies to bare IDs and recognized `antigravity/` or `vertex/` routes. Explicit aliases take precedence, followed by exact native metadata. The fallback requires the corresponding canonical entry in Pi and names the model like a configured alias, for example `claude-opus-5-5-high (Claude Opus 5.5)`; requests keep the advertised `-high` ID.
253
+ For Antigravity IDs `claude-opus-5-5-high` and `claude-sonnet-5-5-high`, the extension falls back to `anthropic/claude-opus-5-5` and `anthropic/claude-sonnet-5-5` metadata. This applies to bare IDs and the recognized route prefixes. Explicit aliases take precedence, followed by exact native metadata. The fallback requires the corresponding canonical entry in Pi and names the model like a configured alias, for example `claude-opus-5-5-high (Claude Opus 5.5)`; requests keep the advertised `-high` ID.
254
+
255
+ The same fallback rules map `gemini-4-argon-high` to `google/gemini-4-argon`, including recognized route prefixes.
231
256
 
232
257
  Use Pi's `models.json` `modelOverrides` for limits, prices, or compatibility changes. Use its `models` array for IDs with no built-in metadata. Updating Pi supplies newer metadata. Catalog prices are estimates, not the proxy's bill; check upstream limits before increasing them.
233
258
 
@@ -244,6 +269,27 @@ These examples select media defaults. Chat routes belong in Pi's built-in `/mode
244
269
 
245
270
  Set the CLIProxyAPI auth record's top-level `prefix` to `vertex` or `antigravity` to advertise those routes. With `routing.force-model-prefix: false` in CLIProxyAPI 8, the proxy retains bare IDs too. Legacy configurations use the top-level `force-model-prefix` setting. This extension does not change proxy configuration or restart it.
246
271
 
272
+ ## OAuth and API-key routes
273
+
274
+ CLIProxyAPI can advertise separate model IDs for OAuth and API-key credentials. The extension labels `oauth/<model>` as **OAuth** and `api/<model>` as **API key**. It matches the unprefixed model's metadata and sends the full advertised ID on requests. It does not retry an explicit route as a bare ID or another credential route.
275
+
276
+ Configure the prefixes in CLIProxyAPI's v8 layout:
277
+
278
+ - For an API-key group, set `api-keys.<provider>[].prefix` to `api`. A key-level `prefix` can override the group value.
279
+ - For an OAuth credential, set the auth record's top-level `prefix` to `oauth`.
280
+
281
+ If a legacy file stores client keys in the root `api-keys` list, migrate them to `access.api-keys` before adding provider groups. A successful v8 management write performs this migration.
282
+
283
+ CLIProxyAPI also supports per-group and per-key model aliases, exclusions, priorities, and proxy overrides. See its [configuration fields](https://github.com/router-for-me/cliproxyapidocs/blob/main/docs/en/configuration/options.md).
284
+
285
+ The [v8 management API](https://github.com/router-for-me/cliproxyapidocs/blob/main/docs/en/management/apiv8.md) manages API-key groups through `/v8/management/config/api-keys/<provider>`. These lists must be replaced as a whole; numeric paths cannot select an entry. OAuth fields use `PATCH /v8/management/credentials/fields`. The extension does not call these endpoints or need a management key for model discovery.
286
+
287
+ After setting the prefixes, run `/cliproxyapi-refresh`. Choose `cliproxyapi/oauth/<model>` or `cliproxyapi/api/<model>` in Pi's `/model` picker. Media routes appear in `/cli:model`.
288
+
289
+ The extension trusts your prefix configuration; it does not inspect credential types. Keep each prefix limited to its matching credential type. Unprefixed IDs remain **Automatic (proxy routing)** and may use either pool. Set `routing.force-model-prefix: true` in CLIProxyAPI to exclude prefixed credentials from unprefixed requests.
290
+
291
+ Chat and media selections remain independent. The automatic OpenAI image default is still unprefixed; select a prefixed media model to choose its credential route.
292
+
247
293
  ## Thinking and child sessions
248
294
 
249
295
  Use a reference such as `cliproxyapi/<model-id>:high` in Pi or pi-subagents. Pi separates the thinking suffix from the request ID. Supported levels come from model metadata; `xhigh` and `max` require explicit support. Pi clamps unsupported levels, and models that require thinking cannot use `off`. Keep thinking suffixes out of alias references.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cliproxyapi-native",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "CLIProxyAPI chat discovery and image/video generation with Pi's native adapters",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@biomejs/biome": "^2.5.13",
42
- "@earendil-works/pi-ai": "^1.1.0",
43
- "@earendil-works/pi-coding-agent": "^1.1.0",
44
- "@earendil-works/pi-tui": "^1.1.0",
42
+ "@earendil-works/pi-ai": "^1.3.0",
43
+ "@earendil-works/pi-coding-agent": "^1.3.0",
44
+ "@earendil-works/pi-tui": "^1.3.0",
45
45
  "@types/node": "^24.13.4",
46
46
  "typescript": "5.9.3"
47
47
  },
package/src/catalog.ts CHANGED
@@ -36,15 +36,20 @@ export function parseCatalog(value: unknown) {
36
36
 
37
37
  // Resolve metadata and capabilities without changing registry or request IDs.
38
38
  export function modelRoute(id: string) {
39
- const match = /^(vertex|antigravity)\/(.+)$/.exec(id);
39
+ const match = /^(vertex|antigravity|oauth|api)\/(.+)$/.exec(id);
40
+ const prefix = match?.[1];
40
41
  return {
41
42
  metadataId: match?.[2] ?? id,
42
- backend: match ? (match[1] === "vertex" ? "Vertex" : "Antigravity") : undefined,
43
+ prefix,
44
+ backend: prefix === "vertex" ? "Vertex" : prefix === "antigravity" ? "Antigravity" : undefined,
45
+ authType: prefix === "api" ? "api-key" : prefix === "oauth" ? "oauth" : undefined,
43
46
  };
44
47
  }
45
48
 
46
49
  export function backendLabel(id: string) {
47
- return modelRoute(id).backend ?? (id.includes("/") ? "Unknown backend" : "Automatic (proxy routing)");
50
+ const { backend, authType } = modelRoute(id);
51
+ if (authType) return authType === "api-key" ? "API key" : "OAuth";
52
+ return backend ?? (id.includes("/") ? "Unknown backend" : "Automatic (proxy routing)");
48
53
  }
49
54
 
50
55
  export function routedName(id: string, name = id) {
@@ -175,6 +180,7 @@ const owners: Readonly<Record<string, string>> = {
175
180
  const metadataFallbacks = new Map([
176
181
  ["claude-opus-5-5-high", "anthropic/claude-opus-5-5"],
177
182
  ["claude-sonnet-5-5-high", "anthropic/claude-sonnet-5-5"],
183
+ ["gemini-4-argon-high", "google/gemini-4-argon"],
178
184
  ]);
179
185
 
180
186
  export function mapCatalog(value: unknown, config: Config, known: readonly Model<Api>[]) {
@@ -188,11 +194,11 @@ export function mapCatalog(value: unknown, config: Config, known: readonly Model
188
194
  skipped.add(entry.id);
189
195
  continue;
190
196
  }
191
- const { metadataId, backend } = modelRoute(entry.id);
192
- const routed = !entry.id.includes("/") || backend;
197
+ const { metadataId, prefix } = modelRoute(entry.id);
198
+ const routed = !entry.id.includes("/") || prefix;
193
199
  const alias = Object.hasOwn(config.aliases, entry.id)
194
200
  ? config.aliases[entry.id]
195
- : backend && Object.hasOwn(config.aliases, metadataId)
201
+ : prefix && Object.hasOwn(config.aliases, metadataId)
196
202
  ? config.aliases[metadataId]
197
203
  : routed && !byId.has(metadataId)
198
204
  ? metadataFallbacks.get(metadataId)
@@ -1,4 +1,5 @@
1
1
  import { setTimeout as sleep } from "node:timers/promises";
2
+ import { modelRoute } from "./catalog.ts";
2
3
  import { type Config, isRecord } from "./config.ts";
3
4
 
4
5
  export type QuotaWaitHandler = (id: symbol, remainingSeconds: number | undefined) => void;
@@ -150,7 +151,9 @@ export async function fetchClaudeQuota(
150
151
  // ponytail: probe at most 100 accounts; batch larger pools before raising this limit.
151
152
  if (accounts.length > 100)
152
153
  throw new Error("Live quota lookup supports at most 100 active Claude accounts.");
153
- const reference = config.aliases[modelId] ?? modelId;
154
+ const { metadataId, prefix } = modelRoute(modelId);
155
+ const reference =
156
+ config.aliases[modelId] ?? (prefix ? config.aliases[metadataId] : undefined) ?? metadataId;
154
157
  const results = await Promise.allSettled(
155
158
  accounts.map(async (account: unknown) => {
156
159
  if (
@@ -34,12 +34,12 @@ export function readMediaDefaults(config: Config, ctx: DefaultsContext) {
34
34
  export function automaticImageDefault(config: Config, ctx: DefaultsContext) {
35
35
  const model = ctx.model;
36
36
  if (!model || mediaPurpose(model.id)) return undefined;
37
- const { metadataId, backend } = modelRoute(model.id);
37
+ const { metadataId, prefix } = modelRoute(model.id);
38
38
  const alias =
39
39
  model.provider === PROVIDER_ID
40
40
  ? Object.hasOwn(config.aliases, model.id)
41
41
  ? config.aliases[model.id]
42
- : backend && Object.hasOwn(config.aliases, metadataId)
42
+ : prefix && Object.hasOwn(config.aliases, metadataId)
43
43
  ? config.aliases[metadataId]
44
44
  : undefined
45
45
  : undefined;
package/src/provider.ts CHANGED
@@ -188,11 +188,12 @@ function route(
188
188
  (selected, context, options) => {
189
189
  // A resumed selection must not send the current key to an old endpoint.
190
190
  const model = { ...selected, baseUrl: endpoint(config.baseUrl, selected.api) };
191
- const { metadataId, backend } = modelRoute(model.id);
192
- const google = backend && model.api === "google-generative-ai";
191
+ const { metadataId, prefix, backend, authType } = modelRoute(model.id);
192
+ const google = prefix && model.api === "google-generative-ai";
193
193
  const managementKey =
194
194
  options?.env?.CLIPROXYAPI_MANAGEMENT_KEY ?? process.env.CLIPROXYAPI_MANAGEMENT_KEY ?? "";
195
- const liveClaude = model.api === "anthropic-messages" && !backend && managementKey !== "";
195
+ const liveClaude =
196
+ model.api === "anthropic-messages" && !backend && authType !== "api-key" && managementKey !== "";
196
197
  const adapterModel = google ? { ...model, id: metadataId } : model;
197
198
  // Google needs canonical IDs for tool turns. Swap identities to keep bare history cross-route.
198
199
  const adapterContext = google
@@ -350,7 +351,7 @@ export function createCliproxyProvider(
350
351
  ) {
351
352
  const standardAuth = envApiKeyAuth("CLIProxyAPI API key", ["CLIPROXYAPI_API_KEY"]);
352
353
  const scope = createHash("sha256")
353
- .update(JSON.stringify([4, { baseUrl: config.baseUrl, aliases: config.aliases }]))
354
+ .update(JSON.stringify([5, { baseUrl: config.baseUrl, aliases: config.aliases }]))
354
355
  .digest("hex");
355
356
  const provider = createProvider<CpaApi>({
356
357
  id: PROVIDER_ID,