From 8c252d7b73064f72f471d32bf02a39752a18c31c Mon Sep 17 00:00:00 2001 From: Yujong Lee Date: Sun, 30 Aug 2026 18:17:58 -0700 Subject: [PATCH] refactor(router): avoid local deployment reassignment --- litellm/router.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index 6f8598304e2..f8d69906cac 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -9576,9 +9576,14 @@ class Router: # Returns: {"api_key": "sk-...", "custom_llm_provider": "openai", "model": "gpt-4o", ...} """ # Try to get deployment by model_id first - deployment = self.get_deployment(model_id=model_id) - if deployment is not None and team_id is not None and not self._deployment_usable_by_team(deployment, team_id): - deployment = None + deployment_candidate: Final = self.get_deployment(model_id=model_id) + deployment = ( + deployment_candidate + if deployment_candidate is None + or team_id is None + or self._deployment_usable_by_team(deployment_candidate, team_id) + else None + ) # If not found, try by model_group_name if deployment is None: