pi-provider-litellm 4.7.1 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -357,7 +357,7 @@ LiteLLM 1.104.0 and later answer such a request with 422, and earlier releases w
357
357
 
358
358
  A `/model/info` route group uses native Anthropic `/v1/messages` only when every deployment explicitly reports Chat mode, identifies a Claude backend through an Anthropic-, Bedrock-, or Vertex-capable adapter, and every declared backend identity resolves the same Anthropic compatibility policy. A `claude-<name>-<major>-<minor>` backend id resolves through its `claude-<name>-<major>` entry when the exact id is absent; an unknown generation stays on Chat Completions. When `supported_endpoints` is a list, it must include `/v1/messages`; an explicit endpoint list without it keeps the group on Chat Completions. A `null` value, which LiteLLM v1.100 and later report for models absent from their model map, counts as absent. An unresolved routing or base-model identity denies native Messages rather than being discarded from the unanimity check. Mixed-generation Claude groups can use Messages when their serializer policies match, with reasoning levels restricted to their common supported set. Groups with incompatible policies, mixed families, or unknown backend evidence remain on Chat Completions; unanimous explicit Responses mode takes precedence. Routes discovered through `/health` never select native Messages: Messages candidates are downgraded to Chat Completions with reasoning controls closed, while correlated Responses detail remains on Responses. Evidence-free `/v1/models` and wholly health-only `/health` groups take transport and presentation metadata from the bounded Pi catalog lookup: `openai-responses` when the catalog says so, otherwise Chat Completions. They expose no speculative reasoning selector and never select native Messages. Catalog identity such as Amazon Bedrock remains separate from the selected wire protocol.
359
359
 
360
- Native Messages authenticates with `x-api-key`; every transport carries the `x-litellm-session-id` header described above. Strict JSON-schema tools are enabled separately from Messages transport and thinking compatibility: every deployment must affirm support for the actual route/API. Generic `supports_response_schema` and `supports_native_structured_output` metadata does not grant strict tools. Only deployments that LiteLLM reports with the `anthropic` adapter carry that evidence today. Claude served through Bedrock or Vertex therefore uses ordinary tool serialization, and a tool that requires strict sampling fails before the request is sent.
360
+ Native Messages authenticates with `x-api-key`; every transport carries the `x-litellm-session-id` header described above. Strict JSON-schema tools are enabled separately from Messages transport and thinking compatibility: every deployment must affirm support for the actual route/API. Generic `supports_response_schema` and `supports_native_structured_output` metadata does not grant strict tools. Only deployments that LiteLLM reports with the `anthropic` adapter carry that evidence today. Claude served through Bedrock or Vertex therefore uses ordinary tool serialization, and a tool that requires strict sampling fails before the request is sent. The same routing rule applies to managed effort, which adds `thinking.block_binding` and mid-conversation effort markers under their `anthropic-beta` flags: hosted Claude endpoints such as Azure reject that field, so a Messages route with any deployment not routed only through Anthropic declares `supportsMidConvoEffort: false`. Thinking is otherwise unchanged: an adaptive-thinking Claude model still sends `thinking.type: "adaptive"` with the selected level as `output_config.effort`.
361
361
 
362
362
  ## Image generation
363
363
 
@@ -558,7 +558,7 @@ Each distinct availability diagnostic is written once per session on stderr. `LI
558
558
 
559
559
  ### Protocols and prompt caching
560
560
 
561
- 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 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 AI (`azure_ai/` prefix or `custom_llm_provider: azure_ai`) deployments additionally depend on the proxy version. On LiteLLM before v1.103.0, or when the version is unknown, they ignore a `supported_endpoints` list that contains `/v1/responses` and need an explicit `mode: "responses"`: those releases have no native Responses config for that provider, so they bridge `/v1/responses` through Chat Completions, and the bridge fails streaming with `list index out of range` on Azure's empty-choices chunks (BerriAI/litellm#34455) while the endpoint list, copied from the model cost map, still advertises `/v1/responses`. From v1.103.0 the list is honored again. Discovery reads the version from the `x-litellm-version` header of one extra request, `GET /v1/responses/resp_version_probe`, sent only when such a deployment is published; LiteLLM answers it with an error and calls no model. A pre-release counts as older than the release it names, and a proxy that omits the header keeps these deployments on Chat Completions. 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`). The family comes from the model id, not from LiteLLM's `openai/`, `openai_like/` or `custom_openai/` adapter prefix, so `openai/qwen3` stays on Chat Completions while `openai/gpt-5.5` uses Responses; a deployment opts into Responses with `mode: "responses"` or a `supported_endpoints` list containing `/v1/responses`. 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.
561
+ 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 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 AI (`azure_ai/` prefix or `custom_llm_provider: azure_ai`) deployments additionally depend on the proxy version. On LiteLLM before v1.103.0, or when the version is unknown, they ignore a `supported_endpoints` list that contains `/v1/responses` and need an explicit `mode: "responses"`: those releases have no native Responses config for that provider, so they bridge `/v1/responses` through Chat Completions, and the bridge fails streaming with `list index out of range` on Azure's empty-choices chunks (BerriAI/litellm#34455) while the endpoint list, copied from the model cost map, still advertises `/v1/responses`. From v1.103.0 the list is honored again. Discovery reads the version from the `x-litellm-version` header of one extra request, `GET /v1/responses/resp_version_probe`, sent only when such a deployment is published; LiteLLM answers it with an error and calls no model. A pre-release counts as older than the release it names, and a proxy that omits the header keeps these deployments on Chat Completions. 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`). The family comes from the model id, not from LiteLLM's `openai/`, `openai_like/` or `custom_openai/` adapter prefix, so `openai/qwen3` stays on Chat Completions while `openai/gpt-5.5` uses Responses; a deployment opts into Responses with `mode: "responses"` or a `supported_endpoints` list containing `/v1/responses`. 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. A model that reaches the provider with Pi's `azure-openai-responses` API, for example a stored entry taken from Pi's Azure catalog, is served as `openai-responses` at `<root>/v1` with the proxy credential, never with Azure URLs or `api-key` auth; any other API the proxy does not serve is still rejected before a request is sent. 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.
562
562
 
