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(router): keep weighted routing when a deployment id equals a model_name
yassinbdc63d590ecf
diff --git a/litellm/router.py b/litellm/router.pyindex 0657c1e05ba..ca0f685b6df 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -12502,7 +12502,7 @@ class Router:# check if aliases set on litellm model alias mapif specific_deployment is True:return model, self._get_deployment_by_litellm_model(model=model)- elif self.has_model_id(model):+ elif model not in self.model_names and self.has_model_id(model):deployment: Final = self.get_deployment(model_id=model)if deployment is not None:deployment_model: Final = deployment.litellm_params.modeldiff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.pyindex f1b445fb1bd..1977fe715cd 100644--- a/tests/test_litellm/test_router.py+++ b/tests/test_litellm/test_router.py@@ -15806,3 +15806,29 @@ async def test_an_open_circuit_breaker_skips_the_session_binding_without_a_warniassert binding is Noneassert [record.getMessage() for record in caplog.records if record.levelno >= logging.WARNING] == []assert any("circuit breaker is open" in record.getMessage() for record in caplog.records)+++async def test_model_name_colliding_with_a_deployment_id_still_load_balances_the_group():+ router = litellm.Router(+ model_list=[+ {+ "model_name": "gpt-5-nano",+ "litellm_params": {"model": "openai/gpt-5-nano", "api_key": "k", "weight": 0, "mock_response": "A"},+ "model_info": {"id": "gpt-5-nano"},+ },+ {+ "model_name": "gpt-5-nano",+ "litellm_params": {"model": "openai/gpt-5-mini", "api_key": "k", "weight": 1, "mock_response": "B"},+ "model_info": {"id": "gpt-5-mini-dep"},+ },+ ],+ routing_strategy="simple-shuffle",+ )++ by_group = await router.acompletion(model="gpt-5-nano", messages=[{"role": "user", "content": "hi"}])+ by_id = await router.acompletion(model="gpt-5-mini-dep", messages=[{"role": "user", "content": "hi"}])++ assert by_group._hidden_params["model_id"] == "gpt-5-mini-dep"+ assert by_group.choices[0].message.content == "B"+ assert by_id._hidden_params["model_id"] == "gpt-5-mini-dep"