Spaces:
Build error
Build error
Commit ·
89d649c
1
Parent(s): 5a87378
Fix pricing lookup for retired Claude models
Browse filesLiteLLM 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.
- headroom/pricing/litellm_pricing.py +16 -0
- tests/test_models.py +5 -2
headroom/pricing/litellm_pricing.py
CHANGED
|
@@ -13,6 +13,16 @@ from typing import Any
|
|
| 13 |
|
| 14 |
import litellm
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
@dataclass
|
| 18 |
class LiteLLMModelPricing:
|
|
@@ -61,6 +71,12 @@ def get_model_pricing(model: str) -> LiteLLMModelPricing | None:
|
|
| 61 |
info = cost_data[f"{prefix}{model}"]
|
| 62 |
break
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
if info is None:
|
| 65 |
return None
|
| 66 |
|
|
|
|
| 13 |
|
| 14 |
import litellm
|
| 15 |
|
| 16 |
+
# Aliases for models removed from LiteLLM's cost database (retired/renamed).
|
| 17 |
+
# Maps old model name -> current LiteLLM key that has equivalent pricing.
|
| 18 |
+
_MODEL_ALIASES: dict[str, str] = {
|
| 19 |
+
# Claude 3.5 Sonnet retired Feb 2026, pricing same as claude-sonnet-4-20250514
|
| 20 |
+
"claude-3-5-sonnet-20241022": "claude-sonnet-4-20250514",
|
| 21 |
+
"claude-3-5-sonnet-20240620": "claude-sonnet-4-20250514",
|
| 22 |
+
# Claude 3 Sonnet retired
|
| 23 |
+
"claude-3-sonnet-20240229": "claude-3-haiku-20240307",
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
|
| 27 |
@dataclass
|
| 28 |
class LiteLLMModelPricing:
|
|
|
|
| 71 |
info = cost_data[f"{prefix}{model}"]
|
| 72 |
break
|
| 73 |
|
| 74 |
+
# Try retired/renamed model aliases (LiteLLM removes old model keys over time)
|
| 75 |
+
if info is None:
|
| 76 |
+
alias = _MODEL_ALIASES.get(model)
|
| 77 |
+
if alias:
|
| 78 |
+
info = cost_data.get(alias)
|
| 79 |
+
|
| 80 |
if info is None:
|
| 81 |
return None
|
| 82 |
|
tests/test_models.py
CHANGED
|
@@ -240,11 +240,14 @@ class TestBuiltInModels:
|
|
| 240 |
info = get_model_info("claude-3-5-sonnet-20241022")
|
| 241 |
assert info.provider == "anthropic"
|
| 242 |
assert info.context_window == 200000
|
| 243 |
-
# Pricing
|
| 244 |
-
pricing = ModelRegistry.get_pricing("claude-
|
| 245 |
assert pricing is not None
|
| 246 |
assert pricing[0] == 3.00 # input cost per 1M
|
| 247 |
assert pricing[1] == 15.00 # output cost per 1M
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
def test_gemini_info(self):
|
| 250 |
"""Test Gemini model info."""
|
|
|
|
| 240 |
info = get_model_info("claude-3-5-sonnet-20241022")
|
| 241 |
assert info.provider == "anthropic"
|
| 242 |
assert info.context_window == 200000
|
| 243 |
+
# Pricing fetched from LiteLLM (falls back to alias for retired models)
|
| 244 |
+
pricing = ModelRegistry.get_pricing("claude-sonnet-4-20250514")
|
| 245 |
assert pricing is not None
|
| 246 |
assert pricing[0] == 3.00 # input cost per 1M
|
| 247 |
assert pricing[1] == 15.00 # output cost per 1M
|
| 248 |
+
# Retired model alias should also resolve
|
| 249 |
+
alias_pricing = ModelRegistry.get_pricing("claude-3-5-sonnet-20241022")
|
| 250 |
+
assert alias_pricing is not None
|
| 251 |
|
| 252 |
def test_gemini_info(self):
|
| 253 |
"""Test Gemini model info."""
|