Skip to content

fix(utils): prefer regional inference-profile price over stripped base price - #30331

Closed
Ewertonslv wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Ewertonslv:fix/bedrock-regional-inference-profile-price
Closed

fix(utils): prefer regional inference-profile price over stripped base price#30331
Ewertonslv wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Ewertonslv:fix/bedrock-regional-inference-profile-price

Conversation

@Ewertonslv

Copy link
Copy Markdown
Contributor

Summary

get_model_info() returned the base (us) price for a Bedrock regional inference profile even when a region-specific entry exists in the cost map.

For example, bedrock/au.anthropic.claude-sonnet-4-5-20250929-v1:0 resolved to anthropic.claude-sonnet-4-5-20250929-v1:0 (us, $3.0/M input) instead of au.anthropic.claude-sonnet-4-5-20250929-v1:0 (au, $3.3/M input), which IS present in the map.

Root cause

In _get_model_info_helper, the candidate lookup tried the region-stripped names (combined_stripped_model_name, stripped_model_name) before split_model, which keeps the regional prefix. The stripped base key matched first, so the regional entry (checked last) was never reached.

Fix

Move the split_model lookup ahead of the stripped lookups, so a region-specific price wins — falling back to the stripped base price only when no regional entry exists. The provider-match guard is preserved on each branch, and the stripped fallback (fine-tuned models, or regions without a dedicated entry) is unchanged.

Test

Added test_get_model_info_bedrock_region_uses_regional_price, which asserts the regional key and its price are returned. It fails on the current base and passes with this change; the rest of tests/local_testing/test_get_model_info.py stays green.

Fixes #27612

…e price

get_model_info() looked up the region-stripped model name before the un-stripped split_model, so a Bedrock regional inference profile such as 'bedrock/au.anthropic.claude-sonnet-4-5-20250929-v1:0' resolved to the base (us) price even when the 'au.' keyed entry exists in the cost map. Move the split_model lookup ahead of the stripped lookups so a region-specific price wins, falling back to the stripped base price only when no regional entry exists.

Fixes BerriAI#27612
@CLAassistant

CLAassistant commented Jun 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a mispricing bug where get_model_info() returned the stripped base-model price for Bedrock regional inference profiles (e.g. au.*) even when a region-specific entry existed in the cost map, because the stripped-name lookups ran before split_model. The fix reorders the three fallback lookups in _get_model_info_helper so the exact split_model key is tried first, with stripped names as a fallback for models that have no dedicated regional entry.

  • litellm/utils.py: Swaps lookup priority so step 3 tries split_model (the region-prefixed name), step 4 tries combined_stripped_model_name, and step 5 tries stripped_model_name; the provider-match guard and fallback chain are unchanged.
  • tests/local_testing/test_get_model_info.py: Adds test_get_model_info_bedrock_region_uses_regional_price asserting that bedrock/au.anthropic.claude-sonnet-4-5-20250929-v1:0 resolves to the AU regional key and its input_cost_per_token, using the local bundled cost map (no network calls).

Confidence Score: 5/5

Safe to merge — a narrow, well-scoped reordering of three lookup candidates that preserves all existing fallback paths.

The reordering is logically correct: split_model (exact regional key) running before stripped names means a dedicated regional entry wins, while the absence of such an entry falls through naturally to the stripped base price, just as before. Both existing tests (including the one that explicitly pops the regional key to exercise the stripped fallback) and the new regional-price test verify the two scenarios. Fine-tuned model lookup is unaffected because split_model for those contains the full suffix and is not in the cost map, so the chain falls through to stripped_model_name as expected.

No files require special attention.

Important Files Changed

Filename Overview
litellm/utils.py Reorders lookup steps 3–5 in _get_model_info_helper so split_model (region-specific key) is tried before the stripped base-name candidates, ensuring regional Bedrock inference profile prices are not silently overridden by the stripped base price.
tests/local_testing/test_get_model_info.py Adds test_get_model_info_bedrock_region_uses_regional_price to assert the regional key and its price are returned; uses LITELLM_LOCAL_MODEL_COST_MAP to avoid network calls, matching the existing test pattern in this file.

Reviews (1): Last reviewed commit: "fix(utils): prefer regional inference-pr..." | Re-trigger Greptile

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Ewertonslv

Copy link
Copy Markdown
Contributor Author

Friendly ping — this one's green (71/71 checks, CLA signed) and has been waiting on a review for a few weeks.

It's a narrow fix: get_model_info() was returning the stripped base-model price for Bedrock regional inference profiles (e.g. au.*) even when a region-specific price exists in the map, so those calls were being costed wrong. Covered by a test that fails before the change and passes after.

Happy to rebase or address anything if it helps. Thanks!

@Ewertonslv

Copy link
Copy Markdown
Contributor Author

Closing this — the same fix landed independently in #32389 (734fd29e0, LIT-4056), which reorders the _get_model_info_helper lookup ladder to try split_model before combined_stripped_model_name / stripped_model_name, exactly as proposed here, and additionally strips the bedrock routing prefix in _get_potential_model_names.

Regional pricing for au.* / eu.* / apac.* inference profiles now resolves correctly on the default branch, so this PR is superseded (and conflicts on precisely those lines).

For anyone landing here from the original report: the behaviour is fixed as of 734fd29e0.

@Ewertonslv Ewertonslv closed this Jul 17, 2026
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.

[Bug]: Regional inference profile prefix stripped when storing Bedrock model, causing wrong-region prices in UI

2 participants