Skip to content

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]

test(batches): run Responses coverage in CI

Rithvik Mysore Suresh390cddb69fed
diff --git a/tests/batches_tests/test_batch_custom_pricing.py b/tests/batches_tests/test_batch_custom_pricing.py
index 01a3e44a496..c2159b564a8 100644
--- a/tests/batches_tests/test_batch_custom_pricing.py
+++ b/tests/batches_tests/test_batch_custom_pricing.py
@@ -128,29 +128,6 @@ def test_aggregate_batch_cost_uses_custom_model_info():
), f"Expected total cost {expected}, got {cost}"
-def test_aggregate_batch_cost_normalizes_mixed_responses_and_chat_usage():
- responses_line = _make_batch_output_line(prompt_tokens=0, completion_tokens=0)
- responses_line["response"]["body"]["usage"] = {
- "input_tokens": 20,
- "output_tokens": 7,
- "total_tokens": 27,
- "input_tokens_details": {"cached_tokens": 3},
- }
- chat_line = _make_batch_output_line(prompt_tokens=10, completion_tokens=5)
-
- cost, usage, _ = _aggregate_batch_cost_usage_models(
- entries=[responses_line, chat_line],
- custom_llm_provider="openai",
- model_info=CUSTOM_MODEL_INFO,
- )
-
- assert usage.prompt_tokens == 30
- assert usage.completion_tokens == 12
- assert usage.total_tokens == 42
- assert usage.cache_read_input_tokens == 3
- assert cost == pytest.approx((30 * 0.00125) + (12 * 0.005))
-
-
@pytest.mark.parametrize("data_residency", ["eu", "us"])
def test_batch_cost_calculator_applies_data_residency_uplift(
data_residency, monkeypatch
diff --git a/tests/test_litellm/batches/test_batch_utils.py b/tests/test_litellm/batches/test_batch_utils.py
index ea9dcea4e72..523b512e4cf 100644
--- a/tests/test_litellm/batches/test_batch_utils.py
+++ b/tests/test_litellm/batches/test_batch_utils.py
@@ -405,6 +405,33 @@ def test_total_usage_sums_successful_only(monkeypatch):
)
+def test_total_usage_and_cost_normalize_mixed_responses_and_chat():
+ responses_row = _success_row(
+ usage={
+ "input_tokens": 20,
+ "output_tokens": 7,
+ "total_tokens": 27,
+ "input_tokens_details": {"cached_tokens": 3},
+ }
+ )
+ chat_row = _success_row(usage=_usage(10, 5))
+
+ cost, usage, _ = bu._aggregate_batch_cost_usage_models(
+ entries=[responses_row, chat_row],
+ custom_llm_provider="openai",
+ model_info={
+ "input_cost_per_token_batches": 0.00125,
+ "output_cost_per_token_batches": 0.005,
+ },
+ )
+
+ assert usage.prompt_tokens == 30
+ assert usage.completion_tokens == 12
+ assert usage.total_tokens == 42
+ assert usage.cache_read_input_tokens == 3
+ assert cost == pytest.approx((30 * 0.00125) + (12 * 0.005))
+
+
def test_total_usage_empty_is_zero():
cost, usage, models = bu._aggregate_batch_cost_usage_models(entries=[], custom_llm_provider="openai")
assert cost == 0.0