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: count tiered_pricing as a cost mapping when blocking unpriced models
mateo-berriab79b8dcb6a0
diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.pyindex ede1b1a0a03..0bf419ca1de 100644--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@ -472,6 +472,8 @@ def _is_positive_cost(value: object) -> bool:def _entry_has_priced_metric(entry: Mapping[str, object]) -> bool:+ if entry.get("tiered_pricing") is not None:+ return Truefor key, value in entry.items():if "cost_per" not in key:continue@@ -483,15 +485,15 @@ def _entry_has_priced_metric(entry: Mapping[str, object]) -> bool:def _entry_declares_price(entry: Mapping[str, object]) -> bool:- return any("cost_per" in key for key in entry)+ return any("cost_per" in key or key == "tiered_pricing" for key in entry)def _model_group_has_pricing(model: str, llm_router: "Router") -> bool:"""- A model group counts as priced when a deployment overrides any *cost_per* field in its- litellm_params, even at zero, or when its resolved model info carries a positive price on- any billed metric (tokens, characters, seconds, pages, images, queries, ...), so models- billed by a non-token metric are not treated as unpriced.+ A model group counts as priced when a deployment overrides any *cost_per* field or+ tiered_pricing in its litellm_params, even at zero, or when its resolved model info carries+ tiered_pricing or a positive price on any billed metric (tokens, characters, seconds, pages,+ images, queries, ...), so models billed by a non-token metric are not treated as unpriced."""for deployment in llm_router.get_model_list(model_name=model) or ():litellm_params = deployment.get("litellm_params") or _EMPTY_COST_ENTRYdiff --git a/tests/test_litellm/proxy/auth/test_auth_checks.py b/tests/test_litellm/proxy/auth/test_auth_checks.pyindex a1b8f2efaae..12ab090fe47 100644--- a/tests/test_litellm/proxy/auth/test_auth_checks.py+++ b/tests/test_litellm/proxy/auth/test_auth_checks.py@@ -3,9 +3,12 @@ import jsonimport osimport sysfrom types import SimpleNamespace-from typing import Optional+from typing import TYPE_CHECKING, Optionalfrom unittest.mock import AsyncMock, MagicMock, patch+if TYPE_CHECKING:+ from litellm.router import Router+sys.path.insert(0, os.path.abspath("../../..")) # Adds the parent directory to the system path@@ -6667,6 +6670,29 @@ def test_model_has_no_cost_mapping_explicit_zero_price_is_false(cost_field):assert model_has_no_cost_mapping(model="free-group", llm_router=router) is False+def test_model_has_no_cost_mapping_tiered_pricing_only_is_false():+ from litellm.proxy.auth.auth_checks import model_has_no_cost_mapping+ from litellm.router import Router++ router = Router(+ model_list=[+ {+ "model_name": "tiered-group",+ "litellm_params": {+ "model": f"{UNPRICED_UNDERLYING_MODEL}-tiered",+ "api_key": "sk-test",+ "tiered_pricing": [+ {"range": [0, 128000], "input_cost_per_token": 2e-7, "output_cost_per_token": 6e-7},+ {"range": [128000, 256000], "input_cost_per_token": 4e-7, "output_cost_per_token": 12e-7},+ ],+ },+ }+ ]+ )++ assert model_has_no_cost_mapping(model="tiered-group", llm_router=router) is False++async def _run_common_checks(model: Optional[str], llm_router: Optional["Router"], route: str = "/chat/completions") -> bool: