Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
`model_info.base_model` or public-route prefix still withholds identity, bar the `accounts` model-path segment; never
reinterpret those as a namespace. Reduce every deployment before choosing
transport, capabilities, limits, prices, or catalog authority; never shallow-merge duplicate route rows.
- `model_info.pricing_provider` (LiteLLM v1.109.0+) is the operator naming the catalog whose rows price a deployment,
so `resolveCatalogProvider` returns it ahead of every inference, including the conflicts that otherwise withhold an
identity (a deployment id equal to another provider's catalog key, such as `baseten/zai-org/GLM-5.2` routed through
`custom_llm_provider: openai`). A conflict withholds the identity in `resolveBackendIdentity` before that helper is
reached, so `resolveModelInfoCatalog` re-reads the row without its `custom_llm_provider` to get the bare model id the
declared catalog is keyed by; without that the declared provider never prices the rows it exists for. It settles the
catalog only, so the identity stays withheld for family and routing, and `routesOnlyThrough` must keep ignoring it.
LiteLLM itself falls back to `custom_llm_provider` when it is unset. The Go port mirrors it.
- Keep catalog lookup provider-aware. Unqualified or conflicting identities must not scan every Pi provider catalog.
- `supported_endpoints` pins transport except for `azure_ai` deployments on a proxy older than LiteLLM v1.103.0 or of
unknown version. Those releases bridge them to Chat Completions regardless of that cost-map list, so they take
Expand All @@ -65,15 +73,15 @@
for a deployment LiteLLM reports as `anthropic` through `base_model`) takes native Messages only when
`litellm_params.model` contains `claude` (LiteLLM picks its native config by that name alone) and the proxy reports
v1.80.12 or later (`AZURE_AI_MESSAGES_FLOOR`; v1.80.10 and v1.80.11 send `api-key` where Azure wants `x-api-key`,
earlier releases bridge to Chat). `publishesVersionGatedTransport` probes for it only when the group would be
earlier releases bridge to Chat). `publishesVersionGatedBehavior` probes for it only when the group would be
published on Messages at that floor.
- When the version was asked for and could not be read, `reportUnreadProxyVersion` names the routes that stay on Chat
Completions, once per route and process like the other route diagnostics. A readable version below a floor is not
reported. Collect the routes where the probe is decided, so the warning and the probe cannot disagree.
- When the version was asked for and could not be read, `reportUnreadProxyVersion` names the routes that keep the
conservative fallback, once per route and process like the other route diagnostics. A readable version below a floor
is not reported. Collect the routes where the probe is decided, so the warning and the probe cannot disagree.
- `toLiteLLMApi` (`protocols.ProxyAPI` in Go) maps a model's API to the protocol the proxy serves: the three LiteLLM APIs, plus Pi's `azure-openai-responses` as `openai-responses`. The stored-model restore, `filterModels` and the stream guard all go through it, so an Azure catalog API never selects Azure URLs or auth against the proxy; any other API stays rejected. The startup seed reader (`src/models-store.ts`, `models_store.go`) stays strict: a store holding such an entry is discovered again instead of seeded.
- Version-gated workarounds read the proxy version through `src/proxy-version.ts`. An unknown version satisfies no
floor, so every gate fails toward the workaround, and a pre-release orders before the release it names. Probe only
when a published deployment's outcome depends on the version (`publishesVersionGatedTransport`), at most once per
when a published deployment's outcome depends on the version (`publishesVersionGatedBehavior`), at most once per
discovery: the probe draws an error reply, so an unconditional one would add a failed request to every operator's
logs. A listed deployment is not yet a published one: a withheld group publishes nothing, and a wildcard route
publishes nothing until `/v1/models` expands it, so its probe waits for the expansion. `scripts/probe-proxy.ts`
Expand Down Expand Up @@ -199,16 +207,29 @@
- A declared `reasoning_effort_levels` list answers every level for its deployment, ahead of the per-level flags.
- Catalog level maps are tristate, not complete lists: an omitted standard level keeps Pi's default.
- Null/absent flags have no opinion; explicit denials win and extended effort levels need explicit support. A router flag is the more specific evidence, so an explicit `true` grants a level over a catalog map that denies it.
- `thinking_always_on` denies Pi's `off` level outright, and `thinking_on_by_default` denies it below LiteLLM v1.110.0
(`THINKING_DISABLE_FLOOR`), which is the release that turns `reasoning_effort: "none"` into
`thinking: {"type": "disabled"}`; earlier releases sent nothing, so the backend kept thinking and billing it. Both
are read in `reportedLevel` ahead of the declared `reasoning_effort_levels` list, because an accepted `none` still
does not stop the thinking, so they reach the Chat, Responses and native Messages level maps alike. Pi's Anthropic
catalog already denies `off` for always-on Claude, but its Bedrock and other hosted catalogs do not, which is where
this evidence lands. A think-by-default route makes `publishesVersionGatedBehavior` probe on its own, with no
transport gate, but only where the published `off` level actually differs across the floor: a sibling that always
thinks denies it at every version, and probing for that would add a failed request and a warning explaining nothing.
The Go port mirrors both.
- Close thinking levels against the protocol and accepted carrier actually used after wildcard expansion. Responses compatibility contains only Responses fields.
- GPT-5.5 and later reject `reasoning_effort` with function tools on Chat Completions. Discovery sets `litellmPolicy.dropToolReasoning` for Chat routes when any deployment's backend id (never the route name) is GPT-5.5+, and wildcard combinators take any parent's flag: dropping reasoning only degrades a request, keeping it fails one. The request hook uses the route name only for a model without `litellmBackendFamily` evidence. It sends the model's declared `thinkingLevelMap.off` effort, and without one omits the field, except under `explicitToolReasoningOff` (GPT-6+ backend evidence, or the route name without evidence), which sends `none` because GPT-6 falls back to its default effort when the field is omitted. `off: null` from `NO_TRANSMISSIBLE_LEVELS` means no carrier evidence, not a model that cannot turn reasoning off.

