pi-provider-litellm 3.0.1 → 3.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
@@ -154,6 +154,8 @@ Treat the configured LiteLLM proxy as trusted: Skills can add instructions to th
154
154
  /model
155
155
  ```
156
156
 
157
+ To refresh catalogs on demand, run `/litellm-refresh` for every configured LiteLLM provider, or `/litellm-refresh <provider>` for one alias. It works with `PI_OFFLINE` set, which stops Pi's own `/model` refresh from contacting the network. It contacts only the configured proxies: `LITELLM_OFFLINE=1` and `LITELLM_DISCOVERY_TIMEOUT_MS=0` still disable it, and models.dev enrichment stays off under `PI_OFFLINE`. Each provider reports its model count, the failure, or missing credentials. With LiteLLM MCP enabled, the refresh also re-checks that provider's MCP tools.
158
+
157
159
  Every request routed through a configured LiteLLM provider includes Pi's canonical session ID in the
158
160
  `x-litellm-session-id` header. This groups Chat Completions, Responses, and native Messages requests in LiteLLM without
159
161
  adding transport-specific fields to request bodies.
@@ -173,12 +175,17 @@ Native Messages authenticates with `x-api-key`; every transport carries the `x-l
173
175
  | `LITELLM_GCLOUD_TOKEN_AUTH` | unset | If set to a non-empty value other than `0`, use Google Application Default Credentials as the LiteLLM bearer token source. This takes precedence over `LITELLM_API_KEY_HELPER` and `LITELLM_API_KEY` when no stored `/login litellm` credential exists. |
174
176
  | `GOOGLE_APPLICATION_CREDENTIALS` | Google default ADC path | Optional path to an ADC JSON file used by `LITELLM_GCLOUD_TOKEN_AUTH`. If unset, the extension checks the default gcloud ADC locations. |
175
177
  | `LITELLM_OFFLINE` | unset | If `1`, disable all model and MCP discovery, including post-login discovery; use cached models only when their stored canonical proxy root exactly matches the active credential root, including any path prefix. URL-standard host casing and default ports are canonicalized, but paths remain case-sensitive. |
178
+ | `PI_OFFLINE` | unset | Pi documents it as disabling automatic network activity, including model catalog refreshes. Through Pi 0.87.1, any set value (including `0` or an empty string) disables startup model discovery and `/model` network refreshes. Run `/litellm-refresh`, or unset it, to discover; cached models can still be used offline. |
176
179
  | `LITELLM_DISCOVERY_TIMEOUT_MS` | `5000` | Background and explicit discovery fetch timeout in ms; `0` disables automatic discovery |
177
180
  | `LITELLM_CLI_JWT_EXPIRATION_HOURS` | `24` | CLI SSO token lifetime fallback for older proxies whose poll response omits `expires_in`; mirror a non-default proxy setting locally |
178
- | `LITELLM_VERBOSE_DISCOVERY` | unset | If `1`, enable progress messages during model and MCP discovery (login, refresh, startup), including MCP prepared/registered/dropped counts. Progress messages are off by default; MCP safety diagnostics (see below) are always reported regardless of this setting |
181
+ | `LITELLM_VERBOSE_DISCOVERY` | unset | If `1`, enable progress messages during model and MCP discovery (login, refresh, startup), including startup skip reasons, defaulted `/model/info` context windows, and MCP prepared/registered/dropped counts. Progress messages are off by default; MCP safety diagnostics (see below) are always reported regardless of this setting |
182
+ | `LITELLM_DEFAULT_CONTEXT_WINDOW` | `128000` | Context window assumed when neither LiteLLM's `/model/info` nor the catalog reports `max_input_tokens`. Set a positive integer for proxies whose custom aliases carry no metadata; an unset or unusable value keeps 128K |
183
+ | `LITELLM_MODELS_DEV` | unset | If `1`, enrich discovered metadata (limits, prices, effort lists) from models.dev, cached for 28 days in `litellm-models-dev.json`. Off by default because LiteLLM's `/model/info` is authoritative; use it when LiteLLM's model map lacks a model's metadata |
179
184
 
180
185
  Only use a trusted `LITELLM_API_KEY_HELPER` or `!command`. Prefer an absolute executable path, keep secrets out of command arguments, and print only the token to stdout without logging it to stderr.
181
186
 
187
+ With `LITELLM_VERBOSE_DISCOVERY=1`, `/model/info` discovery reports published routes whose context window uses the fallback assumption (including wildcard expansions) on one line with the selected value, a count, and a sample of escaped route names. Each route is reported once per process. Explicit or authoritative catalog limits do not trigger it, even when numerically equal to the default. Set `model_info.max_input_tokens` on every deployment in the route to provide real limits; this diagnostic does not change discovery limits or routing.
188
+
182
189
  `LITELLM_DISCOVERY_TIMEOUT_MS=0` disables automatic and explicit refresh model discovery. It does not replace the base URL or API key settings required to send requests when you are not using `/login litellm`.
183
190
 
184
191
  ### Google ADC token auth
