Fix pricing lookup for retired Claude models

LiteLLM removed claude-3-5-sonnet-20241022 from its cost database.
Add alias fallback map so retired model names resolve to current
equivalents for pricing lookups.
This commit is contained in:
chopratejas 2026-03-12 21:11:18 -07:00
parent 4bea17ba8a
commit d2e88d362a
2 changed files with 21 additions and 2 deletions

View file

@ -13,6 +13,16 @@ from typing import Any
import litellm
# Aliases for models removed from LiteLLM's cost database (retired/renamed).
# Maps old model name -> current LiteLLM key that has equivalent pricing.
_MODEL_ALIASES: dict[str, str] = {
# Claude 3.5 Sonnet retired Feb 2026, pricing same as claude-sonnet-4-20250514
"claude-3-5-sonnet-20241022": "claude-sonnet-4-20250514",
"claude-3-5-sonnet-20240620": "claude-sonnet-4-20250514",
# Claude 3 Sonnet retired
"claude-3-sonnet-20240229": "claude-3-haiku-20240307",
}
@dataclass
class LiteLLMModelPricing:
@ -61,6 +71,12 @@ def get_model_pricing(model: str) -> LiteLLMModelPricing | None:
info = cost_data[f"{prefix}{model}"]
break
# Try retired/renamed model aliases (LiteLLM removes old model keys over time)
if info is None:
alias = _MODEL_ALIASES.get(model)
if alias:
info = cost_data.get(alias)
if info is None:
return None

View file

@ -240,11 +240,14 @@ class TestBuiltInModels:
info = get_model_info("claude-3-5-sonnet-20241022")
assert info.provider == "anthropic"
assert info.context_window == 200000
# Pricing is now fetched from LiteLLM
pricing = ModelRegistry.get_pricing("claude-3-5-sonnet-20241022")
# Pricing fetched from LiteLLM (falls back to alias for retired models)
pricing = ModelRegistry.get_pricing("claude-sonnet-4-20250514")
assert pricing is not None
assert pricing[0] == 3.00 # input cost per 1M
assert pricing[1] == 15.00 # output cost per 1M
# Retired model alias should also resolve
alias_pricing = ModelRegistry.get_pricing("claude-3-5-sonnet-20241022")
assert alias_pricing is not None
def test_gemini_info(self):
"""Test Gemini model info."""