diff --git a/litellm/proxy/management_endpoints/common_utils.py b/litellm/proxy/management_endpoints/common_utils.py index 6b3aa6202a0..45d3e795bab 100644 --- a/litellm/proxy/management_endpoints/common_utils.py +++ b/litellm/proxy/management_endpoints/common_utils.py @@ -1,5 +1,5 @@ import os -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from litellm._logging import verbose_proxy_logger from litellm.caching import DualCache diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index d3cddd78301..166e5ee9a3d 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -1960,6 +1960,25 @@ async def update_key_fn( prisma_client=prisma_client, ) + # Step 6d: Key update validation against effective models + if data.models is not None and (data.team_id or existing_key_row.team_id): + team_id_to_check = data.team_id or existing_key_row.team_id + if team_obj is None or team_obj.team_id != team_id_to_check: + team_obj = await get_team_object( + team_id=team_id_to_check, + prisma_client=prisma_client, + user_api_key_cache=user_api_key_cache, + check_db_only=True, + ) + if team_obj is not None: + await _validate_key_models_against_effective_team_models( + team_id=team_id_to_check, + user_id=data.user_id or existing_key_row.user_id, + data=data, + team_table=team_obj, + prisma_client=prisma_client, + ) + # Validate key against project limits if project_id is being set _project_id_to_check = getattr(data, "project_id", None) or getattr( existing_key_row, "project_id", None diff --git a/litellm/proxy/management_helpers/utils.py b/litellm/proxy/management_helpers/utils.py index c10074268ed..76f1ad50d5f 100644 --- a/litellm/proxy/management_helpers/utils.py +++ b/litellm/proxy/management_helpers/utils.py @@ -221,7 +221,7 @@ async def add_new_member( else: _budget_id = default_team_budget_id - if returned_user is not None and returned_user.user_id is not None: + if (_budget_id or models) and returned_user is not None and returned_user.user_id is not None: create_data: Dict[str, Any] = { "team_id": team_id, "user_id": returned_user.user_id,