@@ -200,11 +207,11 @@ If your LiteLLM proxy exposes MCP REST endpoints, this extension discovers tools
200
207
  - `GET /mcp-rest/tools/list`
201
208
  - `POST /mcp-rest/tools/call`
202
209
 
203
- An MCP access denial pauses discovery until a successful `/login litellm` (SSO or API key). The pause survives restarts in `~/.pi/agent/litellm-mcp-pauses/`, scoped to the proxy, login, and headers with salted credential fingerprints. A new API key or header configuration has its own scope. Each explicit login creates a fresh opaque `litellmMcpSession` identifier in Pi's stored credential, even when the key is unchanged; automatic OAuth refresh preserves that identifier and its pause. Older Pi processes cannot pause the new login. Pause files contain no credentials or proxy error text. Model discovery and chat continue normally. Grant MCP access on the proxy before signing in again. An explicit `litellm.mcp.enabled: false` setting remains disabled after login.
210
+ An MCP access denial pauses discovery until a successful `/login litellm` (SSO or API key); an alias provider, which has no login, stays paused until its credentials, base URL, or headers change. The pause survives restarts in `~/.pi/agent/litellm-mcp-pauses/`, scoped to the proxy, login, and headers with salted credential fingerprints. A new API key or header configuration has its own scope. Each explicit login creates a fresh opaque `litellmMcpSession` identifier in Pi's stored credential, even when the key is unchanged; automatic OAuth refresh preserves that identifier and its pause. Older Pi processes cannot pause the new login. Pause files contain no credentials or proxy error text. Model discovery and chat continue normally. Grant MCP access on the proxy before signing in again. An explicit `litellm.mcp.enabled: false` setting remains disabled after login.
204
211
 
205
- Each discovered tool is registered as a native Pi tool named `mcp_<server>_<tool>_<hash>`, at most 64 characters, using only `[a-z0-9_]`. The trailing 10-character hash is derived from the tool's identity (`server_id`, `server_name`, `name`) and is always present, so a name depends only on that tool and never on which other tools happen to be in the same catalog — adding or removing a sibling never renames a survivor. When the readable prefix would overflow 64 characters it is truncated from the right, so a long server name can leave little or none of the tool name visible; the hash is what distinguishes such tools. Tools from different servers therefore never overwrite each other, and exact duplicate identities are registered once.
212
+ Each discovered tool is registered as a native Pi tool named `mcp_<server>_<tool>_<hash>`, at most 64 characters, using only `[a-z0-9_]`. The trailing 10-character hash is derived from the tool's identity (`server_id`, `server_name`, `name`) and is always present, so a name depends only on that tool and never on which other tools happen to be in the same catalog — adding or removing a sibling never renames a survivor. When the readable prefix would overflow 64 characters it is truncated from the right, so a long server name can leave little or none of the tool name visible; the hash is what distinguishes such tools. Tools from different servers therefore never overwrite each other, and exact duplicate identities are registered once. Each alias provider discovers its own catalog: its tools are named `mcp_<alias>_<server>_<tool>_<hash>`, with the alias name also folded into the hash, and are called with that alias's credentials, so two providers exposing the same server never replace each other's tools. The default `litellm` provider keeps unprefixed names, and diagnostics for an alias read `LiteLLM MCP ("<alias>"):`.
206
213
 
207
- MCP discovery runs after Pi refreshes LiteLLM models or after `/login litellm`; extension activation never waits for it. Discovery accepts at most a 5 MiB response and registers at most 512 tools. The response must be a JSON array of tools or an object with a `tools` array; an `unexpected_error` or unknown non-null `error` in the object envelope, an object without `tools`, and every other shape are reported as discovery failures rather than as empty catalogs. Failure reports use extension-owned text and never include LiteLLM's proxy-supplied tag or `message`. A `partial_failure` envelope keeps and registers the returned tools while reporting one bounded generated diagnostic. Each tool is isolated during normalization, so one bad tool never hides valid siblings. A tool is accepted only when its schema has a root of exactly `"type": "object"` (a bare `properties` object with no `type`, or a type union such as `["object","null"]`, is refused), plain-object `properties`, at most 16 levels of JSON nesting (about eight nested schema objects when each level uses `properties`), and a serialized size of at most 64 KiB. Descriptions are limited to 4 KiB, and tool labels and result metadata to 256 bytes, each with a truncation marker.
214
+ MCP discovery runs once for every configured provider before the first agent turn (so `-p` and other non-interactive modes get MCP tools), after Pi refreshes LiteLLM models, and after `/login litellm`; extension activation never waits for it. Discovery accepts at most a 5 MiB response and registers at most 512 tools. The response must be a JSON array of tools or an object with a `tools` array; an `unexpected_error` or unknown non-null `error` in the object envelope, an object without `tools`, and every other shape are reported as discovery failures rather than as empty catalogs. Failure reports use extension-owned text and never include LiteLLM's proxy-supplied tag or `message`. A `partial_failure` envelope keeps and registers the returned tools while reporting one bounded generated diagnostic. Each tool is isolated during normalization, so one bad tool never hides valid siblings. A tool is accepted only when its schema has a root of exactly `"type": "object"` (a bare `properties` object with no `type`, or a type union such as `["object","null"]`, is refused), plain-object `properties`, at most 16 levels of JSON nesting (about eight nested schema objects when each level uses `properties`), and a serialized size of at most 64 KiB. Descriptions are limited to 4 KiB, and tool labels and result metadata to 256 bytes, each with a truncation marker.
208
215
 
