diff --git a/litellm/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.py index bdbaee00c19..7ba932458e5 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/utils.py +++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py @@ -126,7 +126,7 @@ def select_cost_metric_for_model( """ if model_info.get("input_cost_per_character"): return "cost_per_character" - elif model_info.get("input_cost_per_token"): + elif model_info.get("input_cost_per_token") is not None: return "cost_per_token" else: raise ValueError( diff --git a/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py b/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py index ce90719789a..bd78702d6cb 100644 --- a/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py +++ b/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py @@ -3841,3 +3841,18 @@ def test_generic_cost_per_token_grok_46_long_context(_local_model_cost_map): ) assert prompt_cost == pytest.approx(200_000 * 4e-06 + 50_000 * 1e-06) assert completion_cost == pytest.approx(1_000 * 1.2e-05) + + +def test_select_cost_metric_for_model_treats_zero_token_cost_as_priced(): + from litellm.litellm_core_utils.llm_cost_calc.utils import select_cost_metric_for_model + + free_model = {"key": "free-model", "input_cost_per_token": 0.0} + assert select_cost_metric_for_model(free_model) == "cost_per_token" + + char_model = {"key": "char-model", "input_cost_per_character": 1e-6, "input_cost_per_token": 0.0} + assert select_cost_metric_for_model(char_model) == "cost_per_character" + + import pytest + + with pytest.raises(ValueError): + select_cost_metric_for_model({"key": "no-pricing"})