This commit is contained in:
Anuj ojha 2026-08-27 20:01:45 -05:00 • committed by GitHub
commit 4b17754eaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -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(

View file

@ -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"})