diff --git a/litellm/router.py b/litellm/router.py index 59767843d6b..5d3ae274e20 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -8061,11 +8061,12 @@ class Router: if _deployment_model_id and self.has_model_id(_deployment_model_id): return None - # add to model list - _deployment = deployment.to_json(exclude_none=True) # initialize client self._add_deployment(deployment=deployment) + # add to model list + _deployment = deployment.to_json(exclude_none=True) + _model_info_dict: dict = deployment.model_info.model_dump(exclude_none=True) for field in CustomPricingLiteLLMParams.model_fields.keys(): field_value = deployment.litellm_params.get(field) diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py index 47d53933df2..09051c2fb1a 100644 --- a/tests/test_litellm/test_router.py +++ b/tests/test_litellm/test_router.py @@ -1138,6 +1138,33 @@ def test_apply_xai_oauth_alias_helper(): assert router._apply_xai_oauth_alias(untouched) is untouched +def test_add_deployment_normalizes_xai_oauth_alias(): + """add_deployment (used for runtime/DB deployments) must normalize the alias too.""" + from litellm.types.router import Deployment + + router = litellm.Router( + model_list=[ + {"model_name": "grok-4.5", "litellm_params": {"model": "xai/grok-4.5"}} + ] + ) + + router.add_deployment( + Deployment( + model_name="grok-4.5", + litellm_params={"model": "xai-oauth/grok-4.5"}, + ) + ) + + added = [ + m + for m in router.get_model_list() + if m["litellm_params"].get("use_xai_oauth") + ] + assert len(added) == 1 + assert added[0]["litellm_params"]["model"] == "xai/grok-4.5" + assert added[0]["litellm_params"].get("custom_llm_provider") is None + + @pytest.mark.asyncio async def test_router_ageneric_api_call_with_fallbacks_helper(): """