Skip to content

fix: strip Bedrock version pin suffix (:0) in CostService model lookup#6817

Open
zhoufengen wants to merge 1 commit into
comet-ml:mainfrom
zhoufengen:fix/bedrock-version-suffix-costservice
Open

fix: strip Bedrock version pin suffix (:0) in CostService model lookup#6817
zhoufengen wants to merge 1 commit into
comet-ml:mainfrom
zhoufengen:fix/bedrock-version-suffix-costservice

Conversation

@zhoufengen
Copy link
Copy Markdown
Contributor

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 causes total_estimated_cost to be None for these models.

Previously, the fix (#6787) attempted to add :0 variant entries to model_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 :0 automatically 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

  • CostService.java: Added VERSION_SUFFIX_PATTERN constant (:\d+$) and stripVersionSuffix() method. Added fallback lookup in findModelPrice() that strips the version suffix from the original model name before looking up pricing.
  • CostServiceTest.java: Added parameterized test calculateCost_shouldStripVersionSuffix with 3 test cases covering :0 suffix, global variant, and models without suffix (backwards compatibility).

Test plan

  • All 55 existing CostService tests pass
  • New tests verify:
    • 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

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
@zhoufengen zhoufengen requested a review from a team as a code owner May 21, 2026 14:51
@github-actions github-actions Bot added java Pull requests that update Java code Backend tests Including test files, or tests related like configuration. labels May 21, 2026
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)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend java Pull requests that update Java code tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Opus 4.6 via Bedrock does not price

1 participant