## Compatibility Rules

- Provider-specific request compatibility belongs in discovered model `compat` metadata, not broad runtime mutation.
- `promptCache: { short: 300, long: 3600 }` (Pi's built-in Anthropic values) needs unanimous Claude backend evidence plus Messages, or Chat with `cacheControlFormat: "anthropic"`. Never Responses, route text, or the `/v1/models` fallback; wildcard children inherit it; the Go port mirrors it.
- Any deployment whose `supports_prompt_caching` is explicitly `false` withholds every `promptCache` block
(`deniesPromptCache`), whatever its family documents: a relay can host a Claude or GPT generation that bills no
cache (`kyma/claude-fable-5`). An absent flag is not a denial. The Go port mirrors it.
- `promptCache: { short: 1800 }` (OpenAI's and Azure's documented 30-minute default minimum for GPT-5.6 and later) needs every deployment's backend id, never the route name, to be OpenAI-family GPT-5.6+, routed (`routesOnlyThrough`) only through `openai`, `azure` or `azure_ai`, on Responses only. Relays such as OpenRouter or Copilot document no lifetime of their own. No `long`: the 12-hour lifetime needs `prompt_cache_options.ttl`, which Pi's long retention does not send. Same inheritance and Go mirror as the Claude rule.
- Native Messages requires unanimous compatible Claude deployment evidence; evidence-free fallback and health discovery never select it. Keep Messages compatibility separate from Chat and Responses fields.
- Native Messages routes declare `supportsMidConvoEffort: false` unless every deployment routes only through Anthropic (`routesOnlyThrough`, as for strict tools): managed effort sends `thinking.block_binding` with its betas, and hosted Claude endpoints (Azure among them) reject it. `closeSerializerPolicy` keeps that field so the offline cache does not drop the denial; the Go port mirrors both.
- Native Messages routes declare `supportsMidConvoEffort: false` unless every deployment routes only through Anthropic (`routesOnlyThrough`, as for strict tools), or only through `azure_ai` on a proxy reporting LiteLLM v1.109.0 or later (`AZURE_AI_THINKING_BINDING_FLOOR`), the release that stopped dropping the `thinking-binding-controls-2026-08-01` beta header on the way to Foundry: managed effort sends `thinking.block_binding` with its betas, and a hosted Claude endpoint rejects it without that header. Read the azure_ai grant from declared routing, never `routesThroughAzureAi`, whose `model_info.litellm_provider` arm is a cost-map lookup: a Bedrock-routed deployment priced through an Azure row reaches Bedrock, where the beta means nothing. Those groups already probe for the Messages floor, so the gate adds no request. No release is evidence for Bedrock or Vertex, which stay denied. `closeSerializerPolicy` keeps that field so the offline cache does not drop the denial; the Go port mirrors both.
- Strict tools require every deployment's declared routing (`custom_llm_provider` and the `litellm_params.model` prefix) to name Anthropic. `model_info.litellm_provider` is a cost-map lookup of `base_model`, not routing, and `supports_response_schema` / `supports_native_structured_output` describe JSON output, not tool definitions; neither is strict-tool evidence.
- Chat Completions `strict` tool schemas: since Pi 0.87 the `openai-completions` default for unknown endpoints is
`supportsStrictMode: false`, so LiteLLM Chat routes send no `strict` field. Pi only ever sent `strict: true` for tools
Expand Down
2 changes: 1 addition & 1 deletion pig/PORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ aliases come from settings and from the multi-provider environment variables, as
- **Claude on Azure AI Foundry.** `azure_ai` is in `claudeCapableAdapters` like the TypeScript
`CLAUDE_CAPABLE_ADAPTERS`, under the same two conditions: the configured model contains `claude`
(`isAzureAIClaudeDeployment`, LiteLLM's own test for its native config) and the proxy reports v1.80.12 or later
(`azureAIMessagesFloor`). `publishesVersionGatedTransport` asks for the version only when the group would be
(`azureAIMessagesFloor`). `publishesVersionGatedBehavior` asks for the version only when the group would be
published on Messages at that floor, and never for `/health` groups, which never select Messages. The same
rule binds a hosted deployment reported as `anthropic` through `base_model` (`routesThroughAzureAI`), and
`reportUnreadProxyVersion` prints the TypeScript warning when the version was asked for and could not be read.
Expand Down
8 changes: 8 additions & 0 deletions pig/extensions/litellm/internal/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ func ResolveIdentity(entry types.ModelInfoEntry) *Identity {

// ResolveCatalogProvider is resolveCatalogProvider; "" means undefined.
func ResolveCatalogProvider(entry types.ModelInfoEntry) string {
// model_info.pricing_provider (LiteLLM 1.109.0+) is the operator naming the catalog that prices
// this deployment. It outranks every inference, and it is a pricing statement, not routing
// evidence, so RoutesOnlyThrough keeps ignoring it.
if entry.ModelInfo != nil {
if priced := strings.ToLower(strings.TrimSpace(entry.ModelInfo.PricingProvider)); priced != "" {
return priced
}
}
row := fieldsOf(entry)
identity := ResolveIdentity(entry)
if identity != nil && identity.Provider != "" && !genericCatalogProviders[identity.Provider] {
Expand Down
36 changes: 35 additions & 1 deletion pig/extensions/litellm/internal/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestResolveBackendIdentity(t *testing.T) {
t.Errorf("%s should not be OpenAI", id)
}
}
if DiscoveryVersion != 16 {
if DiscoveryVersion != 17 {
t.Errorf("DiscoveryVersion = %d", DiscoveryVersion)
}
})
Expand Down Expand Up @@ -340,6 +340,40 @@ func TestResolveCatalogProvider(t *testing.T) {
})
}

func TestResolveCatalogProviderPricingProvider(t *testing.T) {
t.Run("takes a declared pricing_provider over every inference, including a conflicting one", func(t *testing.T) {
// LiteLLM 1.109.0+: the operator names the catalog that prices the deployment.
got := ResolveCatalogProvider(types.ModelInfoEntry{
ModelInfo: &types.ModelInfoDetails{BaseModel: "zai-org/GLM-5.2", LiteLLMProvider: "openai", PricingProvider: "baseten"},
LiteLLMParams: &types.ModelInfoParams{Model: "openai/zai-org/GLM-5.2", CustomLLMProvider: "openai"},
})
if got != "baseten" {
t.Errorf("got %q", got)
}
// Trimmed and lowercased like the other wire providers, and a blank one changes nothing.
got = ResolveCatalogProvider(types.ModelInfoEntry{ModelInfo: &types.ModelInfoDetails{BaseModel: "gpt-5.2", PricingProvider: " BaseTen "}})
if got != "baseten" {
t.Errorf("got %q", got)
}
got = ResolveCatalogProvider(types.ModelInfoEntry{ModelInfo: &types.ModelInfoDetails{BaseModel: "anthropic/claude-sonnet-5-5", PricingProvider: " "}})
if got != "anthropic" {
t.Errorf("got %q", got)
}
})
t.Run("keeps pricing_provider out of routing evidence", func(t *testing.T) {
row := types.ModelInfoEntry{
ModelInfo: &types.ModelInfoDetails{BaseModel: "claude-sonnet-5-5", PricingProvider: "anthropic"},
LiteLLMParams: &types.ModelInfoParams{Model: "bedrock/claude-sonnet-5-5", CustomLLMProvider: "bedrock"},
}
if got := ResolveCatalogProvider(row); got != "anthropic" {
t.Errorf("got %q", got)
}
if RoutesOnlyThrough(row, map[string]bool{"anthropic": true}) {
t.Error("pricing_provider reached routing evidence")
}
})
}

func TestRoutesOnlyThrough(t *testing.T) {
anthropic := map[string]bool{"anthropic": true}
t.Run("requires every declared routing signal to name an allowed provider", func(t *testing.T) {
Expand Down
52 changes: 41 additions & 11 deletions pig/extensions/litellm/internal/discover/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ func messagesCompatOf(model *ai.GeneratedModel) *modelgroups.MessagesBackendComp

var anthropicRoutes = map[string]bool{"anthropic": true}

// azureAIRoutes is declared routing, not model_info.litellm_provider, which is a cost-map lookup of
// base_model: a Bedrock-routed deployment priced through an Azure row must not claim Foundry's beta handling.
var azureAIRoutes = map[string]bool{"azure_ai": true}

// messagesStrictToolEvidence: the Anthropic catalog describes the Anthropic API, so only deployments
// whose declared routing names Anthropic keep its grant. A hosted route (Bedrock, Vertex) can reject
// tools[].strict for the same model, and LiteLLM reports no per-route strict-tool capability, so it
Expand Down Expand Up @@ -508,21 +512,32 @@ func ResolveModelInfoCatalog(entry types.ModelInfoEntry, publicCatalog catalog.P
return nil
}
identity := backend.ResolveIdentity(entry)
// A declared pricing_provider settles which catalog prices the row, so the provider conflict that
// withheld the identity no longer decides this lookup. Re-read the row without its routing claim, the
// half the conflict was about, for the bare model id that catalog is keyed by. Only the catalog is
// settled: the identity stays withheld for family and routing decisions.
priced := ""
if entry.ModelInfo != nil {
priced = lowerTrim(entry.ModelInfo.PricingProvider)
}
if identity == nil && priced != "" {
unrouted := entry
if entry.LiteLLMParams != nil {
params := *entry.LiteLLMParams
params.CustomLLMProvider = ""
unrouted.LiteLLMParams = &params
}
identity = backend.ResolveIdentity(unrouted)
if identity == nil {
return nil
}
return lookupCatalog(entry, publicCatalog, priced, identity.ModelID, priced+"/"+identity.ModelID)
}
if identity == nil {
return nil
}
lookup := func(provider string) *modelgroups.CatalogResolution {
var record *catalog.PublicCatalogRecord
if publicCatalog != nil {
record = publicCatalog.Lookup(provider, identity.ModelID)
}
resolution := adaptPublicCatalogRecord(provider, identity.QualifiedID, record)
if native, ok := nativeMessagesCatalog(entry); ok {
resolution.MessagesCompat = native.MessagesCompat
resolution.MessagesStrictTools = native.MessagesStrictTools
resolution.MessagesThinkingLevelMap = native.MessagesThinkingLevelMap
}
return &resolution
return lookupCatalog(entry, publicCatalog, provider, identity.ModelID, identity.QualifiedID)
}
if provider := backend.ResolveCatalogProvider(entry); provider != "" {
return lookup(provider)
Expand All @@ -533,6 +548,21 @@ func ResolveModelInfoCatalog(entry types.ModelInfoEntry, publicCatalog catalog.P
return lookup(publicCatalogProviderByFamily[identity.Family])
}

// lookupCatalog prices an entry from one provider's catalog row, keeping its native Messages fields.
func lookupCatalog(entry types.ModelInfoEntry, publicCatalog catalog.PublicCatalog, provider, modelID, qualifiedID string) *modelgroups.CatalogResolution {
var record *catalog.PublicCatalogRecord
if publicCatalog != nil {
record = publicCatalog.Lookup(provider, modelID)
}
resolution := adaptPublicCatalogRecord(provider, qualifiedID, record)
if native, ok := nativeMessagesCatalog(entry); ok {
resolution.MessagesCompat = native.MessagesCompat
resolution.MessagesStrictTools = native.MessagesStrictTools
resolution.MessagesThinkingLevelMap = native.MessagesThinkingLevelMap
}
return &resolution
}

// awaitEnrichmentWithinBudget is awaitEnrichmentWithinBudget: it returns the zero value when the budget
// elapses first, and ctx's error when ctx ends first.
func awaitEnrichmentWithinBudget[T any](ctx context.Context, result <-chan T, budget time.Duration) (T, error) {
Expand Down
6 changes: 3 additions & 3 deletions pig/extensions/litellm/internal/discover/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func discoverFromModelInfo(
}
var versionGatedRoutes []string
for _, route := range groups.routes {
if !strings.Contains(route, "*") && publishesVersionGatedTransport(groups.rows[route], publicCatalog, true) {
if !strings.Contains(route, "*") && publishesVersionGatedBehavior(groups.rows[route], publicCatalog, true) {
versionGatedRoutes = append(versionGatedRoutes, route)
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func discoverFromModelInfo(
continue
}
parents := selectedWildcardRows(entry.ID, wildcardRows, publishedWildcardIDs)
if parents != nil && publishesVersionGatedTransport(parents, publicCatalog, true) {
if parents != nil && publishesVersionGatedBehavior(parents, publicCatalog, true) {
versionGatedRoutes = append(versionGatedRoutes, entry.ID)
expansionAwaitsProxyVersion = true
}
Expand Down Expand Up @@ -490,7 +490,7 @@ func discoverFromHealth(ctx context.Context, base, apiKey string, options Option
var versionGatedRoutes []string
for _, route := range groups.routes {
// Health discovery never selects Messages, so only Responses can await the version.
if publishesVersionGatedTransport(entriesOf(groups.rows[route]), publicCatalog, false) {
if publishesVersionGatedBehavior(entriesOf(groups.rows[route]), publicCatalog, false) {
versionGatedRoutes = append(versionGatedRoutes, route)
}
}
Expand Down
Loading