[Feat - UI] - Allow setting Default Team setting when LiteLLM SSO auto creates teams (#9918)

* endpoint for updating default team settings on ui

* add GET default team settings endpoint

* ui expose default team settings on UI

* update to use DefaultTeamSSOParams

* DefaultTeamSSOParams

* fix DefaultTeamSSOParams

* docs team management

* test_update_default_team_settings
This commit is contained in:
Ishaan Jaff 2025-04-11 14:07:10 -07:00 committed by GitHub
parent c4ea1ab61b
commit 8b1d2d6956
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 646 additions and 61 deletions

View file

@ -1,5 +1,5 @@
#### CRUD ENDPOINTS for UI Settings #####
from typing import List
from typing import Any, List, Union
from fastapi import APIRouter, Depends, HTTPException
@ -7,6 +7,7 @@ import litellm
from litellm._logging import verbose_proxy_logger
from litellm.proxy._types import *
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.types.proxy.management_endpoints.ui_sso import DefaultTeamSSOParams
router = APIRouter()
@ -111,34 +112,31 @@ async def delete_allowed_ip(ip_address: IPAddress):
return {"message": f"IP {ip_address.ip} deleted successfully", "status": "success"}
@router.get(
"/get/internal_user_settings",
tags=["SSO Settings"],
dependencies=[Depends(user_api_key_auth)],
)
async def get_sso_settings():
async def _get_settings_with_schema(
settings_key: str,
settings_class: Any,
config: dict,
) -> dict:
"""
Get all SSO settings from the litellm_settings configuration.
Returns a structured object with values and descriptions for UI display.
Common utility function to get settings with schema information.
Args:
settings_key: The key in litellm_settings to get
settings_class: The Pydantic class to use for schema
config: The config dictionary
"""
from pydantic import TypeAdapter
from litellm.proxy.proxy_server import proxy_config
# Load existing config
config = await proxy_config.get_config()
litellm_settings = config.get("litellm_settings", {}) or {}
default_internal_user_params = (
litellm_settings.get("default_internal_user_params", {}) or {}
)
settings_data = litellm_settings.get(settings_key, {}) or {}
# Create the settings object first
sso_settings = DefaultInternalUserParams(**(default_internal_user_params))
# Get the schema for UISSOSettings
schema = TypeAdapter(DefaultInternalUserParams).json_schema(by_alias=True)
# Create the settings object
settings = settings_class(**(settings_data))
# Get the schema
schema = TypeAdapter(settings_class).json_schema(by_alias=True)
# Convert to dict for response
settings_dict = sso_settings.model_dump()
settings_dict = settings.model_dump()
# Add descriptions to the response
result = {
@ -166,6 +164,89 @@ async def get_sso_settings():
return result
@router.get(
"/get/internal_user_settings",
tags=["SSO Settings"],
dependencies=[Depends(user_api_key_auth)],
)
async def get_sso_settings():
"""
Get all SSO settings from the litellm_settings configuration.
Returns a structured object with values and descriptions for UI display.
"""
from litellm.proxy.proxy_server import proxy_config
# Load existing config
config = await proxy_config.get_config()
return await _get_settings_with_schema(
settings_key="default_internal_user_params",
settings_class=DefaultInternalUserParams,
config=config,
)
@router.get(
"/get/default_team_settings",
tags=["SSO Settings"],
dependencies=[Depends(user_api_key_auth)],
)
async def get_default_team_settings():
"""
Get all SSO settings from the litellm_settings configuration.
Returns a structured object with values and descriptions for UI display.
"""
from litellm.proxy.proxy_server import proxy_config
# Load existing config
config = await proxy_config.get_config()
return await _get_settings_with_schema(
settings_key="default_team_params",
settings_class=DefaultTeamSSOParams,
config=config,
)
async def _update_litellm_setting(
settings: Union[DefaultInternalUserParams, DefaultTeamSSOParams],
settings_key: str,
in_memory_var: Any,
success_message: str,
):
"""
Common utility function to update `litellm_settings` in both memory and config.
Args:
settings: The settings object to update
settings_key: The key in litellm_settings to update
in_memory_var: The in-memory variable to update
success_message: Message to return on success
"""
from litellm.proxy.proxy_server import proxy_config
# Update the in-memory settings
in_memory_var = settings.model_dump(exclude_none=True)
# Load existing config
config = await proxy_config.get_config()
# Update config with new settings
if "litellm_settings" not in config:
config["litellm_settings"] = {}
config["litellm_settings"][settings_key] = settings.model_dump(exclude_none=True)
# Save the updated config
await proxy_config.save_config(new_config=config)
return {
"message": success_message,
"status": "success",
"settings": in_memory_var,
}
@router.patch(
"/update/internal_user_settings",
tags=["SSO Settings"],
@ -176,27 +257,27 @@ async def update_internal_user_settings(settings: DefaultInternalUserParams):
Update the default internal user parameters for SSO users.
These settings will be applied to new users who sign in via SSO.
"""
from litellm.proxy.proxy_server import proxy_config
# Update the in-memory settings
litellm.default_internal_user_params = settings.model_dump(exclude_none=True)
# Load existing config
config = await proxy_config.get_config()
# Update config with new settings
if "litellm_settings" not in config:
config["litellm_settings"] = {}
config["litellm_settings"]["default_internal_user_params"] = settings.model_dump(
exclude_none=True
return await _update_litellm_setting(
settings=settings,
settings_key="default_internal_user_params",
in_memory_var=litellm.default_internal_user_params,
success_message="Internal user settings updated successfully",
)
# Save the updated config
await proxy_config.save_config(new_config=config)
return {
"message": "Internal user settings updated successfully",
"status": "success",
"settings": litellm.default_internal_user_params,
}
@router.patch(
"/update/default_team_settings",
tags=["SSO Settings"],
dependencies=[Depends(user_api_key_auth)],
)
async def update_default_team_settings(settings: DefaultTeamSSOParams):
"""
Update the default team parameters for SSO users.
These settings will be applied to new teams created from SSO.
"""
return await _update_litellm_setting(
settings=settings,
settings_key="default_team_params",
in_memory_var=litellm.default_team_params,
success_message="Default team settings updated successfully",
)