209
216
  ### Which schema a tool ends up with
210
217
 
@@ -256,6 +263,8 @@ If your LiteLLM proxy exposes `/claude-code/marketplace.json`, enabled skills ar
256
263
  - `litellm_skill_create`
257
264
  - `litellm_skill_delete`
258
265
 
266
+ `litellm_skill_create` needs Skill Hub `sourceJson` metadata and a proxy that exposes `/claude-code/plugins`. It does not create skills from code: LiteLLM's `POST /v1/skills` is Anthropic's multipart Skills API.
267
+
259
268
  ## Mocked LiteLLM smoke workflow
260
269
 
261
270
  The `LiteLLM Smoke` GitHub Actions workflow starts VidaiMock and a real LiteLLM proxy on the runner. LiteLLM exposes route-distinct Chat, Responses, native Messages, and mixed-deployment models whose upstreams are served by VidaiMock. The smoke runner discovers those models through LiteLLM, asserts each model's expected API, exercises `/v1/chat/completions`, `/v1/responses`, and `/v1/messages`, verifies the expected `x-litellm-response-cost` behavior, and proves endpoint coverage from captured LiteLLM request logs rather than response text.
@@ -293,9 +302,11 @@ Before tagging a release, keep `package.json` and `package-lock.json` versions i
293
302
 
294
303
  Dynamic catalogs are persisted by Pi in `~/.pi/agent/models-store.json`. Credentials remain in `~/.pi/agent/auth.json`. Legacy `litellm-models.json` model caches are ignored and never deleted. `litellm-models-dev.json` is the models.dev cache and is refreshed in place.
295
304
 
296
- For every genuine `/model/info` row, including deployment details fetched through `/health`, the extension requests `https://models.dev/api.json` for enrichment and caches the result for 28 days in `~/.pi/agent/litellm-models-dev.json`. Health-only entries without deployment details use the bounded Pi catalog lookup without models.dev enrichment. `PI_OFFLINE` suppresses activation-time discovery and the models.dev request. `LITELLM_OFFLINE=1` also disables LiteLLM discovery; direct discovery callers use only an existing models.dev cache and do not refresh it.
305
+ LiteLLM's `/model/info` is the metadata authority, so models.dev enrichment is an opt-in escape hatch. With `LITELLM_MODELS_DEV=1`, for every genuine `/model/info` row, including deployment details fetched through `/health`, the extension requests `https://models.dev/api.json` for enrichment and caches the result for 28 days in `~/.pi/agent/litellm-models-dev.json`. Without it, discovery neither requests models.dev nor reads that cache; Pi's own catalog still applies. Health-only entries without deployment details use the bounded Pi catalog lookup without models.dev enrichment. `PI_OFFLINE` suppresses activation-time discovery and the models.dev request. `LITELLM_OFFLINE=1` also disables LiteLLM discovery; direct discovery callers use only an existing models.dev cache and do not refresh it.
297
306
 
