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
test(cost): type the batch_cost_calculator model_info literals instead of suppressing
mateo-berrie736b5980285
diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.pyindex 850d860b9d2..75c90d793fe 100644--- a/tests/test_litellm/test_cost_calculator.py+++ b/tests/test_litellm/test_cost_calculator.py@@ -20,7 +20,7 @@ from litellm.cost_calculator import (response_cost_calculator,)from litellm.types.llms.openai import OpenAIRealtimeStreamList-from litellm.types.utils import ModelResponse, PromptTokensDetailsWrapper, Usage+from litellm.types.utils import ModelInfo, ModelResponse, PromptTokensDetailsWrapper, Usagefrom litellm.utils import TranscriptionResponse@@ -3562,16 +3562,18 @@ def test_batch_cost_calculator_prices_cache_creation_tokens_at_cache_write_rate("""from litellm.cost_calculator import batch_cost_calculator+ model_info: ModelInfo = {+ "supported_openai_params": [],+ "input_cost_per_token": 3e-6,+ "output_cost_per_token": 15e-6,+ "cache_read_input_token_cost": 3e-7,+ "cache_creation_input_token_cost": 3.75e-6,+ }prompt_cost, completion_cost_value = batch_cost_calculator(usage=_batch_cache_usage(),model="claude-sonnet-4-5-20250929",custom_llm_provider="anthropic",- model_info={ # type: ignore[arg-type]- "input_cost_per_token": 3e-6,- "output_cost_per_token": 15e-6,- "cache_read_input_token_cost": 3e-7,- "cache_creation_input_token_cost": 3.75e-6,- },+ model_info=model_info,)assert prompt_cost == pytest.approx((1000 * 3e-6 + 8000 * 3e-7 + 2000 * 3.75e-6) / 2)@@ -3581,15 +3583,17 @@ def test_batch_cost_calculator_prices_cache_creation_tokens_at_cache_write_rate(def test_batch_cost_calculator_cache_creation_falls_back_to_input_rate():from litellm.cost_calculator import batch_cost_calculator+ model_info: ModelInfo = {+ "supported_openai_params": [],+ "input_cost_per_token": 3e-6,+ "output_cost_per_token": 15e-6,+ "cache_read_input_token_cost": 3e-7,+ }prompt_cost, _ = batch_cost_calculator(usage=_batch_cache_usage(),model="claude-sonnet-4-5-20250929",custom_llm_provider="anthropic",- model_info={ # type: ignore[arg-type]- "input_cost_per_token": 3e-6,- "output_cost_per_token": 15e-6,- "cache_read_input_token_cost": 3e-7,- },+ model_info=model_info,)assert prompt_cost == pytest.approx((1000 * 3e-6 + 8000 * 3e-7 + 2000 * 3e-6) / 2)@@ -3616,16 +3620,26 @@ def test_batch_cost_calculator_honors_an_explicitly_zero_batch_rate("""from litellm.cost_calculator import batch_cost_calculator- model_info: dict[str, float] = {"input_cost_per_token": 3e-6, "output_cost_per_token": 15e-6}- if batch_rate is not None:- model_info["input_cost_per_token_batches"] = batch_rate- model_info["output_cost_per_token_batches"] = batch_rate+ base_model_info: ModelInfo = {+ "supported_openai_params": [],+ "input_cost_per_token": 3e-6,+ "output_cost_per_token": 15e-6,+ }+ model_info: ModelInfo = (+ base_model_info+ if batch_rate is None+ else {+ **base_model_info,+ "input_cost_per_token_batches": batch_rate,+ "output_cost_per_token_batches": batch_rate,+ }+ )prompt_cost, completion_cost_value = batch_cost_calculator(usage=Usage(prompt_tokens=1000, completion_tokens=500, total_tokens=1500),model="claude-sonnet-4-5-20250929",custom_llm_provider="anthropic",- model_info=model_info, # type: ignore[arg-type]+ model_info=model_info,)assert prompt_cost == pytest.approx(expected_prompt)