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): carry cache_read_input_audio_token_cost through get_model_info
mateo-berrie4b058836275
diff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 9eb70e189a1..ef191d79177 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -251,6 +251,7 @@ class ModelInfoBase(ProviderSpecificModelInfo, total=False):cache_creation_input_token_cost_priority: float | None # OpenAI priority service tier pricingcache_creation_input_token_cost_ultrafast: ReadOnly[float | None] # OpenAI ultrafast service tier pricingcache_read_input_token_cost: float | None+ cache_read_input_audio_token_cost: ReadOnly[float | None]cache_read_input_token_cost_flex: float | None # OpenAI flex service tier pricingcache_read_input_token_cost_priority: float | None # OpenAI priority service tier pricingcache_read_input_token_cost_ultrafast: ReadOnly[float | None] # OpenAI ultrafast service tier pricingdiff --git a/litellm/utils.py b/litellm/utils.pyindex 1a77655a5a4..d048265ecd3 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -5866,6 +5866,7 @@ def _get_model_info_helper("cache_creation_input_token_cost_ultrafast", None),cache_read_input_token_cost=_model_info.get("cache_read_input_token_cost", None),+ cache_read_input_audio_token_cost=_model_info.get("cache_read_input_audio_token_cost", None),prompt_cache_min_tokens=_model_info.get("prompt_cache_min_tokens", None),cache_read_input_token_cost_above_200k_tokens=_model_info.get("cache_read_input_token_cost_above_200k_tokens", Nonediff --git a/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py b/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.pyindex 5d55dfb14a3..5ff1ab62698 100644--- a/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py+++ b/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py@@ -5235,3 +5235,20 @@ def test_cached_audio_tokens_capped_at_cached_tokens(_local_model_cost_map: Nonemodel="gpt-realtime-2", usage=usage, custom_llm_provider="openai")assert prompt_cost == pytest.approx(116 * 4e-6 + (167 - 100) * 32e-6 + 100 * 4e-7)+++def test_cached_audio_tokens_billed_at_audio_cache_rate_through_model_info_lookup(_local_model_cost_map: None) -> None:+ usage = Usage(+ prompt_tokens=1000,+ completion_tokens=0,+ total_tokens=1000,+ prompt_tokens_details=PromptTokensDetailsWrapper(+ text_tokens=400,+ audio_tokens=600,+ cached_tokens=500,+ cached_tokens_details={"text_tokens": 100, "audio_tokens": 400},+ ),+ )++ prompt_cost, _ = generic_cost_per_token(model="gpt-realtime-2.1-mini", usage=usage, custom_llm_provider="openai")+ assert prompt_cost == pytest.approx(300 * 6e-7 + 100 * 6e-8 + 200 * 1e-5 + 400 * 3e-7)diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex 19ed31c7b22..d9ca7d9ddee 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -6430,3 +6430,11 @@ def test_completion_finishes_response_metadata_before_handing_the_response_to_thassert snapshot["litellm_call_id"]assert snapshot["response_cost"] is not Noneassert snapshot["api_base"]+++def test_get_model_info_carries_cache_read_input_audio_token_cost(monkeypatch):+ monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")+ monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))+ info = litellm.get_model_info("gpt-realtime-2.1-mini", custom_llm_provider="openai")+ assert info["cache_read_input_audio_token_cost"] == 3e-07+ assert info["cache_read_input_token_cost"] == 6e-08