298
- Opening `/model` refreshes configured provider catalogs in the background using Pi's native model lifecycle.
307
+ Opening `/model` refreshes configured provider catalogs in the background using Pi's native model lifecycle when network discovery is enabled.
308
+
309
+ Pi documents `PI_OFFLINE` and `--offline` as disabling automatic network activity, including model catalog refreshes. Pi 0.87.1 adopted that wording to resolve [earendil-works/pi#8684](https://github.com/earendil-works/pi/issues/8684), without changing the behavior. Pi still checks only whether the variable is set, so `PI_OFFLINE=0` and an empty value also disable model refreshes. With `LITELLM_VERBOSE_DISCOVERY=1`, disabled startup discovery reports its reason, for example `startup discovery skipped (PI_OFFLINE)`. To discover models while keeping `PI_OFFLINE`, run `/litellm-refresh`. To allow all discovery for one invocation, use `env -u PI_OFFLINE pi` and do not pass `--offline`. If you only want to disable Pi's version check, use `PI_SKIP_VERSION_CHECK=1` instead; it does not apply offline mode's other network restrictions. See [#155](https://github.com/balcsida/pi-provider-litellm/issues/155).
299
310
 
300
311
  ### Model host enforcement
301
312
 
@@ -318,7 +329,7 @@ Each distinct availability diagnostic is written once per session on stderr. `LI
318
329
 
319
330
  ### Protocols and prompt caching
320
331
 
321
- Discovery selects native Messages for proven Claude groups under the [Model transport](#model-transport) rules, Responses for OpenAI-family backends, and Chat Completions for other OpenAI-compatible backends. An Azure deployment with an explicit `api_version` older than `2025-03-01-preview` stays on Chat Completions; an unset or newer version uses Responses. Azure is detected from the adapter field, an `azure/` or `azure_ai/` model prefix, or the reported provider; other adapters follow the backend family because LiteLLM bridges `/v1/responses` to Chat Completions when the provider has no native Responses config (`litellm/responses/main.py`, `_bridges_to_chat_completions`). A route whose model prefix and `custom_llm_provider` name different providers is treated as unidentified and stays on Chat Completions, so it also does not get the local 128-tool preflight. When `/model/info` supplies `supported_endpoints`, that list takes precedence, and `mode: "responses"` remains an explicit Responses signal. An evidence-free fallback entry—a bare `/v1/models` id or a `/health` entry with no detail row—takes its protocol from the Pi catalog entry for its id; both evidence-free fallback paths also inherit presentation metadata from the bounded catalog lookup. An unknown id stays on Chat Completions. The route name alone authorizes nothing. A concrete id expanded from wildcard `/model/info` routes inherits the deployment evidence of the wildcard route LiteLLM would select for it, with the requested id substituted into the row's `model` the way LiteLLM serves it; the id is omitted when that selected route is not a published chat-style route. Chat Completions and Responses use `<root>/v1`; native Messages uses the proxy root directly. All three protocols pass through the provider's host guard. When an evidence-free cached `(no metadata)` entry can be enriched from the Pi catalog, it is restored on Responses only for a catalog Responses model and otherwise on Chat Completions, never Anthropic Messages. A model supplied only through `models.json` whose `api` this provider does not implement takes Pi's global API fallback rather than this provider's host guard; the credential-root pin (see [Model host enforcement](#model-host-enforcement)) still keeps the credential on the active proxy.
332
+ Discovery selects native Messages for proven Claude groups under the [Model transport](#model-transport) rules, Responses for OpenAI-family backends, and Chat Completions for other OpenAI-compatible backends. Azure and Azure AI deployments stay on Chat Completions unless an explicit Responses mode or a `supported_endpoints` list containing `/v1/responses` authorizes Responses; `api_version` alone does not prove support. Azure is detected from the adapter field, an `azure/` or `azure_ai/` model prefix, or the reported provider; other adapters follow the backend family because LiteLLM bridges `/v1/responses` to Chat Completions when the provider has no native Responses config (`litellm/responses/main.py`, `_bridges_to_chat_completions`). A route whose model prefix and `custom_llm_provider` name different providers is treated as unidentified and stays on Chat Completions, so it also does not get the local 128-tool preflight. When `/model/info` supplies `supported_endpoints`, that list takes precedence, and `mode: "responses"` remains an explicit Responses signal. An evidence-free fallback entry—a bare `/v1/models` id or a `/health` entry with no detail row—takes its protocol from the Pi catalog entry for its id; both evidence-free fallback paths also inherit presentation metadata from the bounded catalog lookup. An unknown id stays on Chat Completions. The route name alone authorizes nothing. A concrete id expanded from wildcard `/model/info` routes inherits the deployment evidence of the wildcard route LiteLLM would select for it, with the requested id substituted into the row's `model` the way LiteLLM serves it; the id is omitted when that selected route is not a published chat-style route. Chat Completions and Responses use `<root>/v1`; native Messages uses the proxy root directly. All three protocols pass through the provider's host guard. When an evidence-free cached `(no metadata)` entry can be enriched from the Pi catalog, it is restored on Responses only for a catalog Responses model and otherwise on Chat Completions, never Anthropic Messages. A model supplied only through `models.json` whose `api` this provider does not implement takes Pi's global API fallback rather than this provider's host guard; the credential-root pin (see [Model host enforcement](#model-host-enforcement)) still keeps the credential on the active proxy.
322
333
 
323
334
  `cacheControlFormat: "anthropic"` applies only to Chat Completions, where Pi adds Anthropic `cache_control` markers. The Responses transport has a different compatibility type and uses native `prompt_cache_key` (plus supported retention fields), so Responses models must not receive `cacheControlFormat`. Freshly discovered OpenAI-family models forced onto Chat Completions are rejected locally when a request contains more than 128 tools; route them through Responses or reduce enabled extensions. Moonshot request-side reasoning suppression follows LiteLLM's routing provider, not `model_info.base_model`; response-side `<think>` normalization follows discovered Kimi-family evidence. Opaque aliases retain display normalization without sending Moonshot-only parameters to Azure- or Bedrock-hosted Kimi models. Strict tool-message repair requires every deployment to identify Kimi; Gemini effort normalization likewise requires consistent backend-family evidence.
324
335
 
@@ -329,8 +340,8 @@ Discovery policy is versioned in Pi's persisted model catalog. After upgrading,
329
340
  LiteLLM may load-balance one public `model_name` across deployments with different backends or model versions. The extension reduces `/model/info` rows conservatively before publishing one Pi model. A route group that mixes a chat-style deployment with an explicitly incompatible mode such as embedding is withheld entirely and reported with a bounded diagnostic.
330
341
 
331
342
  - Responses is selected only when every deployment supports it under the protocol rules above; a deployment that requires Chat keeps the group on Chat.
332
- - Vision and reasoning are advertised only when every routable deployment resolves them as supported. An explicit `supports_reasoning: false` suppresses all thinking controls, even when catalog or router effort metadata exists. Catalog thinking controls are intersected per level: a level is exposed only when every deployment maps it to the same value, while disagreement or absence becomes an explicit denial. Reasoning selectors additionally require an accepted wire carrier on every deployment. Public effort lists are intersected, explicit LiteLLM denials win, and `xhigh`/`max` need unanimous explicit support. Null or absent standard-effort flags have no opinion.
333
- - Context and output limits use the minimum resolved value across deployments.
343
+ - Vision and reasoning are advertised only when every routable deployment resolves them as supported. An explicit `supports_reasoning: false` suppresses all thinking controls, even when catalog or router effort metadata exists. Catalog thinking controls are intersected per level: a level is exposed only when every deployment maps it to the same value, while disagreement or absence becomes an explicit denial. Catalog maps are not complete effort lists, so absence has one exception: an omitted `minimal`, `low`, `medium` or `high` counts as Pi's default spelling of that level. An omitted `off`, `xhigh` or `max` still differs from an explicit mapping. Reasoning selectors additionally require an accepted wire carrier on every deployment. Public effort lists are intersected, explicit LiteLLM denials win, and `xhigh`/`max` need unanimous explicit support. Null or absent standard-effort flags have no opinion. A deployment that declares `model_info.reasoning_effort_levels` answers every level from that list, ahead of its per-level flags, as LiteLLM itself reads it.
344
+ - Context and output limits use the minimum resolved value across deployments. Pi catalogue lookup prefers the deployment's provider-specific entry before falling back to the generic vendor entry; Azure and Azure AI therefore retain Azure-specific limits rather than being capped by a different OpenAI catalogue entry. When models.dev supplies a sparse vendor record, missing fields still use the provider-specific Pi catalogue.
334
345
  - Each displayed base-price field uses the maximum only when every deployment resolves that field; unresolved fields remain zero and the model name is suffixed with ` (incomplete metadata)`.
335
346
  - When complete base pricing comes from the catalog under unanimous catalog authority, tiered pricing is the conservative worst-case envelope. Its usable finite non-negative thresholds are the sorted union of every deployment's thresholds, and each price field at each interval is the maximum applicable rate across all deployments, floored by each deployment's base rate. Differing tier breakpoints are therefore preserved rather than treated as incompatible. An explicit `/model/info` base-price field replaces catalog pricing for that field at every threshold; catalog tiers remain for unaffected fields and are omitted only when every base-price field is explicit.
336
347
  - Reduced route groups omit tier ladders when complete base-pricing or catalog authority is unavailable. Wildcard expansion retains every known tier from matching groups even when another match has incomplete metadata: suppressing a complete sibling's higher tier could understate the known worst-case rate. The ` (incomplete metadata)` marker remains because the resulting envelope is only as complete as the available ladders.
@@ -345,7 +356,9 @@ The ` (incomplete metadata)` suffix marks reduced `/model/info` groups, incomple
345
356
 
346
357
  ### Reasoning controls
347
358
 
348
- Reasoning levels require deployment evidence for the parameter Pi sends: `reasoning_effort` for effort levels or `thinking` for a native thinking switch. Public route names never authorize these controls. Evidence-free fallback models retain catalog presentation metadata but expose no speculative selector.
359
+ Reasoning levels require deployment evidence for the parameter Pi sends: `reasoning_effort` for effort levels or `thinking` for a native thinking switch. Public route names never authorize these controls.
360
+
361
+ LiteLLM omits `supported_openai_params` for a deployment its model map does not describe. Such a deployment keeps the `reasoning_effort` carrier when its `model_info` explicitly sets `supports_reasoning: true`, which is the operator's opt-in. A `supported_openai_params` list that omits `reasoning_effort` still denies effort levels unless `litellm_params.allowed_openai_params` adds it. Kimi and DeepSeek generations are excluded because their contracts name their own carriers. Evidence-free fallback models retain catalog presentation metadata but expose no speculative selector.
349
362
 
350
363
  Kimi K2.5/K2.6 use an on/off thinking switch; K2.7 Code/Highspeed is always thinking. Kimi K3 and DeepSeek V4 use public effort evidence with LiteLLM overrides. Responses levels are translated to valid `reasoning.effort` values; Chat-only compatibility fields never reach Responses models. Legacy cached level maps remain usable while discovery refreshes, and stored Moonshot compatibility can restore safe display normalization.
351
364
 
@@ -356,6 +369,7 @@ The development probe runs against minimized snapshots with `npm run probe:proxy
356
369
  | Symptom | Likely cause |
357
370
  |---|---|
358
371
  | "no credentials" warning at startup | Env vars not set and no OAuth credential — run `/login litellm` |
372
+ | No models, or no new routes, while `PI_OFFLINE` is set | Pi skips every model network refresh, including the one `/model` starts. Run `/litellm-refresh`, or unset `PI_OFFLINE` (`PI_OFFLINE=0` is not enough) |
359
373
  | `No models available` at startup, gone after a restart | A Pi startup race, not discovery — see [`No models available` at startup](#no-models-available-at-startup) |
360
374
  | "discovered no models" | Proxy returned an empty list — check pi's startup log and verify `/model/info`, `/v1/models`, or `/health` responds |
361
375
  | `/model/info` returning 401/403/404 | Expected behavior with virtual keys — extension falls back to `/v1/models` |
@@ -364,6 +378,7 @@ The development probe runs against minimized snapshots with `npm run probe:proxy
364
378
  | A configured or restored model fails to complete but never leaks the credential | Its `api` is absent from the current provider catalog, so Pi used global API fallback with the credential root pinned. Open `/model` against the active proxy to repopulate the protocol — see [Model host enforcement](#model-host-enforcement) |
365
379
  | `LiteLLM discovery: ... route group(s) have missing or conflicting deployment provider evidence` | One or more deployments lack resolvable backend authority or resolve to different providers or concrete catalog models. Add consistent `litellm_params.model`, `model_info.base_model`, or adapter metadata; catalog-derived limits, pricing, and reasoning metadata are withheld meanwhile. This may be intentional for cross-host routes such as Vertex/Bedrock Claude. |
366
380
  | `LiteLLM discovery: ... route group(s) mix chat-style and explicitly incompatible deployment modes` | A public route can select both a chat-style deployment and an incompatible deployment such as an embedding model. Give the embedding deployment its own `model_name`. |
381
+ | `LiteLLM (...): a fallback served "<route>"` | A successful HTTP response reports a LiteLLM router fallback (`x-litellm-attempted-fallbacks`). `/model/info` does not expose fallbacks, so protocol and model handling follow the requested route's own deployments. If the primary and fallback groups support Chat Completions, set `model_info.supported_endpoints: ["/v1/chat/completions"]` on the primary to avoid Responses-to-Chat bridging. This warning does not change routing or fix upstream bridging defects. Warned once per provider and route until the extension reloads; shown in the UI, or stderr without a UI. |
367
382
  | A model is marked ` (incomplete metadata)` | `/model/info` or `/health` did not provide enough authoritative metadata. Explicit fields remain usable, but unknown cost fields are shown as zero and route-name cache enrichment stays disabled. |
368
383
  | `401 Token expired` | Set `LITELLM_API_KEY_HELPER`. |
369
384
  | No models with gcloud auth | Verify `gcloud auth application-default login` has been run or set `GOOGLE_APPLICATION_CREDENTIALS` to an `authorized_user` ADC file |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-provider-litellm",
3
- "version": "3.0.1",
3
+ "version": "3.2.0",
4
4
  "description": "LiteLLM proxy provider extension for Pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,6 +29,10 @@ const PROVIDER_FAMILIES: Readonly<Record<string, BackendFamily>> = {
29
29
  // Prefixes whose keyword match is trustworthy across the whole "prefix/modelId" string because
30
30
  // the prefix itself names a vendor, not just some unrelated string that happens to contain one.
31
31
  const KNOWN_VENDOR_PREFIXES = new Set([...Object.keys(PROVIDER_FAMILIES), "openai"]);
32
+ // First segments that are known to be model path, never a provider: Fireworks' account-scoped
33
+ // ids ("accounts/fireworks/models/x"). An allowlist fails closed: any other differing prefix,
34
+ // recognized provider or not, stays a conflict.
35
+ const MODEL_PATH_SEGMENTS = new Set(["accounts"]);
32
36
  // `o\d` (OpenAI's o1/o3/o4-mini reasoning models) is only trustworthy at the start of the id or
33
37
  // right after a provider path segment — an interior "-o1-" is as likely to be an unrelated
34
38
  // product's own version marker (e.g. "custom-o1-clone").
@@ -62,14 +66,20 @@ export function resolveBackendIdentity(row: BackendIdentityRow): BackendIdentity
62
66
  wireString(row.model_info?.base_model) ?? wireString(row.litellm_params?.model) ?? wireString(row.model_name);
63
67
  if (!raw) return undefined;
64
68
 
65
- const slash = raw.indexOf("/");
69
+ let slash = raw.indexOf("/");
66
70
  const prefix = slash > 0 ? raw.slice(0, slash).trim().toLowerCase() : undefined;
67
- const prefixProvider = prefix && !GENERIC_ADAPTERS.has(prefix) ? prefix : undefined;
71
+ let prefixProvider = prefix && !GENERIC_ADAPTERS.has(prefix) ? prefix : undefined;
68
72
  // `custom_llm_provider` is how LiteLLM routes an unprefixed model. It is provider evidence
69
- // in its own right, so a prefix that names a different provider is a conflict, not a tiebreak.
73
+ // in its own right, so a differing prefix is a conflict, not a tiebreak. The exception is a
74
+ // known model-path segment: LiteLLM routes by custom_llm_provider, so Fireworks'
75
+ // "accounts/fireworks/models/x" is not a provider named "accounts".
70
76
  const custom = wireString(row.litellm_params?.custom_llm_provider)?.toLowerCase();
71
77
  const customProvider = custom && !GENERIC_ADAPTERS.has(custom) ? custom : undefined;
72
- if (prefixProvider && customProvider && prefixProvider !== customProvider) return undefined;
78
+ if (prefixProvider && customProvider && prefixProvider !== customProvider) {
79
+ if (!MODEL_PATH_SEGMENTS.has(prefixProvider)) return undefined;
80
+ prefixProvider = undefined;
81
+ slash = -1;
82
+ }
73
83
  const provider = prefixProvider ?? customProvider;
74
84
  const modelId = slash > 0 ? raw.slice(slash + 1) : raw;
75
85
  // Scan the full "prefix/modelId" string only when the prefix is itself a whole known vendor
package/src/discover.ts CHANGED
@@ -8,9 +8,10 @@ import {
8
8
  catalogResolution,
9
9
  closeSerializerPolicy,
10
10
  conservativeCostTiers,
11
- DEFAULT_CONTEXT_WINDOW,
12
11
  DEFAULT_MAX_TOKENS,
12
+ defaultContextWindow,
13
13
  hasMixedIncompatibleDeploymentModes,
14
+ isFallbackContextWindow,
14
15
  type MessagesBackendCompat,
15
16
  meetVendorCompat,
16
17
  normalizedMode,
@@ -39,6 +40,7 @@ const DEFAULT_TIMEOUT_MS = 5000;
39
40
  const HEALTH_DETAIL_CONCURRENCY = 8;
40
41
  const reportedConflictingFamilyRoutes = new Set<string>();
41
42
  const reportedWithheldRepairRoutes = new Set<string>();
43
+ const reportedDefaultedContextRoutes = new Set<string>();
42
44
  interface HealthDeployment {
43
45
  entry: ModelInfoEntry;
44
46
  denyLevels: boolean;
@@ -148,16 +150,11 @@ function supportsResponses(entry: ModelInfoEntry): boolean {
148
150
  /^azure(?:_ai)?\//.test(configuredModel ?? "") ||
149
151
  reportedProvider === "azure" ||
150
152
  reportedProvider === "azure_ai";
151
- // LiteLLM bridges /v1/responses to chat completions when the provider has no native Responses config
152
- // (litellm/responses/main.py, _bridges_to_chat_completions), so generic adapters remain eligible for Responses.
153
- if (!azureAdapter) return true;
154
-
155
- const apiVersion = entry.litellm_params?.api_version;
156
- if (apiVersion != null && typeof apiVersion !== "string") return false;
157
- const version = apiVersion?.trim();
158
- if (!version) return true;
159
- const date = version.match(/^(\d{4}-\d{2}-\d{2})(?:-preview)?$/)?.[1];
160
- return date !== undefined && date >= "2025-03-01";
153
+ // An Azure API version describes the API surface, not whether this deployment
154
+ // serves Responses. Require the explicit mode/endpoint evidence above instead
155
+ // of promoting a working Chat route to an unavailable endpoint.
156
+ // Generic adapters remain eligible for LiteLLM's Responses-to-Chat bridge.
157
+ return !azureAdapter;
161
158
  }
162
159
 
163
160
  export function modelProtocol(modelId: string, modeOrEntry?: string | null | ModelInfoEntry): ModelProtocol {
@@ -231,7 +228,9 @@ export function enrichCachedModel(input: Model<Api>): Model<Api> {
231
228
  }),
232
229
  } as Model<Api>;
233
230
  // Reduced deployment groups use a distinct marker; this sentinel remains
234
- // exclusive to evidence-free fallback models that may be enriched safely.
231
+ // exclusive to evidence-free fallback models that may be enriched safely. A window is
232
+ // fallback evidence when it matches either default, so a cached entry still qualifies
233
+ // after an operator configures LITELLM_DEFAULT_CONTEXT_WINDOW.
235
234
  if (
236
235
  !model.name.endsWith(" (no metadata)") ||
237
236
  model.reasoning ||
@@ -243,13 +242,15 @@ export function enrichCachedModel(input: Model<Api>): Model<Api> {
243
242
  model.cost.cacheRead !== 0 ||
244
243
  model.cost.cacheWrite !== 0 ||
245
244
  model.cost.tiers !== undefined ||
246
- model.contextWindow !== DEFAULT_CONTEXT_WINDOW ||
245
+ !isFallbackContextWindow(model.contextWindow) ||
247
246
  model.maxTokens !== DEFAULT_MAX_TOKENS
248
247
  ) {
249
248
  return model;
250
249
  }
251
250
  const catalogModel = findCatalogModel(model.id);
252
- if (!catalogModel) return model;
251
+ // The gate above proved this window is an assumption, so it is re-derived rather than
252
+ // restored: the cache is seeded offline, where discovery never re-reads the setting.
253
+ if (!catalogModel) return { ...model, contextWindow: defaultContextWindow() };
253
254
  // Match evidence-free discovery: only an explicit Responses catalog transport
254
255
  // changes the protocol; all other catalog APIs continue through Chat.
255
256
  const api = catalogModel.api === "openai-responses" ? "openai-responses" : "openai-completions";
@@ -399,7 +400,7 @@ function adaptPublicCatalogRecord(
399
400
  catalogModelId: string,
400
401
  record: PublicCatalogRecord | undefined,
401
402
  ): CatalogResolution {
402
- const piProvider = adapterCatalogProvider(record?.provider ?? provider);
403
+ const piProvider = adapterCatalogProvider(record?.piProvider ?? record?.provider ?? provider);
403
404
  const resolved = piProvider
404
405
  ? (resolveCatalogModel(record?.modelId ?? catalogModelId, piProvider) ??
405
406
  resolveCatalogModel(catalogModelId, piProvider))
@@ -597,6 +598,7 @@ function mapFromModelInfoGroup(
597
598
  ambiguousRoutes?: string[];
598
599
  conflictingFamilyRoutes?: string[];
599
600
  withheldRepairRoutes?: string[];
601
+ defaultedContextRoutes?: Set<string>;
600
602
  denyLevels?: boolean;
601
603
  allowMessages?: boolean;
602
604
  } = {},
@@ -618,6 +620,7 @@ function mapFromModelInfoGroup(
618
620
  };
619
621
  });
620
622
  if (!reduced) return undefined;
623
+ if (reduced.contextWindowDefaulted) options.defaultedContextRoutes?.add(reduced.id);
621
624
  if (reduced.catalogAuthorityAmbiguous) options.ambiguousRoutes?.push(reduced.id);
622
625
  if (reduced.deploymentFamilies.includes("conflicting")) options.conflictingFamilyRoutes?.push(reduced.id);
623
626
  const protocols = entries.map((entry) => modelProtocol(reduced.id, entry));
@@ -720,7 +723,7 @@ function mapFromModelsList(entry: ModelsListEntry): DiscoveredModel | undefined
720
723
  }),
721
724
  input: catalogModel?.input ?? ["text"],
722
725
  cost: catalogModel?.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
723
- contextWindow: catalogModel?.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
726
+ contextWindow: catalogModel?.contextWindow ?? defaultContextWindow(),
724
727
  maxTokens: catalogModel?.maxTokens ?? DEFAULT_MAX_TOKENS,
725
728
  api,
726
729
  litellmDiscoveryVersion: LITELLM_DISCOVERY_VERSION,
@@ -1034,6 +1037,7 @@ export async function discoverModels(
1034
1037
  const incompatibleModeRoutes: string[] = [];
1035
1038
  const conflictingFamilyRoutes: string[] = [];
1036
1039
  const withheldRepairRoutes: string[] = [];
1040
+ const defaultedContextRoutes = new Set<string>();
1037
1041
  const reducedGroups = [...groups.entries()].map(([route, group]) => {
1038
1042
  if (hasMixedIncompatibleDeploymentModes(group)) incompatibleModeRoutes.push(route);
1039
1043
  return {
@@ -1042,6 +1046,7 @@ export async function discoverModels(
1042
1046
  ambiguousRoutes,
1043
1047
  conflictingFamilyRoutes,
1044
1048
  withheldRepairRoutes,
1049
+ defaultedContextRoutes,
1045
1050
  }),
1046
1051
  deploymentFamilies: group.map(deploymentFamily),
1047
1052
  };
@@ -1097,7 +1102,27 @@ export async function discoverModels(
1097
1102
  }
1098
1103
  }
1099
1104
  reportWithheldToolRepair(withheldRepairRoutes);
1100
- return { source: "model_info", models: deduplicateModels(models) };
1105
+ models = deduplicateModels(models);
1106
+ if (process.env.LITELLM_VERBOSE_DISCOVERY === "1") {
1107
+ const defaultedWildcards = wildcardRoutes.filter(({ route }) => defaultedContextRoutes.has(route));
1108
+ // Exact routes override wildcard templates; a tighter measured parent can also win.
1109
+ const defaulted = models.filter((model) =>
1110
+ groups.has(model.id)
1111
+ ? defaultedContextRoutes.has(model.id)
1112
+ : defaultedWildcards.some(
1113
+ ({ route, model: parent }) =>
1114
+ parent?.contextWindow === model.contextWindow && wildcardMatches(route, model.id),
1115
+ ),
1116
+ );
1117
+ reportBoundedRoutes(
1118
+ reportedDefaultedContextRoutes,
1119
+ defaulted.map((model) => JSON.stringify(model.id)),
1120
+ (count) =>
1121
+ `LiteLLM discovery: ${count} route(s) default contextWindow to ${defaultContextWindow()}; ` +
1122
+ "set model_info.max_input_tokens on every deployment in each route",
1123
+ );
1124
+ }
1125
+ return { source: "model_info", models };
1101
1126
  }
1102
1127
  if (![401, 403, 404].includes(infoResult.status)) {
1103
1128
  throw new Error(`/model/info returned ${infoResult.status}`);