Merge pull request #35371 from rimysore/fix-managed-batch-cross-provider-fallback

fix(batches): prevent managed file fallbacks
This commit is contained in:
Mateo Wang 2026-08-06 11:40:38 -07:00 • committed by GitHub
commit 0c3017e1de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 1 deletions

View file

@ -264,6 +264,7 @@ async def create_batch(
detail={"error": "LLM Router not initialized. Ensure models added to proxy."},
)
_create_batch_data.update(disable_fallbacks=True) # pyright: ignore[reportCallIssue] # router flag
response = await llm_router.acreate_batch(**_create_batch_data)
response.input_file_id = input_file_id
response._hidden_params["unified_file_id"] = unified_file_id

View file

@ -469,13 +469,14 @@ 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,
{
"input_file_id": "litellm_proxy_unified_id",
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
"disable_fallbacks": False,
},
)
with (
@ -489,6 +490,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"

View file

@ -6710,6 +6710,51 @@ def test_get_configured_token_limits_coerces_numeric_strings():
assert router.get_configured_token_limits("quoted-limits-model") == (32000, 8000)
@pytest.mark.asyncio
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