Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(cost): price base_model deployments past rule-only cost map entries (#47497)

Kerry Lu8d2bf426f59f
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py
index 20914df8fe2..e8ca60e00af 100644
--- a/litellm/cost_calculator.py
+++ b/litellm/cost_calculator.py
@@ -1642,7 +1642,7 @@ def completion_cost(
*(((model, request_pricing_provider),) if model is not None else ()),
)
potential_model_names: Final = (
- raw_candidates if explicit_pricing else _priced_candidates_before_unpriced_rules(raw_candidates)
+ raw_candidates if custom_pricing is True else _priced_candidates_before_unpriced_rules(raw_candidates)
)
for idx, (model, pricing_provider) in enumerate(potential_model_names):
diff --git a/tests/unit/test_cost_calculator.py b/tests/unit/test_cost_calculator.py
index fee4db586cd..2854f9010b2 100644
--- a/tests/unit/test_cost_calculator.py
+++ b/tests/unit/test_cost_calculator.py
@@ -391,6 +391,38 @@ def test_completion_cost_bills_undated_azure_data_zone_base_model_at_its_dated_r
)
+def test_completion_cost_prices_rule_only_base_model_from_the_response_model(
+ _local_model_cost_map: None,
+ _price_free_gpt_family_generalization: None,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """LIT-9812: a deployment whose base_model is an undated name only a capability rule matches must not
+ stop the ladder at $0 when the response names a priced model"""
+ monkeypatch.setattr(
+ litellm,
+ "model_cost",
+ {
+ "azure/gpt-9.9-2026-01-01": {
+ "litellm_provider": "azure",
+ "mode": "chat",
+ "input_cost_per_token": 0.0000111,
+ "output_cost_per_token": 0.0000222,
+ }
+ },
+ )
+ usage: Final = Usage(prompt_tokens=17, completion_tokens=9, total_tokens=26)
+ response: Final = ModelResponse(model="gpt-9.9-2026-01-01", choices=[], usage=usage)
+
+ cost: Final = completion_cost(
+ completion_response=response,
+ model="azure/my-eu-deployment",
+ custom_llm_provider="azure",
+ base_model="azure/eu/gpt-9.9",
+ )
+
+ assert cost == pytest.approx(usage.prompt_tokens * 0.0000111 + usage.completion_tokens * 0.0000222)
+
+
def test_completion_cost_orders_candidates_without_extra_huggingface_config_requests(
_local_model_cost_map: None,
) -> None: