pi-cliproxyapi-native 0.1.8 → 0.1.9
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 +29 -6
- package/package.json +1 -1
- package/src/catalog.ts +11 -6
- package/src/claude-quota.ts +4 -1
- package/src/media-defaults.ts +2 -2
- package/src/provider.ts +5 -4
package/README.md
CHANGED
|
@@ -11,10 +11,10 @@ The extension targets Pi 1.1.0 and CLIProxyAPI 8.0.22, with Node.js 22.19 or new
|
|
|
11
11
|
If you installed `pi-cliproxy-native`, remove it before installing the renamed package. Both register the same `cliproxyapi` provider.
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
pi install npm:pi-cliproxyapi-native@0.1.
|
|
14
|
+
pi install npm:pi-cliproxyapi-native@0.1.9
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
For Git installation, use `pi install git:github.com/hawkff/pi-cliproxyapi-native@v0.1.
|
|
17
|
+
For Git installation, use `pi install git:github.com/hawkff/pi-cliproxyapi-native@v0.1.9`. For a local checkout, use `pi install /path/to/pi-cliproxyapi-native`.
|
|
18
18
|
|
|
19
19
|
The default proxy address is `http://localhost:8317`. For another address, set the [connection](#connection) before logging in. Restart Pi, then run:
|
|
20
20
|
|
|
@@ -135,9 +135,9 @@ Your proxy must advertise the exact ID for a model to be available.
|
|
|
135
135
|
| Google models | `gemini-2.5-flash-image`, `gemini-3.1-flash-image`, `gemini-3-pro-image`, `gemini-3.1-flash-lite-image` |
|
|
136
136
|
| 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
137
|
|
|
138
|
-
|
|
138
|
+
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
139
|
|
|
140
|
-
The extension disables these retired Imagen IDs, including their
|
|
140
|
+
The extension disables these retired Imagen IDs, including their supported prefixed forms:
|
|
141
141
|
|
|
142
142
|
- `imagen-3.0-generate-002`
|
|
143
143
|
- `imagen-3.0-fast-generate-001`
|
|
@@ -199,6 +199,8 @@ Invalid management credentials, rejected account access, invalid usage data, or
|
|
|
199
199
|
|
|
200
200
|
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
201
|
|
|
202
|
+
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.
|
|
203
|
+
|
|
202
204
|
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
205
|
|
|
204
206
|
### Compaction
|
|
@@ -225,9 +227,9 @@ To describe a proxy alias, add a canonical metadata reference to `~/.pi/agent/pi
|
|
|
225
227
|
|
|
226
228
|
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
229
|
|
|
228
|
-
|
|
230
|
+
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
231
|
|
|
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
|
|
232
|
+
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.
|
|
231
233
|
|
|
232
234
|
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
235
|
|
|
@@ -244,6 +246,27 @@ These examples select media defaults. Chat routes belong in Pi's built-in `/mode
|
|
|
244
246
|
|
|
245
247
|
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
248
|
|
|
249
|
+
## OAuth and API-key routes
|
|
250
|
+
|
|
251
|
+
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.
|
|
252
|
+
|
|
253
|
+
Configure the prefixes in CLIProxyAPI's v8 layout:
|
|
254
|
+
|
|
255
|
+
- For an API-key group, set `api-keys.<provider>[].prefix` to `api`. A key-level `prefix` can override the group value.
|
|
256
|
+
- For an OAuth credential, set the auth record's top-level `prefix` to `oauth`.
|
|
257
|
+
|
|
258
|
+
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.
|
|
259
|
+
|
|
260
|
+
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).
|
|
261
|
+
|
|
262
|
+
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.
|
|
263
|
+
|
|
264
|
+
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`.
|
|
265
|
+
|
|
266
|
+
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.
|
|
267
|
+
|
|
268
|
+
Chat and media selections remain independent. The automatic OpenAI image default is still unprefixed; select a prefixed media model to choose its credential route.
|
|
269
|
+
|
|
247
270
|
## Thinking and child sessions
|
|
248
271
|
|
|
249
272
|
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
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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -188,11 +193,11 @@ export function mapCatalog(value: unknown, config: Config, known: readonly Model
|
|
|
188
193
|
skipped.add(entry.id);
|
|
189
194
|
continue;
|
|
190
195
|
}
|
|
191
|
-
const { metadataId,
|
|
192
|
-
const routed = !entry.id.includes("/") ||
|
|
196
|
+
const { metadataId, prefix } = modelRoute(entry.id);
|
|
197
|
+
const routed = !entry.id.includes("/") || prefix;
|
|
193
198
|
const alias = Object.hasOwn(config.aliases, entry.id)
|
|
194
199
|
? config.aliases[entry.id]
|
|
195
|
-
:
|
|
200
|
+
: prefix && Object.hasOwn(config.aliases, metadataId)
|
|
196
201
|
? config.aliases[metadataId]
|
|
197
202
|
: routed && !byId.has(metadataId)
|
|
198
203
|
? metadataFallbacks.get(metadataId)
|
package/src/claude-quota.ts
CHANGED
|
@@ -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
|
|
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 (
|
package/src/media-defaults.ts
CHANGED
|
@@ -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,
|
|
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
|
-
:
|
|
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 =
|
|
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 =
|
|
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([
|
|
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,
|