fix(utils): prefer regional inference-profile price over stripped base price - #30331
Conversation
…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
Greptile SummaryThis PR fixes a mispricing bug where
Confidence Score: 5/5Safe 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.
|
| 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
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: Happy to rebase or address anything if it helps. Thanks! |
|
Closing this — the same fix landed independently in #32389 ( Regional pricing for For anyone landing here from the original report: the behaviour is fixed as of |
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:0resolved toanthropic.claude-sonnet-4-5-20250929-v1:0(us, $3.0/M input) instead ofau.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) beforesplit_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_modellookup 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 oftests/local_testing/test_get_model_info.pystays green.Fixes #27612