fix: strip Bedrock version pin suffix (:0) in CostService model lookup#6817
Open
zhoufengen wants to merge 1 commit into
Open
fix: strip Bedrock version pin suffix (:0) in CostService model lookup#6817zhoufengen wants to merge 1 commit into
zhoufengen wants to merge 1 commit into
Conversation
Bedrock returns model names with a version pin suffix (e.g. anthropic.claude-opus-4-6-v1:0) but the pricing database only has the base name (anthropic.claude-opus-4-6-v1). This causes total_estimated_cost to be None for these models. Added stripVersionSuffix() that removes :<digits> from the end of model names, with fallback lookup in findModelPrice(). The fix is generic and handles all Bedrock models with version pin suffixes without requiring duplicate entries in the auto-synced pricing JSON. Fixes comet-ml#5130
Comment on lines
+149
to
+153
| // Try stripping version suffix (e.g., ":0") from model names. | ||
| // Bedrock model names often include a version pin (e.g., "anthropic.claude-opus-4-6-v1:0") | ||
| // where the pricing database only has the base name ("anthropic.claude-opus-4-6-v1"). | ||
| String withoutVersionOriginal = stripVersionSuffix(modelName); | ||
| if (!withoutVersionOriginal.equalsIgnoreCase(modelName)) { |
Contributor
There was a problem hiding this comment.
The date- and version-suffix fallbacks look duplicated here; should we extract a helper that takes a suffix-stripping function and handles the shared lookup/normalization steps?
Finding type: Code Dedup and Conventions | Severity: 🟢 Low
Want Baz to fix this for you? Activate Fixer
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.
Summary
Bedrock returns model names with a version pin suffix (e.g.
anthropic.claude-opus-4-6-v1:0) but the pricing database only has the base name (anthropic.claude-opus-4-6-v1). This causestotal_estimated_costto beNonefor these models.Previously, the fix (#6787) attempted to add
:0variant entries tomodel_prices_and_context_window.json, but that file is auto-synced from upstream LiteLLM — manual edits would be overwritten on the next sync.This PR takes the correct approach: fix
CostService.findModelPrice()to strip the version pin suffix (:\d+$) during model name lookup, so Bedrock model names with:0automatically fall back to the base pricing entry.The fix is generic and handles all Bedrock models with version pin suffixes without requiring any changes to the auto-synced pricing JSON.
Changes
VERSION_SUFFIX_PATTERNconstant (:\d+$) andstripVersionSuffix()method. Added fallback lookup infindModelPrice()that strips the version suffix from the original model name before looking up pricing.calculateCost_shouldStripVersionSuffixwith 3 test cases covering:0suffix, global variant, and models without suffix (backwards compatibility).Test plan
anthropic.claude-opus-4-6-v1:0→ cost found (version suffix stripped)global.anthropic.claude-opus-4-6-v1:0→ cost found (version suffix stripped)anthropic.claude-opus-4-6-v1→ cost found (exact match, backwards compatible)Fixes #5130