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_calculator): require real values when detecting declared realtime pricing
mateo-berrib48bff7b5444
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.pyindex 128060815f6..9ac2b425961 100644--- a/litellm/cost_calculator.py+++ b/litellm/cost_calculator.py@@ -2393,7 +2393,10 @@ def _cost_map_entry_declares_pricing(model_name: str, custom_llm_provider: str)litellm.model_cost.get(model_name),litellm.model_cost.get(f"{custom_llm_provider}/{model_name}"),)- return any(entry is not None and any("cost_per" in field for field in entry) for entry in entries)+ return any(+ entry is not None and any("cost_per" in field and value is not None for field, value in entry.items())+ for entry in entries+ )def _first_priced_realtime_token_costs(diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.pyindex cfd07171556..6d292cb5f94 100644--- a/tests/test_litellm/test_cost_calculator.py+++ b/tests/test_litellm/test_cost_calculator.py@@ -4146,17 +4146,32 @@ def test_gemini_live_native_audio_ga_realtime_cost(_local_model_cost_map: None)assert cost == pytest.approx(expected_cost, rel=1e-9)+ "priceless_entry",+ [+ {"litellm_provider": "vertex_ai", "mode": "realtime"},+ {+ "litellm_provider": "vertex_ai",+ "mode": "realtime",+ "input_cost_per_token": None,+ "output_cost_per_token": None,+ "input_cost_per_audio_token": None,+ },+ ],+ ids=["registered_without_price_fields", "registered_with_none_valued_price_fields"],+)def test_realtime_priceless_deployment_entry_falls_through_to_priced_model(- _local_model_cost_map: None, monkeypatch: pytest.MonkeyPatch+ _local_model_cost_map: None, monkeypatch: pytest.MonkeyPatch, priceless_entry: dict) -> None:"""Regression for https://github.com/BerriAI/litellm/issues/31087: the router registers every- deployment's backend key into litellm.model_cost without price fields, and the realtime cost- handler used to accept that zero-defaulted entry for the session.created model and stop, so a- configured base_model never priced the session."""+ deployment's backend key into litellm.model_cost without price fields (and merges a None-valued+ ModelInfo skeleton into mapped entries), and the realtime cost handler used to accept that+ zero-defaulted entry for the session.created model and stop, so a configured base_model never+ priced the session."""monkeypatch.setitem(litellm.model_cost,"vertex_ai/some-unmapped-live-model",- {"litellm_provider": "vertex_ai", "mode": "realtime"},+ priceless_entry,)priced_model = "vertex_ai/gemini-live-2.5-flash-preview-native-audio-09-2025"priced_entry = litellm.model_cost["gemini-live-2.5-flash-preview-native-audio-09-2025"]