fix(pricing): strip Bedrock version/date suffix before cost lookup - #62320
fix(pricing): strip Bedrock version/date suffix before cost lookup#62320pgregg88 wants to merge 1 commit into
Conversation
Bedrock foundation-model IDs returned by ListFoundationModels and inference profiles carry a trailing revision suffix that the bare `_OFFICIAL_DOCS_PRICING` keys don't have: a release date (`-20250514`), a Bedrock model version (`-v1`), and/or a minor revision (`:0`) — e.g. `anthropic.claude-sonnet-4-5-20250929-v1:0` or `anthropic.claude-opus-4-6-v1`. `_lookup_official_docs_pricing` does an exact dict-key match on the normalized name, so any id carrying that suffix misses its bare row and the session prices as `unknown` even though the row exists. This is the `-v1` facet of NousResearch#50295 (distinct from the cache-cost-fields facet in open PR NousResearch#46299 and the cross-region-prefix facet already handled). `_normalize_bedrock_model_name` already strips the region prefix and normalizes dot-notation versions; this adds a trailing-suffix strip anchored to the end. The pattern only matches an 8-digit date, `-vN`, and `:N`, so the model version itself (`-4-6` / `-4-8`) is never eaten. Tests: two regression tests in test_usage_pricing.py — one asserting every suffixed shape (with/without cross-region prefix) resolves to the same entry as the bare id (invariant, not a frozen dollar value), one asserting the normalizer preserves the model version and bare provider IDs. Full file: 17 passed.
|
Thanks for the focused regression fix. The premise is confirmed on current remote main: The proposed anchored suffix normalization is appropriately scoped to the existing Bedrock pricing-normalization path, preserves bare model-version components, and the added tests assert lookup equivalence rather than fixed price snapshots. GitHub reports the PR mergeable against current main. Automated hermes-sweeper review. |
|
Merged via PR #67976. Your suffix-strip fix duplicated PR #50437 (@Osraka, submitted June 21 — the earlier submission, so their commits were cherry-picked as the base), and the sonnet-5 pricing row from your sibling PR #62327 had already landed via #67932. Note on attribution: your commits were authored under a placeholder identity ( |
Problem
Bedrock foundation-model IDs returned by
ListFoundationModelsand inference profiles carry a trailing revision suffix that the bare_OFFICIAL_DOCS_PRICINGkeys don't have:-20250514-v1:0e.g.
anthropic.claude-sonnet-4-5-20250929-v1:0oranthropic.claude-opus-4-6-v1._lookup_official_docs_pricingdoes an exact dict-key match on the normalized name._normalize_bedrock_model_namestrips the region prefix (us./global./…) and normalizes dot-notation versions, but does not strip that trailing suffix — so any id carrying it misses its bare pricing row and the session reportsTotal cost: unknowneven though the row exists.Reproduce on
mainFix
Add a trailing-suffix strip to
_normalize_bedrock_model_name, anchored to the end of the string. It only matches an 8-digit date,-vN, and:N— so the model version itself (-4-6/-4-8) is never eaten, and non-Claude provider IDs (amazon.nova-pro-v1:0→amazon.nova-pro) collapse correctly too.Scope / relation to other work
This is the
-v1/date-suffix facet of #50295. It is distinct from and non-overlapping with:cache_read/cache_writecost fields to existing Bedrock Claude rows. That edits existing rows; this fixes key matching. No conflict.us./global./eu.) — already handled in_normalize_bedrock_model_nameand covered bytest_bedrock_cross_region_profile_prefix_resolves_to_pricing.It does not add the missing current-gen rows (opus-4-8/4-7, sonnet-5) — that needs authoritative commercial (non-GovCloud) pricing numbers and is left for a separate change / maintainer with those figures.
Tests
Two regression tests in
tests/agent/test_usage_pricing.py:test_bedrock_version_suffix_resolves_to_pricing— asserts every suffixed shape (with/without cross-region prefix) resolves to the same entry as the bare id (an invariant, not a frozen dollar value, per the repo's "behavior contracts over snapshots" guidance).test_bedrock_version_suffix_normalizer_preserves_model_version— asserts the stripper preserves the model version and bare provider IDs.tests/agent/test_usage_pricing.py: 17 passed. Ruff clean on both files.