fix(cost): keep size buckets for Together registry rows without pricing

This commit is contained in:
mateo-berri 2026-08-25 17:09:12 -07:00
parent ac866e98c8
commit abe9af622b
3 changed files with 18 additions and 4 deletions

View file

@ -77,7 +77,7 @@ from litellm.llms.tencent.cost_calculator import (
)
from litellm.llms.together_ai.cost_calculator import (
get_model_params_and_category,
has_together_registry_entry,
has_together_registry_pricing,
)
from litellm.llms.vertex_ai.cost_calculator import (
cost_per_character as google_cost_per_character,
@ -1556,7 +1556,7 @@ def completion_cost(
# Calculate cost based on prompt_tokens, completion_tokens
if (
"togethercomputer" in model or "together_ai" in model or custom_llm_provider == "together_ai"
) and not has_together_registry_entry(model, litellm.model_cost):
) and not has_together_registry_pricing(model, litellm.model_cost):
model = get_model_params_and_category(model, call_type=CallTypes(call_type))
# replicate llms are calculate based on time for request running

View file

@ -19,9 +19,10 @@ from litellm.constants import (
from litellm.types.utils import CallTypes
def has_together_registry_entry(model: str, cost_map: Mapping[str, object]) -> bool:
def has_together_registry_pricing(model: str, cost_map: Mapping[str, object]) -> bool:
stripped: Final = model.removeprefix("together_ai/")
return f"together_ai/{stripped}" in cost_map
entry: Final = cost_map.get(f"together_ai/{stripped}")
return isinstance(entry, Mapping) and "input_cost_per_token" in entry
# Extract the number of billion parameters from the model name

View file

@ -3838,3 +3838,16 @@ def test_completion_cost_together_unmapped_model_still_uses_size_bucket(_local_m
)
assert cost == pytest.approx((23 + 15) * 9e-07, rel=1e-9)
def test_completion_cost_together_metadata_only_model_still_uses_size_bucket(_local_model_cost_map):
assert "input_cost_per_token" not in litellm.model_cost["together_ai/togethercomputer/CodeLlama-34b-Instruct"]
cost = completion_cost(
completion_response=_together_chat_response(
model="togethercomputer/CodeLlama-34b-Instruct", prompt_tokens=23, completion_tokens=15, cached_tokens=0
),
custom_llm_provider="together_ai",
)
assert cost == pytest.approx((23 + 15) * 8e-07, rel=1e-9)