Skip to content

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]

Change UI Settings to a dedicated table

yuneng-jiange4442c2946de
diff --git a/litellm-proxy-extras/litellm_proxy_extras/schema.prisma b/litellm-proxy-extras/litellm_proxy_extras/schema.prisma
index 40f00437e58..e227c41f93a 100644
--- a/litellm-proxy-extras/litellm_proxy_extras/schema.prisma
+++ b/litellm-proxy-extras/litellm_proxy_extras/schema.prisma
@@ -688,4 +688,12 @@ model LiteLLM_CacheConfig {
cache_settings Json
created_at DateTime @default(now())
updated_at DateTime @updatedAt
+}
+
+// UI Settings configuration table
+model LiteLLM_UISettings {
+ id String @id @default("ui_settings")
+ ui_settings Json
+ created_at DateTime @default(now())
+ updated_at DateTime @updatedAt
}
\ No newline at end of file
diff --git a/litellm/proxy/schema.prisma b/litellm/proxy/schema.prisma
index 40f00437e58..e227c41f93a 100644
--- a/litellm/proxy/schema.prisma
+++ b/litellm/proxy/schema.prisma
@@ -688,4 +688,12 @@ model LiteLLM_CacheConfig {
cache_settings Json
created_at DateTime @default(now())
updated_at DateTime @updatedAt
+}
+
+// UI Settings configuration table
+model LiteLLM_UISettings {
+ id String @id @default("ui_settings")
+ ui_settings Json
+ created_at DateTime @default(now())
+ updated_at DateTime @updatedAt
}
\ No newline at end of file
diff --git a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py
index cf0960b4423..8aba9a37175 100644
--- a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py
+++ b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py
@@ -1,4 +1,5 @@
#### CRUD ENDPOINTS for UI Settings #####
+import json
from typing import Any, Dict, List, Union, Optional
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File
@@ -678,20 +679,32 @@ async def get_ui_settings():
Get UI-specific configuration flags.
All authenticated users can fetch these settings for client-side behavior.
"""
- from litellm.proxy.proxy_server import proxy_config
+ from litellm.proxy.proxy_server import prisma_client
- config = await proxy_config.get_config()
+ if prisma_client is None:
+ raise HTTPException(
+ status_code=500,
+ detail={"error": "Database not connected. Please connect a database."},
+ )
+
+ ui_settings: Dict[str, Any] = {}
+
+ db_record = await prisma_client.db.litellm_uisettings.find_unique(
+ where={"id": "ui_settings"}
+ )
+
+ if db_record and db_record.ui_settings:
+ ui_settings_json = db_record.ui_settings
+ if isinstance(ui_settings_json, str):
+ ui_settings = json.loads(ui_settings_json)
+ else:
+ ui_settings = dict(ui_settings_json)
# Sanitize any unexpected keys from persisted config before returning
- if (
- "litellm_settings" in config
- and isinstance(config["litellm_settings"].get("ui_settings"), dict)
- ):
- config["litellm_settings"]["ui_settings"] = {
- k: v
- for k, v in config["litellm_settings"]["ui_settings"].items()
- if k in ALLOWED_UI_SETTINGS_FIELDS
- }
+ ui_settings = {k: v for k, v in ui_settings.items() if k in ALLOWED_UI_SETTINGS_FIELDS}
+
+ # Build config-like object for schema helper
+ config: Dict[str, Any] = {"litellm_settings": {"ui_settings": ui_settings}}
return await _get_settings_with_schema(
settings_key="ui_settings",
@@ -712,13 +725,19 @@ async def update_ui_settings(
Update UI-specific configuration flags.
Only proxy admins are allowed to modify these settings.
"""
- from litellm.proxy.proxy_server import proxy_config, store_model_in_db
+ from litellm.proxy.proxy_server import prisma_client, store_model_in_db
if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:
raise HTTPException(
status_code=403, detail="Only proxy admins can update UI settings."
)
+ if prisma_client is None:
+ raise HTTPException(
+ status_code=500,
+ detail={"error": "Database not connected. Please connect a database."},
+ )
+
if store_model_in_db is not True:
raise HTTPException(
status_code=500,
@@ -727,20 +746,25 @@ async def update_ui_settings(
},
)
- config = await proxy_config.get_config()
-
- if "litellm_settings" not in config:
- config["litellm_settings"] = {}
-
settings_dict = settings.model_dump(exclude_none=True)
# Enforce allowlist and drop anything unexpected
ui_settings = {
k: v for k, v in settings_dict.items() if k in ALLOWED_UI_SETTINGS_FIELDS
}
- config["litellm_settings"]["ui_settings"] = ui_settings
- await proxy_config.save_config(new_config=config)
+ await prisma_client.db.litellm_uisettings.upsert(
+ where={"id": "ui_settings"},
+ data={
+ "create": {
+ "id": "ui_settings",
+ "ui_settings": json.dumps(ui_settings),
+ },
+ "update": {
+ "ui_settings": json.dumps(ui_settings),
+ },
+ },
+ )
return {
"message": "UI settings updated successfully",
diff --git a/schema.prisma b/schema.prisma
index 40f00437e58..e227c41f93a 100644
--- a/schema.prisma
+++ b/schema.prisma
@@ -688,4 +688,12 @@ model LiteLLM_CacheConfig {
cache_settings Json
created_at DateTime @default(now())
updated_at DateTime @updatedAt
+}
+
+// UI Settings configuration table
+model LiteLLM_UISettings {
+ id String @id @default("ui_settings")
+ ui_settings Json
+ created_at DateTime @default(now())
+ updated_at DateTime @updatedAt
}
\ No newline at end of file
diff --git a/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py b/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py
index 5730852fc98..d44a63cfacc 100644
--- a/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py
+++ b/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py
@@ -622,12 +622,18 @@ class TestProxySettingEndpoints:
assert "UI_LOGO_PATH" in updated_config["environment_variables"]
assert mock_proxy_config["save_call_count"]() == 1
- def test_get_ui_settings(self, mock_proxy_config, mock_auth):
+ def test_get_ui_settings(self, mock_auth, monkeypatch):
"""Test retrieving UI settings with allowlist sanitization"""
- mock_proxy_config["config"]["litellm_settings"]["ui_settings"] = {
+ from unittest.mock import AsyncMock, MagicMock
+
+ mock_prisma = MagicMock()
+ mock_db_record = MagicMock()
+ mock_db_record.ui_settings = {
"disable_model_add_for_internal_users": True,
"unexpected_flag": True,
}
+ mock_prisma.db.litellm_uisettings.find_unique = AsyncMock(return_value=mock_db_record)
+ monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", mock_prisma)
response = client.get("/get/ui_settings")
@@ -636,11 +642,15 @@ class TestProxySettingEndpoints:
assert data["values"]["disable_model_add_for_internal_users"] is True
assert "unexpected_flag" not in data["values"]
assert "disable_model_add_for_internal_users" in data["field_schema"]["properties"]
+ mock_prisma.db.litellm_uisettings.find_unique.assert_called_once_with(
+ where={"id": "ui_settings"}
+ )
def test_update_ui_settings_allowlisted_value(
- self, mock_proxy_config, mock_auth, monkeypatch
+ self, mock_auth, monkeypatch
):
"""Test updating UI settings with an allowlisted field"""
+ from unittest.mock import AsyncMock, MagicMock
class MockUser:
def __init__(self, user_role):
@@ -654,6 +664,9 @@ class TestProxySettingEndpoints:
mock_admin_auth,
)
monkeypatch.setattr("litellm.proxy.proxy_server.store_model_in_db", True)
+ mock_prisma = MagicMock()
+ mock_prisma.db.litellm_uisettings.upsert = AsyncMock()
+ monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", mock_prisma)
payload = {"disable_model_add_for_internal_users": True}
@@ -664,14 +677,18 @@ class TestProxySettingEndpoints:
assert data["status"] == "success"
assert data["settings"]["disable_model_add_for_internal_users"] is True
- ui_settings = mock_proxy_config["config"]["litellm_settings"]["ui_settings"]
- assert ui_settings["disable_model_add_for_internal_users"] is True
- assert mock_proxy_config["save_call_count"]() == 1
+ assert mock_prisma.db.litellm_uisettings.upsert.called
+ call_args = mock_prisma.db.litellm_uisettings.upsert.call_args
+ assert call_args.kwargs["where"]["id"] == "ui_settings"
+ create_data = call_args.kwargs["data"]["create"]
+ stored_settings = json.loads(create_data["ui_settings"])
+ assert stored_settings["disable_model_add_for_internal_users"] is True
def test_update_ui_settings_ignores_non_allowlisted_value(
- self, mock_proxy_config, mock_auth, monkeypatch
+ self, mock_auth, monkeypatch
):
"""Test non-allowlisted UI settings are ignored on update"""
+ from unittest.mock import AsyncMock, MagicMock
class MockUser:
def __init__(self, user_role):
@@ -685,6 +702,9 @@ class TestProxySettingEndpoints:
mock_admin_auth,
)
monkeypatch.setattr("litellm.proxy.proxy_server.store_model_in_db", True)
+ mock_prisma = MagicMock()
+ mock_prisma.db.litellm_uisettings.upsert = AsyncMock()
+ monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", mock_prisma)
payload = {
"disable_model_add_for_internal_users": False,
@@ -699,10 +719,11 @@ class TestProxySettingEndpoints:
assert "unsupported_flag" not in data["settings"]
assert data["settings"]["disable_model_add_for_internal_users"] is False
- ui_settings = mock_proxy_config["config"]["litellm_settings"]["ui_settings"]
- assert "unsupported_flag" not in ui_settings
- assert ui_settings["disable_model_add_for_internal_users"] is False
- assert mock_proxy_config["save_call_count"]() == 1
+ assert mock_prisma.db.litellm_uisettings.upsert.called
+ call_args = mock_prisma.db.litellm_uisettings.upsert.call_args
+ stored_settings = json.loads(call_args.kwargs["data"]["create"]["ui_settings"])
+ assert "unsupported_flag" not in stored_settings
+ assert stored_settings["disable_model_add_for_internal_users"] is False
def test_get_sso_settings_from_database(self, mock_proxy_config, mock_auth, monkeypatch):
"""Test getting SSO settings from the dedicated database table"""