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]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_batch_output_single_pass

mateo-berria97233067d5d
diff --cc basedpyright-code-budget.json
index 3259f519f66,f4e506afcde..65142091712
--- a/basedpyright-code-budget.json
+++ b/basedpyright-code-budget.json
@@@ -1,12 -1,12 +1,12 @@@
{
"reportAny": {
- "limit": 33210
- "limit": 31909
++ "limit": 31903
},
"reportArgumentType": {
- "limit": 2648
+ "limit": 2645
},
"reportAssignmentType": {
- "limit": 330
+ "limit": 329
},
"reportAttributeAccessIssue": {
"limit": 516
@@@ -54,10 -54,10 +54,10 @@@
"limit": 0
},
"reportMissingParameterType": {
- "limit": 5893
+ "limit": 5869
},
"reportMissingTypeArgument": {
- "limit": 15883
- "limit": 15864
++ "limit": 15861
},
"reportMissingTypeStubs": {
"limit": 41
@@@ -105,19 -105,19 +105,19 @@@
"limit": 113
},
"reportUnknownMemberType": {
- "limit": 40523
- "limit": 40479
++ "limit": 40477
},
"reportUnknownParameterType": {
- "limit": 20381
- "limit": 20341
++ "limit": 20338
},
"reportUnknownVariableType": {
- "limit": 32095
- "limit": 32051
++ "limit": 32047
},
"reportUnnecessaryCast": {
"limit": 177
},
"reportUnnecessaryComparison": {
- "limit": 1022
- "limit": 1023
++ "limit": 1021
},
"reportUnnecessaryContains": {
"limit": 7
@@@ -135,10 -135,10 +135,10 @@@
"limit": 33
},
"reportUnusedFunction": {
- "limit": 205
- "limit": 206
++ "limit": 204
},
"reportUnusedImport": {
- "limit": 1005
+ "limit": 1003
},
"reportUnusedVariable": {
"limit": 1297
diff --cc ruff-strict-budget.json
index 6323dde9a9f,f1c205c2425..dfdc4efe800
--- a/ruff-strict-budget.json
+++ b/ruff-strict-budget.json
@@@ -135,7 -135,7 +135,7 @@@
"limit": 30
},
"PERF401": {
- "limit": 143
- "limit": 144
++ "limit": 142
},
"PERF402": {
"limit": 9
@@@ -315,16 -315,16 +315,16 @@@
"limit": 98
},
"TRY201": {
- "limit": 422
- "limit": 424
++ "limit": 420
},
"TRY203": {
- "limit": 122
- "limit": 123
++ "limit": 121
},
"TRY300": {
- "limit": 881
- "limit": 883
++ "limit": 879
},
"UP006": {
- "limit": 12143
- "limit": 12142
++ "limit": 12138
},
"UP007": {
"limit": 2526
@@@ -363,6 -363,6 +363,6 @@@
"limit": 105
},
"UP045": {
- "limit": 17823
- "limit": 17806
++ "limit": 17805
}
}
diff --cc tests/test_litellm/batches/test_batch_utils.py
index fb9a9a9d040,bf871623a94..ea9dcea4e72
--- a/tests/test_litellm/batches/test_batch_utils.py
+++ b/tests/test_litellm/batches/test_batch_utils.py
@@@ -747,6 -713,97 +749,98 @@@ async def test_output_file_content_vert
assert captured["custom_llm_provider"] == "vertex_ai"
+ def _vertex_predictions_row(custom_id, prompt_tokens, completion_tokens):
+ return {
+ "request": {
+ "contents": [{"role": "user", "parts": [{"text": "hi"}]}],
+ "labels": {"litellm_custom_id": custom_id},
+ },
+ "status": "",
+ "response": {
+ "candidates": [
+ {
+ "content": {"role": "model", "parts": [{"text": "ok"}]},
+ "finishReason": "STOP",
+ }
+ ],
+ "usageMetadata": {
+ "promptTokenCount": prompt_tokens,
+ "candidatesTokenCount": completion_tokens,
+ "totalTokenCount": prompt_tokens + completion_tokens,
+ },
+ "modelVersion": "gemini-3.6-flash",
+ },
+ "processed_time": "2026-07-30T00:00:00.000000+00:00",
+ }
+
+
+ @pytest.fixture
+ def respx_interceptable_httpx_client(monkeypatch):
+ monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)
+ litellm.in_memory_llm_clients_cache.flush_cache()
+ yield
+ litellm.in_memory_llm_clients_cache.flush_cache()
+
+
+ @pytest.mark.asyncio
+ @respx.mock
+ async def test_output_file_content_vertex_managed_uri_accepted_by_real_validation(respx_interceptable_httpx_client):
+ managed_output_uri = (
+ "gs://litellm-bucket/litellm-vertex-files/publishers/google/models/"
+ "gemini-3.6-flash/abc-123/prediction-model/predictions.jsonl"
+ )
+ rows = [
+ _vertex_predictions_row("request-1", 10, 5),
+ _vertex_predictions_row("request-2", 20, 10),
+ ]
+ route = respx.get(url__regex=r"https://storage\.googleapis\.com/storage/v1/b/litellm-bucket/o/.*").mock(
+ return_value=httpx.Response(200, content=_vertex_jsonl(rows))
+ )
+
- result = await bu._get_batch_output_file_content_as_dictionary(
++ file_content = await bu._fetch_batch_output_file_content(
+ _batch(managed_output_uri),
+ custom_llm_provider="vertex_ai",
+ litellm_params={
+ "api_key": "test-token",
+ "vertex_project": "proj-1",
+ "vertex_location": "us-central1",
+ "gcs_bucket_name": "litellm-bucket",
+ },
+ )
++ result = bu._get_file_content_as_dictionary(file_content)
+
+ assert route.call_count == 1
+ request = route.calls.last.request
+ assert request.url.raw_path == (
+ b"/storage/v1/b/litellm-bucket/o/"
+ b"litellm-vertex-files%2Fpublishers%2Fgoogle%2Fmodels%2Fgemini-3.6-flash"
+ b"%2Fabc-123%2Fprediction-model%2Fpredictions.jsonl?alt=media"
+ )
+ assert [row["custom_id"] for row in result] == ["request-1", "request-2"]
+ assert all(row["response"]["status_code"] == 200 for row in result)
+ assert all(row["response"]["body"]["model"] == "gemini-3.6-flash" for row in result)
+ assert [row["response"]["body"]["usage"]["prompt_tokens"] for row in result] == [10, 20]
+ assert [row["response"]["body"]["usage"]["completion_tokens"] for row in result] == [5, 10]
+
+
+ @pytest.mark.asyncio
+ @respx.mock
+ async def test_output_file_content_vertex_foreign_bucket_rejected_by_real_validation():
+ with pytest.raises(Exception, match="does not match the configured storage bucket"):
- await bu._get_batch_output_file_content_as_dictionary(
++ await bu._fetch_batch_output_file_content(
+ _batch("gs://attacker-bucket/litellm-vertex-files/x/predictions.jsonl"),
+ custom_llm_provider="vertex_ai",
+ litellm_params={
+ "api_key": "test-token",
+ "vertex_project": "proj-1",
+ "vertex_location": "us-central1",
+ "gcs_bucket_name": "litellm-bucket",
+ },
+ )
+
+ assert respx.mock.calls.call_count == 0
+
+
@pytest.mark.asyncio
async def test_handle_completed_vertex_batch_computes_cost_usage_and_models(monkeypatch):
import litellm.files.main as files_main
diff --cc type-discipline-budget.json
index a7ee2c261c3,69b2506dc08..bef3a4c98aa
--- a/type-discipline-budget.json
+++ b/type-discipline-budget.json
@@@ -1,9 -1,9 +1,9 @@@
{
"LIT001": {
- "limit": 23279
- "limit": 23261
++ "limit": 23253
},
"LIT002": {
- "limit": 27473
+ "limit": 27433
},
"LIT003": {
"limit": 292