563
563
  `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. Claude-backed routes on native Messages or Chat Completions declare Pi's `promptCache` lifetimes (`short: 300`, `long: 3600` seconds, the values Pi's built-in Anthropic models use), so Pi's `cacheWarming` can keep their caches warm. Responses routes whose every deployment is GPT-5.6 or later and routes through LiteLLM's `openai`, `azure` or `azure_ai` provider declare `short: 1800`, the 30-minute default minimum lifetime OpenAI and Azure document for those models, and no `long` value. Claude routes on Responses, Chat routes to OpenAI models, earlier GPT models, GPT models served through a relay such as OpenRouter or GitHub Copilot, routes identified only by their name, and other backend families declare none, so Pi does not warm them. A `modelOverrides` entry for the route in the global `models.json` can change the values, and `cacheWarming: "off"` disables warming.
564
564
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-provider-litellm",
3
- "version": "4.7.1",
3
+ "version": "4.7.2",
4
4
  "description": "LiteLLM proxy provider extension for Pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,4 +1,4 @@
1
- export const LITELLM_DISCOVERY_VERSION = 10 as const;
1
+ export const LITELLM_DISCOVERY_VERSION = 11 as const;
2
2
 
3
3
  export type BackendFamily = "claude" | "deepseek" | "gemini" | "kimi" | "openai";
4
4
 
package/src/discover.ts CHANGED
@@ -769,6 +769,11 @@ function mapFromModelInfoGroup(
769
769
  ? {
770
770
  ...reduced.messagesCompat,
771
771
  ...(reduced.messagesStrictTools !== undefined ? { supportsStrictTools: reduced.messagesStrictTools } : {}),
772
+ // Managed effort adds thinking.block_binding, which hosted Claude endpoints (Azure among them) reject.
773
+ // LiteLLM reports no per-route support, so only a group routed solely through Anthropic may keep it.
774
+ ...(entries.every((entry) => routesOnlyThrough(entry, ANTHROPIC_ROUTES))
775
+ ? {}
776
+ : { supportsMidConvoEffort: false }),
772
777
  }
773
778
  : undefined;
774
779
  const policy = closeSerializerPolicy({
@@ -447,7 +447,12 @@ export function closeSerializerPolicy(input: {
447
447
  } = input;
448
448
  if (api === "anthropic-messages") {
449
449
  const messagesCompat = vendorCompat as Model<"anthropic-messages">["compat"];
450
- const fields = ["forceAdaptiveThinking", "supportsTemperature", "supportsStrictTools"] as const;
450
+ const fields = [
451
+ "forceAdaptiveThinking",
452
+ "supportsTemperature",
453
+ "supportsStrictTools",
454
+ "supportsMidConvoEffort",
455
+ ] as const;
451
456
  const entries = fields
452
457
  .filter((field) => messagesCompat?.[field] !== undefined)
453
458
  .map((field) => [field, messagesCompat?.[field]]);
package/src/protocols.ts CHANGED
@@ -29,6 +29,16 @@ export function isLiteLLMApi(api: unknown): api is LiteLLMApi {
29
29
  return typeof api === "string" && Object.hasOwn(LITELLM_PROTOCOLS, api);
30
30
  }
31
31
 
32
+ // Pi's Azure Responses API is the OpenAI Responses wire format behind Azure URLs and `api-key` auth. A model can
33
+ // carry it from Pi's Azure catalog, but the proxy serves Responses itself at `<root>/v1` with its own credential.
34
+ const PROXY_API_ALIASES: Readonly<Record<string, LiteLLMApi>> = { "azure-openai-responses": "openai-responses" };
35
+
36
+ /** The protocol the proxy speaks for a model's API, or undefined when the proxy does not serve it. */
37
+ export function toLiteLLMApi(api: unknown): LiteLLMApi | undefined {
38
+ if (isLiteLLMApi(api)) return api;
39
+ return typeof api === "string" && Object.hasOwn(PROXY_API_ALIASES, api) ? PROXY_API_ALIASES[api] : undefined;
40
+ }
41
+
32
42
  export function resolveModelBaseUrl(baseUrl: string, api: LiteLLMApi, allowInsecureHttp = false): string {
33
43
  return LITELLM_PROTOCOLS[api].modelBaseUrl(normalizeBaseUrl(baseUrl, allowInsecureHttp));
34
44
  }
package/src/provider.ts CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  LITELLM_IMAGES_API,
35
35
  type LiteLLMImageModel,
36
36
  } from "./images.js";
37
- import { createLiteLLMProtocolApis, isLiteLLMApi, LITELLM_API_NAMES, resolveModelBaseUrl } from "./protocols.js";
37
+ import { createLiteLLMProtocolApis, LITELLM_API_NAMES, resolveModelBaseUrl, toLiteLLMApi } from "./protocols.js";
38
38
  import type { DiscoveredModel, DiscoveryResult, LiteLLMApi, LiteLLMModel } from "./types.js";
39
39
 
40
40
  export type LiteLLMProviderOptions = {
@@ -149,7 +149,7 @@ function modelRootError(
149
149
  active: { root: string; canonical: string; hostname: string },
150
150
  allowInsecureHttp = false,
151
151
  ): Error | undefined {
152
- if (!isLiteLLMApi(model.api)) {
152
+ if (!toLiteLLMApi(model.api)) {
153
153
  return new Error(
154
154
  `LiteLLM model ${model.id} declares unsupported protocol "${String(model.api)}"; ` +
155
155
  `set "api" to one of ${LITELLM_API_NAMES.join(", ")} in models.json`,
@@ -204,8 +204,9 @@ function requestModel(
204
204
  const active = activeCredentialRoot(credentialRoot, allowInsecureHttp);
205
205
  const error = modelRootError(model, active, allowInsecureHttp);
206
206
  if (error) throw error;
207
+ const api = toLiteLLMApi(model.api)!;
207
208
  const toolCount =
208
- model.api === "openai-completions" && (model as LiteLLMModel).litellmBackendFamily === "openai"
209
+ api === "openai-completions" && (model as LiteLLMModel).litellmBackendFamily === "openai"
209
210
  ? getCurrentTools(context.messages).length
210
211
  : 0;
211
212
  if (toolCount > CHAT_TOOL_CAP) {
@@ -214,7 +215,7 @@ function requestModel(
214
215
  `${CHAT_TOOL_CAP}-tool cap; route this model via Responses or reduce enabled extensions`,
215
216
  );
216
217
  }
217
- return { ...model, provider, baseUrl: resolveModelBaseUrl(active.root, model.api, allowInsecureHttp) };
218
+ return { ...model, api, provider, baseUrl: resolveModelBaseUrl(active.root, api, allowInsecureHttp) };
218
219
  }
219
220
 
220
221
  export function createLiteLLMProvider(options: LiteLLMProviderOptions): Provider<LiteLLMApi> {
@@ -253,10 +254,8 @@ export function createLiteLLMProvider(options: LiteLLMProviderOptions): Provider
253
254
  reportUnavailable(error.message);
254
255
  continue;
255
256
  }
256
- available.push({
257
- ...model,
258
- baseUrl: resolveModelBaseUrl(active.root, model.api, options.allowInsecureHttp),
259
- });
257
+ const api = toLiteLLMApi(model.api)!;
258
+ available.push({ ...model, api, baseUrl: resolveModelBaseUrl(active.root, api, options.allowInsecureHttp) });
260
259
  }
261
260
  return available;
262
261
  };
@@ -413,7 +412,11 @@ export function createLiteLLMProvider(options: LiteLLMProviderOptions): Provider
413
412
  refreshModels: async (context) => {
414
413
  // Pi 0.99 persists models of every type; the policy helpers below read chat-only fields, so
415
414
  // chat, image and classifier entries are restored separately. Other types are not this provider's.
416
- const storedModels = (context.stored?.models ?? []).filter(isChatModel);
415
+ // A stored entry can carry Pi's Azure Responses API; its policy is restored for the protocol the proxy serves.
416
+ const storedModels = (context.stored?.models ?? []).filter(isChatModel).map((model) => {
417
+ const api = toLiteLLMApi(model.api);
418
+ return api && api !== model.api ? { ...model, api } : model;
419
+ });
417
420
  // Image and classifier entries carry no request policy to restore; a stale one is only kept
418
421
  // when startup discovery proved the same route, otherwise the network refresh replaces it.
419
422
  const restoreOperationModels = <T extends AnyModel>(is: (model: AnyModel) => model is T): T[] =>