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(batches): reconcile merge with upstream batch pricing changes
mubashir1osmani98447e004364
diff --git a/litellm/batches/batch_utils.py b/litellm/batches/batch_utils.pyindex bae8e198223..d0874b5aff5 100644--- a/litellm/batches/batch_utils.py+++ b/litellm/batches/batch_utils.py@@ -86,7 +86,7 @@ async def _handle_completed_batch(return BatchCostUsageResult(cost=0.0,usage=Usage(prompt_tokens=0, completion_tokens=0, total_tokens=0),- models=[],+ models=[], # mutable-ok: no output file means no model was ever priced; BatchCostUsageResult.models requires list[str]successful_requests=0,failed_requests=await _count_error_file_failed_requests(batch, custom_llm_provider=custom_llm_provider, litellm_params=litellm_paramsdiff --git a/tests/test_litellm/batches/test_batch_utils.py b/tests/test_litellm/batches/test_batch_utils.pyindex 0adebf2506b..64b3df4180b 100644--- a/tests/test_litellm/batches/test_batch_utils.py+++ b/tests/test_litellm/batches/test_batch_utils.py@@ -1501,24 +1501,24 @@ async def test_handle_completed_bedrock_batch_prices_from_deployment_model(monkemonkeypatch.setattr(bu, "_fetch_batch_output_file_content", fake_fetch)- cost, usage, _ = await bu._handle_completed_batch(+ result = await bu._handle_completed_batch(_batch("of"),custom_llm_provider="bedrock",model_name="bedrock/global.anthropic.claude-sonnet-4-6",)- assert (usage.prompt_tokens, usage.completion_tokens, usage.total_tokens) == (1800, 1000, 2800)+ assert (result.usage.prompt_tokens, result.usage.completion_tokens, result.usage.total_tokens) == (1800, 1000, 2800)# 3e-06 / 1.5e-05 on-demand, halved for batch.- assert cost == pytest.approx(1800 * 3e-06 / 2 + 1000 * 1.5e-05 / 2)+ assert result.cost == pytest.approx(1800 * 3e-06 / 2 + 1000 * 1.5e-05 / 2)# The response model alone cannot price a bedrock batch: this is the $0 bug.- zero_cost, zero_usage, _ = await bu._handle_completed_batch(+ zero_result = await bu._handle_completed_batch(_batch("of"),custom_llm_provider="bedrock",model_name=None,)- assert zero_cost == 0.0- assert zero_usage.total_tokens == 2800+ assert zero_result.cost == 0.0+ assert zero_result.usage.total_tokens == 2800@pytest.mark.asyncio@@ -1531,7 +1531,7 @@ async def test_handle_completed_batch_honors_deployment_pricing(monkeypatch) ->monkeypatch.setattr(bu, "_fetch_batch_output_file_content", fake_fetch)- free_cost, _, _ = await bu._handle_completed_batch(+ free_result = await bu._handle_completed_batch(_batch("of"),custom_llm_provider="vertex_ai",model_name="vertex_ai/gemini-2.5-flash",@@ -1542,15 +1542,15 @@ async def test_handle_completed_batch_honors_deployment_pricing(monkeypatch) ->"output_cost_per_token_batches": 0.0,},)- assert free_cost == 0.0+ assert free_result.cost == 0.0- billed_cost, _, _ = await bu._handle_completed_batch(+ billed_result = await bu._handle_completed_batch(_batch("of"),custom_llm_provider="vertex_ai",model_name="vertex_ai/gemini-2.5-flash",model_info=None,)- assert billed_cost > 0.0+ assert billed_result.cost > 0.0# =========================================================================== #diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.pyindex 0d54680fa81..e46057fe11a 100644--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py@@ -586,9 +586,17 @@ class TestRetrieveBatchCostPassesModelIdentity:captured: dict[str, object] = {}- async def fake_handle_completed_batch(**kwargs: object) -> tuple[float, Usage, list[str]]:+ from litellm.batches.batch_utils import BatchCostUsageResult++ async def fake_handle_completed_batch(**kwargs: object) -> BatchCostUsageResult:captured.update(kwargs)- return 1.25, Usage(prompt_tokens=1800, completion_tokens=1000, total_tokens=2800), ["m"]+ return BatchCostUsageResult(+ cost=1.25,+ usage=Usage(prompt_tokens=1800, completion_tokens=1000, total_tokens=2800),+ models=["m"],+ successful_requests=1,+ failed_requests=0,+ )monkeypatch.setattr(logging_module, "_handle_completed_batch", fake_handle_completed_batch)