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(pass_through_endpoints.py): improve clearing logic - only remove unvisited endpoints (#16400)
Krish Dholakiac1b2dff59565
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.pyindex 669988d6835..f210dbba071 100644--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py@@ -1893,6 +1893,11 @@ class InitPassThroughEndpointHelpers:"""Clear all pass-through routes from the registry"""_registered_pass_through_routes.clear()+ @staticmethod+ def get_registered_pass_through_endpoints_keys() -> List[str]:+ """Get all registered pass-through endpoints from the registry"""+ return list(_registered_pass_through_routes.keys())+@staticmethoddef is_registered_pass_through_route(route: str) -> bool:"""@@ -1995,7 +2000,16 @@ async def initialize_pass_through_endpoints(combined_pass_through_endpoints = pass_through_endpoints # type: ignore## clear all existing pass-through endpoints from the FastAPI app routes- InitPassThroughEndpointHelpers.clear_all_pass_through_routes()+ # InitPassThroughEndpointHelpers.clear_all_pass_through_routes()++ # get a list of all registered pass-through endpoints+ # mark the ones that are visited in the list+ # remove the ones that are not visited from the list+ registered_pass_through_endpoints = (+ InitPassThroughEndpointHelpers.get_registered_pass_through_endpoints_keys()+ )++ visited_endpoints = set()for endpoint in combined_pass_through_endpoints:if isinstance(endpoint, PassThroughGenericEndpoint):@@ -2049,6 +2063,8 @@ async def initialize_pass_through_endpoints(endpoint_id=endpoint_id,)+ visited_endpoints.add(f"{endpoint_id}:exact:{_path}")+# Add wildcard route for sub-pathsif endpoint.get("include_subpath", False) is True:InitPassThroughEndpointHelpers.add_subpath_route(@@ -2063,10 +2079,17 @@ async def initialize_pass_through_endpoints(endpoint_id=endpoint_id,)+ visited_endpoints.add(f"{endpoint_id}:subpath:{_path}")+verbose_proxy_logger.debug("Added new pass through endpoint: %s (ID: %s)", _path, endpoint_id)+ # remove the ones that are not visited from the list+ for endpoint in registered_pass_through_endpoints:+ if endpoint not in visited_endpoints:+ InitPassThroughEndpointHelpers.remove_endpoint_routes(endpoint)+async def _get_pass_through_endpoints_from_db(endpoint_id: Optional[str] = None,