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]

fix(batches): keep managed files on owner

Rithvik Mysore Sureshf0ffc6507e1d
diff --git a/litellm/proxy/batches_endpoints/endpoints.py b/litellm/proxy/batches_endpoints/endpoints.py
index a91b29002e3..b7713d388ea 100644
--- a/litellm/proxy/batches_endpoints/endpoints.py
+++ b/litellm/proxy/batches_endpoints/endpoints.py
@@ -262,7 +262,10 @@ async def create_batch(
detail={"error": "LLM Router not initialized. Ensure models added to proxy."},
)
- response = await llm_router.acreate_batch(**_create_batch_data)
+ response = await llm_router.acreate_batch(
+ **_create_batch_data,
+ disable_fallbacks=True,
+ )
response.input_file_id = input_file_id
response._hidden_params["unified_file_id"] = unified_file_id
else:
diff --git a/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py b/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py
index 6a185988c9b..b382313ea1f 100644
--- a/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py
+++ b/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py
@@ -469,7 +469,7 @@ async def test_create__fallback_body_custom_llm_provider(harness):
@pytest.mark.asyncio
-async def test_create__unified_file_id_single_model(harness):
+async def test_create__unified_file_id_single_model_disables_cross_model_fallbacks(harness):
set_body(
harness,
{
@@ -489,6 +489,7 @@ async def test_create__unified_file_id_single_model(harness):
harness.litellm_acreate.assert_not_called()
# model injected from the unified id, input_file_id restored, hidden param set
assert harness.router_kwargs()["model"] == "gpt-4o-mini"
+ assert harness.router_kwargs()["disable_fallbacks"] is True
assert resp.input_file_id == "litellm_proxy_unified_id"
assert resp._hidden_params["unified_file_id"] == "unified-xyz"
diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py
index 46b5ce65c3f..aa917757bbf 100644
--- a/tests/test_litellm/test_router.py
+++ b/tests/test_litellm/test_router.py
@@ -6054,6 +6054,51 @@ def test_get_configured_token_limits_coerces_numeric_strings():
assert router.get_configured_token_limits("quoted-limits-model") == (32000, 8000)
+async def test_acreate_batch_disable_fallbacks_surfaces_owning_provider_error():
+ router = litellm.Router(
+ model_list=[
+ {
+ "model_name": "owning-model",
+ "litellm_params": {
+ "model": "openai/gpt-4o-mini",
+ "api_key": "sk-owning",
+ },
+ },
+ {
+ "model_name": "fallback-model",
+ "litellm_params": {
+ "model": "azure/gpt-4o-mini",
+ "api_key": "sk-fallback",
+ "api_base": "https://fallback.openai.azure.com",
+ "api_version": "2024-08-01-preview",
+ },
+ },
+ ],
+ fallbacks=[{"owning-model": ["fallback-model"]}],
+ num_retries=0,
+ )
+ owning_provider_error = litellm.BadRequestError(
+ message="completion_window must be one of: 24h",
+ model="openai/gpt-4o-mini",
+ llm_provider="openai",
+ )
+ mock_create = AsyncMock(side_effect=owning_provider_error)
+
+ with patch.object(router, "_acreate_batch", mock_create):
+ with pytest.raises(litellm.BadRequestError, match="24h"):
+ await router.acreate_batch(
+ model="owning-model",
+ input_file_id="file-owned-by-openai",
+ endpoint="/v1/chat/completions",
+ completion_window="5m",
+ disable_fallbacks=True,
+ )
+
+ mock_create.assert_awaited_once()
+ assert mock_create.call_args.kwargs["model"] == "owning-model"
+
+
@pytest.mark.asyncio
async def test_acreate_batch_request_bedrock_tags_override_deployment_tags():
import httpx