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] Containers API - Allow using LIST, Create Containers using custom-llm-provider (#17740)

Ishaan Jaff142567e14365
diff --git a/litellm/router.py b/litellm/router.py
index efc622ed3c3..eb83c430e6e 100644
--- a/litellm/router.py
+++ b/litellm/router.py
@@ -43,10 +43,6 @@ import litellm
import litellm.litellm_core_utils
import litellm.litellm_core_utils.exception_mapping_utils
from litellm import get_secret_str
-from litellm.router_utils.common_utils import (
- filter_team_based_models,
- filter_web_search_deployments,
-)
from litellm._logging import verbose_router_logger
from litellm._uuid import uuid
from litellm.caching.caching import (
@@ -89,6 +85,10 @@ from litellm.router_utils.clientside_credential_handler import (
get_dynamic_litellm_params,
is_clientside_credential,
)
+from litellm.router_utils.common_utils import (
+ filter_team_based_models,
+ filter_web_search_deployments,
+)
from litellm.router_utils.cooldown_cache import CooldownCache
from litellm.router_utils.cooldown_handlers import (
DEFAULT_COOLDOWN_TIME_SECONDS,
@@ -157,7 +157,11 @@ from litellm.types.utils import (
)
from litellm.types.utils import ModelInfo
from litellm.types.utils import ModelInfo as ModelMapInfo
-from litellm.types.utils import ModelResponseStream, StandardLoggingPayload, Usage
+from litellm.types.utils import (
+ ModelResponseStream,
+ StandardLoggingPayload,
+ Usage,
+)
from litellm.utils import (
CustomStreamWrapper,
EmbeddingResponse,
@@ -3957,10 +3961,6 @@ class Router:
"avideo_status",
"avideo_content",
"avideo_remix",
- "acreate_container",
- "alist_containers",
- "aretrieve_container",
- "adelete_container",
"acancel_batch",
"acreate_skill",
"alist_skills",
@@ -3971,6 +3971,17 @@ class Router:
original_function=original_function,
**kwargs,
)
+ elif call_type in (
+ "acreate_container",
+ "alist_containers",
+ "aretrieve_container",
+ "adelete_container",
+ ):
+ return await self._init_containers_api_endpoints(
+ original_function=original_function,
+ custom_llm_provider=custom_llm_provider,
+ **kwargs,
+ )
elif call_type == "allm_passthrough_route":
return await self._ageneric_api_call_with_fallbacks(
original_function=original_function,
@@ -4019,6 +4030,22 @@ class Router:
kwargs["custom_llm_provider"] = custom_llm_provider
return await original_function(**kwargs)
+ async def _init_containers_api_endpoints(
+ self,
+ original_function: Callable,
+ custom_llm_provider: Optional[str] = None,
+ **kwargs,
+ ):
+ """
+ Initialize the Containers API endpoints on the router.
+
+ Container operations don't need model-based routing, so we call the
+ original function directly with the custom_llm_provider.
+ """
+ if custom_llm_provider and "custom_llm_provider" not in kwargs:
+ kwargs["custom_llm_provider"] = custom_llm_provider
+ return await original_function(**kwargs)
+
async def _init_responses_api_endpoints(
self,
original_function: Callable,
diff --git a/tests/router_unit_tests/test_router_endpoints.py b/tests/router_unit_tests/test_router_endpoints.py
index 94cb3a28300..d913539417a 100644
--- a/tests/router_unit_tests/test_router_endpoints.py
+++ b/tests/router_unit_tests/test_router_endpoints.py
@@ -1104,3 +1104,27 @@ def test_initialize_skills_endpoints():
for endpoint in skills_endpoints:
assert hasattr(router, endpoint)
assert callable(getattr(router, endpoint))
+
+
+async def test_init_containers_api_endpoints():
+ """
+ Test that _init_containers_api_endpoints calls the original function
+ directly without model-based routing.
+ """
+ router = Router(model_list=[])
+
+ mock_response = {"id": "cntr_test", "name": "Test Container"}
+ mock_original_function = AsyncMock(return_value=mock_response)
+
+ result = await router._init_containers_api_endpoints(
+ original_function=mock_original_function,
+ custom_llm_provider="openai",
+ name="Test Container"
+ )
+
+ mock_original_function.assert_called_once_with(
+ custom_llm_provider="openai",
+ name="Test Container"
+ )
+ assert result == mock_response
diff --git a/tests/test_litellm/containers/test_container_api.py b/tests/test_litellm/containers/test_container_api.py
index 51a53c0efaa..d4c42b0b3d6 100644
--- a/tests/test_litellm/containers/test_container_api.py
+++ b/tests/test_litellm/containers/test_container_api.py
@@ -1,26 +1,35 @@
+import asyncio
import json
import os
import sys
from unittest.mock import MagicMock, patch
-import asyncio
-import pytest
import httpx
+import pytest
sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
import litellm
-from litellm.types.containers.main import ContainerObject, ContainerListResponse, DeleteContainerResult
from litellm.containers.main import (
- create_container, acreate_container,
- list_containers, alist_containers,
- retrieve_container, aretrieve_container,
- delete_container, adelete_container
+ acreate_container,
+ adelete_container,
+ alist_containers,
+ aretrieve_container,
+ create_container,
+ delete_container,
+ list_containers,
+ retrieve_container,
)
-from litellm.llms.openai.containers.transformation import OpenAIContainerConfig
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
+from litellm.llms.openai.containers.transformation import OpenAIContainerConfig
+from litellm.router import Router
+from litellm.types.containers.main import (
+ ContainerListResponse,
+ ContainerObject,
+ DeleteContainerResult,
+)
class TestContainerAPI:
@@ -361,3 +370,32 @@ class TestContainerAPI:
# Verify provider config was requested
mock_config_manager.get_provider_container_config.assert_called_once()
assert response.name == "Config Test"
+
+ @pytest.mark.asyncio
+ async def test_router_acreate_container_without_model(self):
+ """
+ Test that router.acreate_container works without a model configured.
+ Ensures container operations bypass model deployment lookup.
+ """
+ router = Router(model_list=[])
+
+ mock_response = ContainerObject(
+ id="cntr_test",
+ object="container",
+ created_at=1747857508,
+ status="running",
+ expires_after={"anchor": "last_active_at", "minutes": 20},
+ last_active_at=1747857508,
+ name="Test Container"
+ )
+
+ with patch('litellm.containers.main.base_llm_http_handler') as mock_handler:
+ mock_handler.container_create_handler.return_value = mock_response
+
+ result = await router.acreate_container(
+ name="Test Container",
+ custom_llm_provider="openai"
+ )
+
+ assert result.id == "cntr_test"
+ assert result.name == "Test Container"