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
perf(router): optimize model lookups with O(1) data structures
AlexsanderHamir6e4da1da6557
diff --git a/litellm/router.py b/litellm/router.pyindex 5972b06f01a..05fff0afaf5 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -189,7 +189,7 @@ class RoutingArgs(enum.Enum):class Router:- model_names: List = []+ model_names: set = set()cache_responses: Optional[bool] = Falsedefault_cache_time_seconds: int = 1 * 60 * 60 # 1 hourtenacity = None@@ -5154,7 +5154,7 @@ class Router:verbose_router_logger.debug(f"\nInitialized Model List {self.get_model_names()}")- self.model_names = [m["model_name"] for m in model_list]+ self.model_names = {m["model_name"] for m in model_list}# Build model_name index for O(1) lookupsself._build_model_name_index(self.model_list)@@ -5360,7 +5360,7 @@ class Router:self._add_model_to_list_and_index_map(model=_deployment, model_id=deployment.model_info.id)- self.model_names.append(deployment.model_name)+ self.model_names.add(deployment.model_name)return deploymentdef _update_deployment_indices_after_removal(