Repository navigation
feat(model-catalog): candidate rows and pricing snapshot for /v1/messages Claude providers - #52472
Merged
narmstrong-berri merged 6 commits intoNov 23, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
3 of 6 tasks
maciej-berri
force-pushed
the
litellm_cost_model_catalog_rows
branch
from
November 19, 2026 08:23
a077291 to
7e67b16
Compare
3 of 6 tasks
maciej-berri
force-pushed
the
litellm_cost_model_catalog_rows
branch
from
November 20, 2026 21:28
f6d635e to
c019b88
Compare
maciej-berri
marked this pull request as ready for review
November 20, 2026 22:40
Contributor
This was referenced Nov 22, 2026
narmstrong-berri
force-pushed
the
litellm_cost_model_catalog_rows
branch
from
November 23, 2026 18:27
c019b88 to
e5675c0
Compare
narmstrong-berri
force-pushed
the
litellm_cost_model_catalog_rows
branch
from
November 23, 2026 19:07
e5675c0 to
35c7f0a
Compare
narmstrong-berri
approved these changes
Nov 23, 2026
narmstrong-berri
left a comment
Contributor
There was a problem hiding this comment.
LGTM overall. Some minor changes
narmstrong-berri
force-pushed
the
litellm_cost_model_catalog_rows
branch
from
November 23, 2026 20:37
35c7f0a to
3f32986
Compare
narmstrong-berri
enabled stacked auto-merge (squash)
November 23, 2026 20:47
Adjustments now carry the geo multipliers and the speed: fast multiplier main reads out of provider_specific_entry, so the Rust pricing core can apply them from the lowered row.
…ages Claude providers Snapshot::candidates ports main's row choice for a finished call (select_model_name_for_cost_calc, the completion_cost candidate loop, cost_per_token key normalisation and the get_model_info walk) for anthropic, bedrock, bedrock_mantle, azure_ai and vertex_ai. Every call main would price by another path comes back Deferred so Python keeps it. A Snapshot reads a host's live table through LiveTable, keyed on the model cost version and the cost discount and margin config identities, and lowers rows lazily with a cache keyed by row object. Deployment rows are exposed by id as RowRef with Registered provenance. The Bedrock model id helpers move here from litellm-llms, which re-exports them, so routes and lookups share one copy. Parity is pinned by 48 calls whose rows main billed and tried were captured once.
NativeModelCostMap::cost_snapshot hands out the model-catalog Snapshot of the published table for its current generation. LiveRow is the snapshot's row, identified by the row object, and invalidate() also forgets cached rows so changed_in_place() and registration passes reread them. The host module gains generation() and known_names(), the two facts only Python has. The row-to-fields reader is shared with NativePrices.
…the Python snapshot into python-bridge The shared core now reads a host table through CatalogView (key, folded key, fields, registered_fields, lowered) plus an immutable PricingContext, and resolve/ runs on a borrowed CostLookup. Generation, the swap-on-change manager and the identity-keyed row cache move to python-bridge, which keeps lowerings by row contents so a price edited in place in litellm.model_cost is billed on the next call. Catalog implements the view, so the Rust host resolves through the same path.
…log into litellm-cost model-catalog keeps the general lookups (exact key, folded key, the get_model_info walk, lowered rows) and implements litellm-cost's new CandidateTable with row facts only. The walk, its row and deferral types and the Bedrock profile rule now live in litellm_cost::candidates, so the catalog holds no completion_cost billing rules. The parity tests stay in model-catalog because litellm-cost cannot see a catalog.
…efusal, move the walk parity tests under resolve/tests
narmstrong-berri
force-pushed
the
litellm_cost_model_catalog_rows
branch
from
November 23, 2026 21:47
3f32986 to
13b06ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handwritten 1-3 sentence description
[insert handwritten description here]
Details
TLDR
This is layer 2 of a stack under the Rust cost port. Layer 1 (
litellm_cost_generic_on_main, the base of this PR) carries #51566 rebased onto main and has its own draft PR #52816. Layer 3 (the pricing core, bridge and Python adapter) builds on this one.Problem this solves:
/v1/messagesClaude callslitellm.model_costthat never bills a stale priceHow it solves it:
litellm_cost::candidatesprovider_specific_entrygeo and speed upliftsHow the pieces split
Model Catalog answers table questions only.
CatalogViewis the read interface a host implements (exact key, folded key, a row's fields, itsregistered_fields, andlowered, which by default lowers the row each time), andPricingContextis the immutable rest (capability rules, provider names, renamed models).resolve/keeps theget_model_infoname walk (names.rs,lookupinmod.rs) and the Bedrock id spellings.CatalogimplementsCatalogView, so the Rust host resolves through the same code with no Python.completion_cost's candidate walk (which names to try, in which order, deployment rows by id, the provider to bill as, when to defer) moved to
litellm-costascandidates/. It reads a catalog only through litellm-cost'sCandidateTabletrait, which Model Catalog implements overCostLookup, so litellm-cost never depends on Model Catalog. The parity tests againstcost_candidates.jsonstay in Model Catalog (resolve/candidate_walk.rs) because that is the only crate that sees both, and the fixture is unchanged.python-bridge keeps the Python-shaped parts: the generation read from Python, the snapshot that is swapped when it moves, and the row cache. The cache used to key converted rows by Python object identity, so
litellm.model_cost["x"]["input_cost_per_token"] = 2e-6after a call was priced kept billing the old rate. It now keeps each lowering with the fields it came from and reuses it only while the row reads the same fields, and each pricing call reads every row once so it sees one version of it.Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
E2E exception at a077291. Nothing calls the new code yet. The pricing core and the native Messages hand-off that use it land in the next layer of the stack, so there is no user flow to run before and after, and no live provider keys were available for this work. The proof is parity against main's own answers instead.
Main's choices were captured once from
litellm.completion_cost(call_type="anthropic_messages")at main 532df6e plus #51566, withLITELLM_LOCAL_MODEL_COST_MAP=TrueandNativePricesspied, for 48 realistic calls across native Anthropic, Bedrock invoke (cross-region profiles,invoke/,claude_platform/, region paths,bedrock/mantle/), Bedrock Mantle with and without a region, Azure AI with and withoutbase_model, and Vertex AI with@versionand@default. Each case records the row main bills and, with every pricing attempt forced to fail, every row main falls through in order. The Rust test asserts the same rows in the same order, then whether main would go on to a path that is left to Python. All 48 match. A second capture registers aregister_modelprice on a Bedrock row a cross-region profile reaches, and the Rust rows match main there too, with and without custom pricing. A new test resolves every fixture call over the Rust host'sCatalogand over the Python-shaped table of the same document and asserts the same rows.Commands and results
Mutation checks, each applied to the source, run against
cargo test -p litellm-model-catalog --lib, then reverted. All nine were caught. Keeping main's candidate order without moving rule-only names last fails 4 fixture cases. Skipping the Mantle region key failsmantle_gov_region_row. Dropping the Bedrock cross-region profile rule failsbedrock_profile_over_served_base_id. Pricing a Bedrockregister_modelprice through the normal lookup fails the registration case. Ignoring the row provider match fails 20 cases. Dropping the served-model preference fails 4 cases. Stripping only one repeated provider prefix failsanthropic_thrice_repeated_prefix. Keeping the Mantle region in the split name fails the names test, and dropping the geo lowering fails 4 lowering and snapshot tests.Restack
On 2026-11-19 the whole stack was rebased onto main, and layer 1 now has its own draft PR #52816.
On 2026-11-20 the snapshot and the candidate walk were split as described in "How the pieces split", and this PR's new tip is f6d635ee49. At that tip and at the two PRs above it, the cost, model-catalog, inference-messages and python-bridge Rust tests pass (python-bridge's logger test needs the venv's Python, as before), clippy and fmt are clean, the
cost_candidates.jsonparity cases pass unchanged, and the in-place edit regression test in #52484 fails on the old tip and passes now. A rerun of the native/v1/messagesSDK A/B set for Anthropic, Bedrock invoke and Azure AI (1080 calls) gives costs identical to the earlier run.Type
🆕 New Feature
🧹 Refactoring
Caveats (if any)
Medium
Deferred, so Python keeps pricing themAGENTS.mdLow
litellm-llmsinto model-catalog,llmsre-exports them. The two the billing walk needs (routing prefix strip and the cross-region profile check) live inlitellm_cost::candidates::bedrockand Model Catalog re-exports them, since the rest needslitellm-auth-awsmake checkcould not installlitellm-admin-mcp(403) or run the dashboard API sync withoutnode_modulestype_check_gatecould not provision its environment for the same reasonFinal Attestation