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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(router): apply decoded provider for managed container IDs without model_id
mateo-berri46ba48e69a90
diff --git a/litellm/router.py b/litellm/router.pyindex 7449492e89f..676a9e6e205 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_providermodel_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_providerreturn 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.pyindex 19d7155e4aa..0ce2dec9b56 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_unwrapsassert call_kw["container_id"] == "cfile_upstream_abc"assert call_kw["file_id"] == "cfile_xyz"assert call_kw["custom_llm_provider"] == "openai"+++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"