mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix(cost): treat an explicit zero input_cost_per_token as priced, not missing
This commit is contained in:
parent
4fd7a73ef5
commit
4efea1f7d8
2 changed files with 16 additions and 1 deletions
|
|
@ -112,7 +112,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(
|
||||
|
|
|
|||
|
|
@ -3345,3 +3345,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"})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue