The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(cost): keep size buckets for Together registry rows without pricing
mateo-berriabe9af622bbb
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.pyindex 78a555940c8..153b8457e38 100644--- a/litellm/cost_calculator.py+++ b/litellm/cost_calculator.py@@ -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_tokensif ("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 runningdiff --git a/litellm/llms/together_ai/cost_calculator.py b/litellm/llms/together_ai/cost_calculator.pyindex 2f492496e7b..6fc2c949fa6 100644--- a/litellm/llms/together_ai/cost_calculator.py+++ b/litellm/llms/together_ai/cost_calculator.py@@ -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 namediff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.pyindex bf230bf794c..edc0635a741 100644--- a/tests/test_litellm/test_cost_calculator.py+++ b/tests/test_litellm/test_cost_calculator.py@@ -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)