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): scope wildcard cleanup to subpath entries and restore registry in test

Sameer Kankuteab1744f9fe19
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
index 3beaa32b313..0f676a1feb2 100644
--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
@@ -2033,13 +2033,13 @@ class InitPassThroughEndpointHelpers:
route_info = _registered_pass_through_routes[key]
path = route_info.get("path")
if isinstance(path, str):
- # Remove base path and wildcard path from openai_routes
openai_routes = LiteLLMRoutes.openai_routes.value
if path in openai_routes:
openai_routes.remove(path)
- wildcard_path = path.rstrip("/") + "/*"
- if wildcard_path in openai_routes:
- openai_routes.remove(wildcard_path)
+ if route_info.get("type") == "subpath":
+ wildcard_path = path.rstrip("/") + "/*"
+ if wildcard_path in openai_routes:
+ openai_routes.remove(wildcard_path)
del _registered_pass_through_routes[key]
verbose_proxy_logger.debug(
"Removed pass-through route from registry: %s", key
diff --git a/tests/test_litellm/proxy/auth/test_route_checks.py b/tests/test_litellm/proxy/auth/test_route_checks.py
index b6c4fa73dfb..83703cd4edd 100644
--- a/tests/test_litellm/proxy/auth/test_route_checks.py
+++ b/tests/test_litellm/proxy/auth/test_route_checks.py
@@ -1397,3 +1397,10 @@ async def test_initialize_pass_through_registers_wildcard_for_auth_subpath():
assert wildcard_path not in LiteLLMRoutes.openai_routes.value
finally:
LiteLLMRoutes.openai_routes.value[:] = original_routes
+ # Clean up any routes registered during this test to avoid
+ # polluting the module-level _registered_pass_through_routes
+ registered = InitPassThroughEndpointHelpers.get_all_registered_pass_through_routes()
+ for k in registered:
+ InitPassThroughEndpointHelpers.remove_endpoint_routes(
+ k.split(":")[0]
+ )