diff --git a/litellm/router.py b/litellm/router.py index 7449492e89..676a9e6e20 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -5278,12 +5278,12 @@ class Router: original_id = decoded.get("response_id", container_id) if original_id != container_id: kwargs["container_id"] = original_id + decoded_provider = decoded.get("custom_llm_provider") + if decoded_provider and kwargs.get("custom_llm_provider") == "openai": + kwargs["custom_llm_provider"] = decoded_provider model_id = decoded.get("model_id") if model_id: kwargs["model"] = model_id - decoded_provider = decoded.get("custom_llm_provider") - if decoded_provider and kwargs.get("custom_llm_provider") == "openai": - kwargs["custom_llm_provider"] = decoded_provider return await self._ageneric_api_call_with_fallbacks( original_function=original_function, **kwargs, diff --git a/tests/router_unit_tests/test_router_endpoints.py b/tests/router_unit_tests/test_router_endpoints.py index 19d7155e4a..0ce2dec9b5 100644 --- a/tests/router_unit_tests/test_router_endpoints.py +++ b/tests/router_unit_tests/test_router_endpoints.py @@ -1203,3 +1203,36 @@ async def test_init_containers_api_endpoints_managed_id_without_model_id_unwraps assert call_kw["container_id"] == "cfile_upstream_abc" assert call_kw["file_id"] == "cfile_xyz" assert call_kw["custom_llm_provider"] == "openai" + + +@pytest.mark.asyncio +async def test_init_containers_api_endpoints_managed_id_without_model_id_applies_decoded_provider(): + """ + A managed ``cntr_`` ID can encode a non-OpenAI provider (e.g. ``azure``) with + an empty ``model_id`` (streaming events without router ``model_info.id``). + The router must still apply the decoded provider so the request routes to + the correct upstream — not stay on the default ``openai``. + """ + from litellm.responses.utils import ResponsesAPIRequestUtils + + router = Router(model_list=[]) + mock_original_function = AsyncMock(return_value={"ok": True}) + + managed_id = ResponsesAPIRequestUtils._build_container_id( + custom_llm_provider="azure", + model_id=None, + container_id="cfile_upstream_abc", + ) + + await router._init_containers_api_endpoints( + original_function=mock_original_function, + custom_llm_provider="openai", + container_id=managed_id, + file_id="cfile_xyz", + ) + + mock_original_function.assert_called_once() + call_kw = mock_original_function.call_args.kwargs + assert call_kw["container_id"] == "cfile_upstream_abc" + assert call_kw["file_id"] == "cfile_xyz" + assert call_kw["custom_llm_provider"] == "azure"