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
fix(proxy): check and persist only the settings the request sent
mateo-berri1581c45615cc
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 4654dffcb11..ddee8337609 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -16977,7 +16977,7 @@ async def update_config(proxy_config.reject_config_owned_writes(section_name="general_settings", changed_keys=requested_general_settings)- proxy_config.reject_config_owned_writes(section_name="litellm_settings", changed_keys=updated_litellm_settings)+ proxy_config.reject_config_owned_writes(section_name="litellm_settings", changed_keys=raw_litellm_settings)proxy_config.reject_config_owned_writes(section_name="router_settings", changed_keys=router_settings_updates)async def _read_section(param_name: str) -> dict:@@ -17006,8 +17006,7 @@ async def update_config(if config_info.general_settings is not None:existing = await _read_section("general_settings")before_general_settings: Final = copy.deepcopy(existing)- updates: Mapping[str, JsonValue] = config_info.general_settings.dict(exclude_none=True)- for k, v in updates.items():+ for k, v in requested_general_settings.items():if k == "alert_to_webhook_url":if "alerting" not in existing:existing["alerting"] = ["slack"]diff --git a/tests/proxy_unit_tests/test_proxy_server.py b/tests/proxy_unit_tests/test_proxy_server.pyindex 1fcdaa67143..8d1daa8a3d5 100644--- a/tests/proxy_unit_tests/test_proxy_server.py+++ b/tests/proxy_unit_tests/test_proxy_server.py@@ -3069,6 +3069,9 @@ async def test_update_config_success_callback_normalization():async def add_deployment(self, prisma_client=None, proxy_logging_obj=None): # noqa: F811 # pytest fixture, not a redefinitionreturn None+ def reject_config_owned_writes(self, *, section_name, changed_keys):+ return None+setattr(proxy_server, "proxy_config", MockProxyConfig())config_update = ConfigYAML(litellm_settings={"success_callback": ["SQS", "sQs"]})diff --git a/tests/test_litellm/proxy/proxy_server/test_proxy_config.py b/tests/test_litellm/proxy/proxy_server/test_proxy_config.pyindex 42cd6e4ed78..1e9a93bd019 100644--- a/tests/test_litellm/proxy/proxy_server/test_proxy_config.py+++ b/tests/test_litellm/proxy/proxy_server/test_proxy_config.py@@ -3399,9 +3399,8 @@ async def test_ProxyConfig__add_router_settings_from_db_config_updates_router():fake_prisma.db.litellm_config.find_first = AsyncMock(return_value=SimpleNamespace(param_value={"timeout": 30, "retries": 2, "fallbacks": []}))- config_data = {"router_settings": {"timeout": 10}}+ pc.router_settings.load_yaml({"timeout": 10})await pc._add_router_settings_from_db_config(- config_data=config_data,llm_router=fake_router,prisma_client=fake_prisma,)@@ -3421,7 +3420,7 @@ async def test_ProxyConfig__add_router_settings_from_db_config_updates_router():async def test_ProxyConfig__add_router_settings_from_db_config_none_router_noop():pc = ProxyConfig()# No router and no prisma — should silently return.- await pc._add_router_settings_from_db_config(config_data={}, llm_router=None, prisma_client=None)+ await pc._add_router_settings_from_db_config(llm_router=None, prisma_client=None)# Error-style: bad call signature raises.with pytest.raises(TypeError):await pc._add_router_settings_from_db_config() # type: ignore[call-arg]diff --git a/tests/test_litellm/proxy/proxy_server/test_routes_config.py b/tests/test_litellm/proxy/proxy_server/test_routes_config.pyindex 0a2daf64463..e4d80c86f57 100644--- a/tests/test_litellm/proxy/proxy_server/test_routes_config.py+++ b/tests/test_litellm/proxy/proxy_server/test_routes_config.py@@ -176,6 +176,48 @@ def test_config_update_rejects_config_owned_keys_and_accepts_the_same_value(assert persisted[next(iter(yaml_values))] == yaml_values[next(iter(yaml_values))]+def test_config_update_persists_only_the_general_settings_keys_the_request_set(+ client, auth_as, mock_prisma, monkeypatch+):+ from litellm.proxy import proxy_server as ps+ from litellm.proxy._types import LitellmUserRoles++ table = _install_litellm_config(mock_prisma)+ monkeypatch.setattr(ps, "prisma_client", mock_prisma)+ monkeypatch.setattr(ps.proxy_config, "add_deployment", AsyncMock())+ ps.proxy_config.settings.load_yaml({"health_check_interval": 60})+ try:+ with auth_as(LitellmUserRoles.PROXY_ADMIN):+ response = client.post("/config/update", json={"general_settings": {"alerting_threshold": 600}})+ finally:+ ps.proxy_config.settings.load_yaml({})++ assert response.status_code == 200+ persisted = json.loads(table.upsert.call_args.kwargs["data"]["create"]["param_value"])+ assert persisted == {"alerting_threshold": 600}+++def test_config_update_accepts_a_config_owned_success_callback_the_file_spells_in_mixed_case(+ client, auth_as, mock_prisma, monkeypatch+):+ from litellm.proxy import proxy_server as ps+ from litellm.proxy._types import LitellmUserRoles++ table = _install_litellm_config(mock_prisma)+ monkeypatch.setattr(ps, "prisma_client", mock_prisma)+ monkeypatch.setattr(ps.proxy_config, "add_deployment", AsyncMock())+ ps.proxy_config.litellm_settings.load_yaml({"success_callback": ["Langfuse"]})+ try:+ with auth_as(LitellmUserRoles.PROXY_ADMIN):+ response = client.post("/config/update", json={"litellm_settings": {"success_callback": ["Langfuse"]}})+ finally:+ ps.proxy_config.litellm_settings.load_yaml({})++ assert response.status_code == 200+ persisted = json.loads(table.upsert.call_args.kwargs["data"]["create"]["param_value"])+ assert persisted["success_callback"] == ["langfuse"]++def test_config_update_rejects_assistants_config(client, auth_as, mock_prisma, monkeypatch):from litellm.proxy import proxy_server as psfrom litellm.proxy._types import LitellmUserRoles