From 8d2bf426f59ffbda9aaa49608706aee4acb93395 Mon Sep 17 00:00:00 2001 From: Kerry Lu Date: Tue, 20 Oct 2026 09:26:38 -0700 Subject: [PATCH] fix(cost): price base_model deployments past rule-only cost map entries (#47497) * fix(cost): price base_model deployments past rule-only cost map entries and warn when base_model has no rates * fix(router): warn on unpriced base_model from add_deployment too and honour model_info prices * refactor(cost): drop the unpriced base_model startup warning, keep the one-line ladder fix --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/cost_calculator.py | 2 +- tests/unit/test_cost_calculator.py | 32 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) 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: