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(proxy): avoid mutating container responses

user20eb9c96caba
diff --git a/litellm/proxy/container_endpoints/ownership.py b/litellm/proxy/container_endpoints/ownership.py
index edb1b65c715..05634d506b7 100644
--- a/litellm/proxy/container_endpoints/ownership.py
+++ b/litellm/proxy/container_endpoints/ownership.py
@@ -73,7 +73,7 @@ def _get_response_id(response: Any) -> Optional[str]:
def _dump_response(response: Any) -> Dict[str, Any]:
if isinstance(response, dict):
- return response
+ return dict(response)
if hasattr(response, "model_dump"):
return response.model_dump()
if hasattr(response, "dict"):
diff --git a/tests/test_litellm/containers/test_container_proxy_ownership.py b/tests/test_litellm/containers/test_container_proxy_ownership.py
index 576e25bbbad..8ebfd3ab6f7 100644
--- a/tests/test_litellm/containers/test_container_proxy_ownership.py
+++ b/tests/test_litellm/containers/test_container_proxy_ownership.py
@@ -57,6 +57,35 @@ async def test_should_record_container_owner_with_original_provider_id(monkeypat
assert data["created_by"] == "user-1"
+async def test_should_not_mutate_dict_container_response_when_recording_owner(
+ monkeypatch,
+):
+ table = AsyncMock()
+ table.find_unique.return_value = None
+ prisma_client = SimpleNamespace(
+ db=SimpleNamespace(litellm_managedobjecttable=table)
+ )
+ monkeypatch.setattr(
+ ownership,
+ "_get_prisma_client",
+ AsyncMock(return_value=prisma_client),
+ )
+ auth = UserAPIKeyAuth(user_id="user-1")
+ response = {"id": "cntr_provider", "object": "container"}
+
+ returned = await ownership.record_container_owner(
+ response=response,
+ user_api_key_dict=auth,
+ custom_llm_provider="openai",
+ )
+
+ assert returned == {"id": "cntr_provider", "object": "container"}
+ data = table.create.await_args.kwargs["data"]
+ assert data["file_object"]["custom_llm_provider"] == "openai"
+ assert data["file_object"]["provider_container_id"] == "cntr_provider"
+
+
@pytest.mark.asyncio
async def test_should_record_team_owner_for_keys_without_user_id(monkeypatch):
table = AsyncMock()