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(proxy): forward decoded container ids after ownership checks
userc01f20972354
diff --git a/litellm/proxy/container_endpoints/handler_factory.py b/litellm/proxy/container_endpoints/handler_factory.pyindex f4887f812cb..4284cdd5d4a 100644--- a/litellm/proxy/container_endpoints/handler_factory.py+++ b/litellm/proxy/container_endpoints/handler_factory.py@@ -19,7 +19,10 @@ from litellm.proxy.common_utils.openai_endpoint_utils import (get_custom_llm_provider_from_request_headers,get_custom_llm_provider_from_request_query,)-from litellm.proxy.container_endpoints.ownership import assert_user_can_access_container+from litellm.proxy.container_endpoints.ownership import (+ assert_user_can_access_container,+ get_container_forwarding_params,+)def _load_endpoints_config() -> Dict:@@ -162,8 +165,9 @@ async def _process_binary_request("""Process binary content requests through the standard proxy/router pipeline.- The router owns managed container ID decoding and deployment selection. This- handler only adapts the byte response to FastAPI.+ Validate ownership before forwarding the provider-native container id through+ the standard proxy/router pipeline. This handler only adapts the byte+ response to FastAPI."""from litellm.proxy.proxy_server import (general_settings,@@ -185,15 +189,18 @@ async def _process_binary_request(or "openai")- await assert_user_can_access_container(+ original_container_id, resolved_provider = await assert_user_can_access_container(container_id=container_id,user_api_key_dict=user_api_key_dict,custom_llm_provider=custom_llm_provider,)data: Dict[str, Any] = {- "container_id": container_id,"file_id": file_id,- "custom_llm_provider": custom_llm_provider,+ **get_container_forwarding_params(+ container_id=container_id,+ original_container_id=original_container_id,+ custom_llm_provider=resolved_provider,+ ),}processor = ProxyBaseLLMRequestProcessing(data=data)@@ -302,14 +309,19 @@ async def _process_multipart_upload_request(or "openai")- await assert_user_can_access_container(+ original_container_id, resolved_provider = await assert_user_can_access_container(container_id=container_id,user_api_key_dict=user_api_key_dict,custom_llm_provider=custom_llm_provider,)- data["container_id"] = container_id- data["custom_llm_provider"] = custom_llm_provider+ data.update(+ get_container_forwarding_params(+ container_id=container_id,+ original_container_id=original_container_id,+ custom_llm_provider=resolved_provider,+ )+ )processor = ProxyBaseLLMRequestProcessing(data=data)try:@@ -376,12 +388,22 @@ async def _process_request(# Validate container_id ownership if present in path_params.if "container_id" in path_params:- await assert_user_can_access_container(- container_id=path_params["container_id"],- user_api_key_dict=user_api_key_dict,- custom_llm_provider=custom_llm_provider,+ original_container_id, resolved_provider = (+ await assert_user_can_access_container(+ container_id=path_params["container_id"],+ user_api_key_dict=user_api_key_dict,+ custom_llm_provider=custom_llm_provider,+ )+ )+ data.update(+ get_container_forwarding_params(+ container_id=path_params["container_id"],+ original_container_id=original_container_id,+ custom_llm_provider=resolved_provider,+ ))- data["custom_llm_provider"] = custom_llm_provider+ else:+ data["custom_llm_provider"] = custom_llm_providerprocessor = ProxyBaseLLMRequestProcessing(data=data)try:diff --git a/tests/test_litellm/containers/test_azure_container_transformation.py b/tests/test_litellm/containers/test_azure_container_transformation.pyindex 9a3a8bc20a9..70181f6f03d 100644--- a/tests/test_litellm/containers/test_azure_container_transformation.py+++ b/tests/test_litellm/containers/test_azure_container_transformation.py@@ -543,7 +543,7 @@ class TestAzureContainerKnownFailureRegressions:assert isinstance(c1, AzureContainerConfig)@pytest.mark.asyncio- async def test_proxy_process_request_preserves_managed_container_id(+ async def test_proxy_process_request_forwards_decoded_container_id(self, monkeypatch):from starlette.requests import Request@@ -607,9 +607,9 @@ class TestAzureContainerKnownFailureRegressions:access_check.assert_awaited_once()assert access_check.await_args.kwargs["container_id"] == encoded_idassert captured["route_type"] == "alist_container_files"- assert captured["data"]["container_id"] == encoded_id- assert captured["data"]["custom_llm_provider"] == "openai"- assert "model_id" not in captured["data"]+ assert captured["data"]["container_id"] == "cntr_123"+ assert captured["data"]["custom_llm_provider"] == "azure"+ assert captured["data"]["model_id"] == "model_abc123"assert "api_base" not in captured["data"]@pytest.mark.asyncio@@ -679,9 +679,10 @@ class TestAzureContainerKnownFailureRegressions:access_check.assert_awaited_once()assert access_check.await_args.kwargs["container_id"] == encoded_idassert captured["route_type"] == "aretrieve_container_file_content"- assert captured["data"]["container_id"] == encoded_id+ assert captured["data"]["container_id"] == "cntr_123"assert captured["data"]["file_id"] == "cfile_abc"- assert captured["data"]["custom_llm_provider"] == "openai"+ assert captured["data"]["custom_llm_provider"] == "azure"+ assert captured["data"]["model_id"] == "model_abc123"assert response.status_code == 200assert response.body == b"csv-bytes"assert response.headers["x-litellm-call-id"] == "call-123"@@ -766,5 +767,6 @@ class TestAzureContainerKnownFailureRegressions:access_check.assert_awaited_once()assert access_check.await_args.kwargs["container_id"] == encoded_idassert captured["route_type"] == "aupload_container_file"- assert captured["data"]["container_id"] == encoded_id- assert captured["data"]["custom_llm_provider"] == "openai"+ assert captured["data"]["container_id"] == "cntr_123"+ assert captured["data"]["custom_llm_provider"] == "azure"+ assert captured["data"]["model_id"] == "model_abc123"diff --git a/tests/test_litellm/containers/test_container_proxy_ownership.py b/tests/test_litellm/containers/test_container_proxy_ownership.pyindex 63e5e16d0d6..2a760edf7db 100644--- a/tests/test_litellm/containers/test_container_proxy_ownership.py+++ b/tests/test_litellm/containers/test_container_proxy_ownership.py@@ -632,7 +632,7 @@ async def test_should_include_memory_container_list_when_db_recovers_without_row@pytest.mark.asyncio-async def test_should_validate_owner_and_preserve_managed_id_for_proxy_forwarding(+async def test_should_validate_owner_and_forward_decoded_id_for_proxy_forwarding(monkeypatch,):from litellm.proxy.container_endpoints import handler_factory@@ -691,13 +691,13 @@ async def test_should_validate_owner_and_preserve_managed_id_for_proxy_forwardinaccess_check.assert_awaited_once()assert access_check.await_args.kwargs["container_id"] == encoded_id- assert result["container_id"] == encoded_id- assert result["custom_llm_provider"] == "openai"- assert "model_id" not in result+ assert result["container_id"] == "cntr_provider"+ assert result["custom_llm_provider"] == "azure"+ assert result["model_id"] == "router-gpt"@pytest.mark.asyncio-async def test_should_validate_owner_and_preserve_managed_id_for_multipart_upload(+async def test_should_validate_owner_and_forward_decoded_id_for_multipart_upload(monkeypatch,):from litellm.proxy.common_utils import http_parsing_utils@@ -767,9 +767,9 @@ async def test_should_validate_owner_and_preserve_managed_id_for_multipart_uploaaccess_check.assert_awaited_once()assert access_check.await_args.kwargs["container_id"] == encoded_id- assert result["container_id"] == encoded_id- assert result["custom_llm_provider"] == "openai"- assert "model_id" not in result+ assert result["container_id"] == "cntr_provider"+ assert result["custom_llm_provider"] == "azure"+ assert result["model_id"] == "router-gpt"assert result["file"] == "file-data"