Skip to content

fix(tests): derive the priced Claude model from litellm's catalog by capability - #19

Merged
Mearman merged 1 commit into
mainfrom
fix/pricing-test-candidates
Oct 11, 2026
Merged

Mearman merged 1 commit into
mainfrom
fix/pricing-test-candidates

Conversation

@Mearman

@Mearman Mearman commented Oct 11, 2026

Copy link
Copy Markdown
Member

CI on main has stopped at test collection since litellm's price data changed: tests/test_cost_card_attribution.py and tests/test_savings_provider_matrix.py raise "litellm prices none of the candidate models" at import, so every test shard fails, and three further tests fail on main for the same reason. Issues are disabled on this repo, so the explanation is here.

The candidates in tests/_pricing_models.py are not retired. They are all still in litellm.model_cost, but the first-party claude-* rows no longer carry the *_above_200k_tokens tier fields (the 1M-context beta that carried that premium is gone from the catalog; those rows now have max_input_tokens of 200000). The tests ask for input_cost_per_token_above_200k_tokens, so the helper found nothing. Swapping in another first-party id cannot work, because none has the field. The only claude rows that still carry it are the Bedrock and Vertex AI ones, for example claude-sonnet-4-5-20250929-v1:0 and vertex_ai/claude-sonnet-4-5.

test_long_context_derives_the_one_hour_rate_and_says_so and the two above-200k cases of TestLongContextPricing::test_litellm_path are the same cause: they used claude-sonnet-4-5 and assumed the catalog charges a second tier for it, which it no longer does for that row. The product code is correct there (it reads the catalog), so this PR is test-only.

The helper now scans the catalog for Claude rows that have the requested fields instead of walking a hardcoded list (first-party rows first, then unqualified ids, then alphabetical, so the pick is deterministic). The two long-context tests request a tiered row. test_models.py::test_claude_info compared the picked model against a literal $3/$15, which only held while the list happened to start at Sonnet 4.5, so it now compares against the catalog's numbers.

Not changed: _LONG_CONTEXT_TIERED_MODELS in headroom/providers/anthropic.py still applies a 2x premium on the manual fallback path for Sonnet 4/4.5 above 200K, which now disagrees with the first-party catalog. That is product behaviour and needs its own decision, so I left it.

Real behavior proof

Setup: worktree of this branch, env -u HTTPS_PROXY -u NO_PROXY -u no_proxy -u https_proxy uv sync --frozen --extra dev, litellm price data as installed from uv.lock at the time of the run.

Before (origin/main): the old helper called with the field the tests need.

AssertionError: litellm prices none of the candidate models with the fields
['input_cost_per_token', 'input_cost_per_token_above_200k_tokens', 'output_cost_per_token']

All four ids still in the catalog still lack that field. On main,
pytest tests/test_counterfactual_pricing.py tests/test_providers/test_anthropic.py::TestLongContextPricing
gives 3 failures (assert 3e-06 > 3e-06; 0.975 == 1.9125; 0.57 == 1.1025).

After (this branch):

env -u HTTPS_PROXY -u NO_PROXY -u no_proxy -u https_proxy .venv/bin/python -m pytest -q -p no:cacheprovider \
  tests/test_models.py tests/test_counterfactual_pricing.py tests/test_providers/test_anthropic.py \
  tests/test_cost_card_attribution.py tests/test_savings_provider_matrix.py
125 passed

The neighbouring pricing tests that use the same helper (test_cost_budget_basis, test_cost_tracker_counterfactual, test_savings_ledger, test_cost_pricing_warning_dedup) also pass. The full suite was not run locally; that is what CI is for.

…capability

The first-party claude-* rows in litellm's price map no longer carry the
*_above_200k_tokens tier fields, so no id in the hardcoded candidate list
satisfied a test asking for a long-context tier and two test modules failed at
collection. Only the Bedrock and Vertex AI Claude rows still carry the tier.

anthropic_pricing_model now scans litellm.model_cost for Claude rows that have
the requested fields, preferring Anthropic's own rows, then ids without a
provider or region qualifier, then alphabetical order, so retiring an id or a
field never needs a list edit. The long-context tests in
test_counterfactual_pricing and TestLongContextPricing::test_litellm_path ask
for a tiered row instead of naming claude-sonnet-4-5, and test_models compares
the registry against the catalog instead of a literal $3/$15.
@Mearman
Mearman marked this pull request as ready for review October 11, 2026 22:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-11T23:03:20.724920Z ce8f69e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Mearman
Mearman merged commit 7d10584 into main Oct 11, 2026
22 checks passed
@Mearman
Mearman deleted the fix/pricing-test-candidates branch October 11, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant