From 35798b6f0bb3354bb6712b738876b67286b0cf6a Mon Sep 17 00:00:00 2001 From: Anuj7411 Date: Sun, 9 Aug 2026 02:43:55 +0530 Subject: [PATCH 1/2] fix(lowest_cost): resolve provider-prefixed model pricing via get_model_info --- litellm/router_strategy/lowest_cost.py | 7 +++++ .../local_testing/test_lowest_cost_routing.py | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/litellm/router_strategy/lowest_cost.py b/litellm/router_strategy/lowest_cost.py index b927df0c438..5ce2734acf0 100644 --- a/litellm/router_strategy/lowest_cost.py +++ b/litellm/router_strategy/lowest_cost.py @@ -246,6 +246,13 @@ class LowestCostLoggingHandler(CustomLogger): ) item_litellm_model_name = _deployment.get("litellm_params", {}).get("model") item_litellm_model_cost_map = litellm.model_cost.get(item_litellm_model_name, {}) + if not item_litellm_model_cost_map and item_litellm_model_name: + try: + item_litellm_model_cost_map = dict( + litellm.get_model_info(model=item_litellm_model_name) + ) + except Exception: + item_litellm_model_cost_map = {} # check if user provided input_cost_per_token and output_cost_per_token in litellm_params item_input_cost = None diff --git a/tests/local_testing/test_lowest_cost_routing.py b/tests/local_testing/test_lowest_cost_routing.py index 4e8b06fb628..c6813174dab 100644 --- a/tests/local_testing/test_lowest_cost_routing.py +++ b/tests/local_testing/test_lowest_cost_routing.py @@ -49,6 +49,36 @@ async def test_get_available_deployments(): assert selected_model["model_info"]["id"] == "groq-llama" +@pytest.mark.asyncio +async def test_get_available_deployments_provider_prefixed_model_pricing(): + test_cache = DualCache() + model_list = [ + { + "model_name": "gpt-3.5-turbo", + "litellm_params": {"model": "openai/gpt-4o-mini"}, + "model_info": {"id": "prefixed-openai"}, + }, + { + "model_name": "gpt-3.5-turbo", + "litellm_params": { + "model": "azure/some-custom-deployment", + "input_cost_per_token": 0.5, + "output_cost_per_token": 0.5, + }, + "model_info": {"id": "custom-priced"}, + }, + ] + lowest_cost_logger = LowestCostLoggingHandler( + router_cache=test_cache, + ) + + selected_model = await lowest_cost_logger.async_get_available_deployments( + model_group="gpt-3.5-turbo", healthy_deployments=model_list + ) + + assert selected_model["model_info"]["id"] == "prefixed-openai" + + @pytest.mark.asyncio async def test_get_available_deployments_custom_price(): from litellm._logging import verbose_router_logger From 8beb5622c93199c16cd7fd89521992a7f0285473 Mon Sep 17 00:00:00 2001 From: Anuj7411 Date: Sun, 9 Aug 2026 02:56:28 +0530 Subject: [PATCH 2/2] fix(lowest_cost): honor an explicit zero custom price instead of the fallback --- litellm/router_strategy/lowest_cost.py | 4 +-- .../local_testing/test_lowest_cost_routing.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/litellm/router_strategy/lowest_cost.py b/litellm/router_strategy/lowest_cost.py index 5ce2734acf0..9e50122d69f 100644 --- a/litellm/router_strategy/lowest_cost.py +++ b/litellm/router_strategy/lowest_cost.py @@ -257,10 +257,10 @@ class LowestCostLoggingHandler(CustomLogger): # check if user provided input_cost_per_token and output_cost_per_token in litellm_params item_input_cost = None item_output_cost = None - if _deployment.get("litellm_params", {}).get("input_cost_per_token", None): + if _deployment.get("litellm_params", {}).get("input_cost_per_token") is not None: item_input_cost = _deployment.get("litellm_params", {}).get("input_cost_per_token") - if _deployment.get("litellm_params", {}).get("output_cost_per_token", None): + if _deployment.get("litellm_params", {}).get("output_cost_per_token") is not None: item_output_cost = _deployment.get("litellm_params", {}).get("output_cost_per_token") if item_input_cost is None: diff --git a/tests/local_testing/test_lowest_cost_routing.py b/tests/local_testing/test_lowest_cost_routing.py index c6813174dab..b52d5d47cfd 100644 --- a/tests/local_testing/test_lowest_cost_routing.py +++ b/tests/local_testing/test_lowest_cost_routing.py @@ -79,6 +79,40 @@ async def test_get_available_deployments_provider_prefixed_model_pricing(): assert selected_model["model_info"]["id"] == "prefixed-openai" +@pytest.mark.asyncio +async def test_get_available_deployments_zero_custom_price_is_honored(): + test_cache = DualCache() + model_list = [ + { + "model_name": "gpt-3.5-turbo", + "litellm_params": { + "model": "anthropic/claude-3-5-haiku-latest", + "input_cost_per_token": 0, + "output_cost_per_token": 0, + }, + "model_info": {"id": "byok-zero-cost"}, + }, + { + "model_name": "gpt-3.5-turbo", + "litellm_params": { + "model": "azure/some-custom-deployment", + "input_cost_per_token": 0.5, + "output_cost_per_token": 0.5, + }, + "model_info": {"id": "custom-priced"}, + }, + ] + lowest_cost_logger = LowestCostLoggingHandler( + router_cache=test_cache, + ) + + selected_model = await lowest_cost_logger.async_get_available_deployments( + model_group="gpt-3.5-turbo", healthy_deployments=model_list + ) + + assert selected_model["model_info"]["id"] == "byok-zero-cost" + + @pytest.mark.asyncio async def test_get_available_deployments_custom_price(): from litellm._logging import verbose_router_logger