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
feat(proxy): add disable_auto_add_proxy_admin_to_teams flag (#33563)
ryan-crabbe-berri5ab160113f9f
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.pyindex 053f78a3698..d102c1d1e37 100644--- a/litellm/proxy/_types.py+++ b/litellm/proxy/_types.py@@ -2369,6 +2369,10 @@ class ConfigGeneralSettings(LiteLLMPydanticObjectBase):None,description="If True, stores request messages and responses in spend logs. Default is False.",)+ disable_auto_add_proxy_admin_to_teams: bool | None = Field(+ None,+ description="By default, the user calling /team/new is automatically added to the new team as a team admin. If True, proxy admins are no longer auto-added; members explicitly listed in members_with_roles are unaffected. Default is False.",+ )maximum_spend_logs_retention_period: Optional[str] = Field(None,description="Maximum retention period for spend logs (e.g., '7d' for 7 days). Logs older than this will be deleted.",diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.pyindex d267a3cac69..70c002d2d2d 100644--- a/litellm/proxy/management_endpoints/team_endpoints.py+++ b/litellm/proxy/management_endpoints/team_endpoints.py@@ -14,7 +14,7 @@ import jsonimport mathimport tracebackfrom datetime import datetime, timezone-from typing import Annotated, Any, Dict, List, Optional, Tuple, Union, cast+from typing import Annotated, Any, Dict, List, Mapping, Optional, Tuple, Union, castimport fastapifrom fastapi import APIRouter, Depends, Header, HTTPException, Request, status@@ -894,6 +894,17 @@ def _check_team_budget_update_authority()+def _should_auto_add_team_creator(+ user_api_key_dict: UserAPIKeyAuth,+ general_settings: Mapping[str, object],+) -> bool:+ if user_api_key_dict.user_id is None:+ return False+ if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:+ return True+ return general_settings.get("disable_auto_add_proxy_admin_to_teams") is not True++#### TEAM MANAGEMENT ####@router.post("/team/new",@@ -997,6 +1008,7 @@ async def new_team(from litellm.proxy.proxy_server import (_license_check,create_audit_log_for_update,+ general_settings,litellm_proxy_admin_name,prisma_client,user_api_key_cache,@@ -1123,13 +1135,11 @@ async def new_team(user_api_key_cache=user_api_key_cache,)- if user_api_key_dict.user_id is not None:- creating_user_in_list = False- for member in data.members_with_roles:- if member.user_id == user_api_key_dict.user_id:- creating_user_in_list = True-- if creating_user_in_list is False:+ if _should_auto_add_team_creator(user_api_key_dict, general_settings):+ creating_user_in_list = any(+ member.user_id == user_api_key_dict.user_id for member in data.members_with_roles+ )+ if not creating_user_in_list:data.members_with_roles.append(Member(role="admin", user_id=user_api_key_dict.user_id))_check_passthrough_routes_caller_permission(data, user_api_key_dict, entity="team")diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 7e6ca5a0108..b0eb42b266e 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -5794,6 +5794,13 @@ class ProxyConfig:# For other types, convert to boolgeneral_settings["store_prompts_in_spend_logs"] = bool(value)+ if "disable_auto_add_proxy_admin_to_teams" in _general_settings:+ value = _general_settings["disable_auto_add_proxy_admin_to_teams"]+ if isinstance(value, str):+ general_settings["disable_auto_add_proxy_admin_to_teams"] = value.lower() == "true"+ else:+ general_settings["disable_auto_add_proxy_admin_to_teams"] = value if value is None else bool(value)+## STORE MODEL IN DB ##if "store_model_in_db" in _general_settings:value = _general_settings["store_model_in_db"]@@ -14907,6 +14914,7 @@ async def get_config_list("mcp_required_fields": {"type": "List"},"cancel_on_disconnect": {"type": "Boolean"},"skip_user_budget_on_team_key": {"type": "Boolean"},+ "disable_auto_add_proxy_admin_to_teams": {"type": "Boolean"},}return_val = []diff --git a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.pyindex f7b2df45a85..4936191c344 100644--- a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py@@ -555,6 +555,85 @@ async def test_new_team_with_mcp_tool_permissions(mock_db_client, mock_admin_autassert created_permission_data["mcp_servers"] == ["server_a", "server_b"]+ "user_role,user_id,flag_value,expected",+ [+ (LitellmUserRoles.PROXY_ADMIN, "admin-1", True, False),+ (LitellmUserRoles.PROXY_ADMIN, "admin-1", False, True),+ (LitellmUserRoles.PROXY_ADMIN, "admin-1", None, True),+ (LitellmUserRoles.INTERNAL_USER, "user-1", True, True),+ (LitellmUserRoles.ORG_ADMIN, "org-admin-1", True, True),+ (LitellmUserRoles.PROXY_ADMIN, None, False, False),+ ],+)+def test_should_auto_add_team_creator(user_role, user_id, flag_value, expected):+ from litellm.proxy.management_endpoints.team_endpoints import (+ _should_auto_add_team_creator,+ )++ general_settings = (+ {} if flag_value is None else {"disable_auto_add_proxy_admin_to_teams": flag_value}+ )+ auth = UserAPIKeyAuth(user_role=user_role, user_id=user_id)+ assert _should_auto_add_team_creator(auth, general_settings) is expected+++ "disable_flag,expect_creator_added", [(True, False), (False, True)]+)+async def test_new_team_disable_auto_add_proxy_admin_flag(+ mock_db_client, disable_flag, expect_creator_added+):+ """+ When general_settings.disable_auto_add_proxy_admin_to_teams is True, a proxy+ admin calling /team/new must NOT be auto-added to the team's members. When+ the flag is off, the creator is auto-added as a team admin (default+ behavior, regression guard for LIT-3739).+ """+ mock_db_client.jsonify_team_object = lambda db_data: db_data+ mock_db_client.get_data = AsyncMock(return_value=None)+ mock_db_client.update_data = AsyncMock(return_value=MagicMock())+ mock_db_client.db = MagicMock()++ team_create_result = MagicMock(team_id="team-789")+ team_create_result.model_dump.return_value = {"team_id": "team-789"}+ mock_db_client.db.litellm_teamtable = MagicMock()+ mock_db_client.db.litellm_teamtable.create = AsyncMock(+ return_value=team_create_result+ )+ mock_db_client.db.litellm_teamtable.count = AsyncMock(return_value=0)+ mock_db_client.db.litellm_usertable = MagicMock()+ mock_db_client.db.litellm_usertable.update = AsyncMock(return_value=MagicMock())++ from fastapi import Request++ from litellm.proxy._types import NewTeamRequest+ from litellm.proxy.management_endpoints.team_endpoints import new_team++ admin_auth = UserAPIKeyAuth(+ user_role=LitellmUserRoles.PROXY_ADMIN, user_id="admin-user-1"+ )++ with patch(+ "litellm.proxy.proxy_server.general_settings",+ {"disable_auto_add_proxy_admin_to_teams": disable_flag},+ ), patch(+ "litellm.proxy.management_endpoints.team_endpoints._add_team_members_to_team",+ new_callable=AsyncMock,+ ) as mock_add_members:+ await new_team(+ data=NewTeamRequest(team_alias="flag-test-team"),+ http_request=MagicMock(spec=Request),+ user_api_key_dict=admin_auth,+ )++ mock_add_members.assert_called_once()+ member_add_request = mock_add_members.call_args.kwargs["data"]+ member_user_ids = [m.user_id for m in member_add_request.member]+ assert ("admin-user-1" in member_user_ids) is expect_creator_added++@pytest.mark.asyncioasync def test_team_update_object_permissions_existing_permission(monkeypatch):"""diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.pyindex 079b844638c..2f0e71c4205 100644--- a/tests/test_litellm/proxy/test_proxy_server.py+++ b/tests/test_litellm/proxy/test_proxy_server.py@@ -6265,6 +6265,32 @@ async def test_update_general_settings_store_model_in_db_false():assert ps.general_settings["store_model_in_db"] is False+ "db_value,expected",+ [(True, True), (False, False), ("true", True), ("false", False), (None, None)],+)+async def test_update_general_settings_disable_auto_add_proxy_admin_to_teams(db_value, expected):+ """+ Verify _update_general_settings propagates disable_auto_add_proxy_admin_to_teams+ from the DB config into the live general_settings dict, so a UI toggle via+ /config/field/update takes effect on the next config poll instead of+ requiring a proxy restart.+ """+ from litellm.proxy.proxy_server import ProxyConfig++ proxy_config = ProxyConfig()++ with patch("litellm.proxy.proxy_server.general_settings", {}):+ await proxy_config._update_general_settings(+ db_general_settings={"disable_auto_add_proxy_admin_to_teams": db_value}+ )++ import litellm.proxy.proxy_server as ps++ assert ps.general_settings["disable_auto_add_proxy_admin_to_teams"] is expected++@pytest.mark.asyncioasync def test_update_general_settings_store_model_in_db_string_normalization():"""diff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.tsindex 96e2c450e00..11fc38c7c34 100644--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts@@ -22504,6 +22504,11 @@ export interface components {* @description connect to a postgres db - needed for generating temporary keys + tracking spend / key*/database_url?: string | null;+ /**+ * Disable Auto Add Proxy Admin To Teams+ * @description By default, the user calling /team/new is automatically added to the new team as a team admin. If True, proxy admins are no longer auto-added; members explicitly listed in members_with_roles are unaffected. Default is False.+ */+ disable_auto_add_proxy_admin_to_teams?: boolean | null;/*** Disable Budget Reservation* @description If True, disables the optimistic per-request budget reservation introduced in v1.84.0. WARNING: This weakens hard budget enforcement. Without the reservation, a burst of concurrent requests from a single key can each pass the read-time spend check before any of them is charged, allowing a configured budget to be exceeded under high concurrency. Budgets are still evaluated on every request at read time, so an already-exhausted budget is still rejected. Enable only if your deployment is experiencing phantom BudgetExceededError responses caused by leaked reservations (see GitHub issue #27639). A proxy-level WARNING is logged on every request while this flag is active as a reminder that hard enforcement is relaxed.