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: preserve config update authorization order
mateocb511f70ccbe
diff --git a/litellm/constants.py b/litellm/constants.pyindex a7506cb6378..5b44e8b5f51 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -9,6 +9,28 @@ DEFAULT_HEALTH_CHECK_PROMPT: Final = str(os.getenv("DEFAULT_HEALTH_CHECK_PROMPT"AZURE_DEFAULT_RESPONSES_API_VERSION: Final = str(os.getenv("AZURE_DEFAULT_RESPONSES_API_VERSION", "preview"))ROUTER_MAX_FALLBACKS: Final = int(os.getenv("ROUTER_MAX_FALLBACKS", 5))ROUTER_FALLBACK_ERROR_DETAIL_MAX_CHARS: Final = 2000+RUNTIME_UPDATABLE_ROUTER_SETTINGS: Final[frozenset[str]] = frozenset(+ {+ "routing_strategy_args",+ "routing_strategy",+ "routing_groups",+ "allowed_fails",+ "cooldown_time",+ "num_retries",+ "timeout",+ "max_retries",+ "retry_after",+ "fallbacks",+ "context_window_fallbacks",+ "retry_policy",+ "model_group_retry_policy",+ "model_group_alias",+ "enable_weighted_failover",+ "enable_tag_filtering",+ "tag_routing_prefix",+ "optional_pre_call_checks",+ }+)DEFAULT_BATCH_SIZE: Final = int(os.getenv("DEFAULT_BATCH_SIZE", 512))DEFAULT_FLUSH_INTERVAL_SECONDS: Final = int(os.getenv("DEFAULT_FLUSH_INTERVAL_SECONDS", 5))DEFAULT_S3_FLUSH_INTERVAL_SECONDS: Final = int(os.getenv("DEFAULT_S3_FLUSH_INTERVAL_SECONDS", 10))@@ -38,28 +60,6 @@ DEFAULT_MAX_TOKENS: Final = int(os.getenv("DEFAULT_MAX_TOKENS", 4096))DEFAULT_ALLOWED_FAILS: Final = int(os.getenv("DEFAULT_ALLOWED_FAILS", 3))DEFAULT_REDIS_SYNC_INTERVAL: Final = int(os.getenv("DEFAULT_REDIS_SYNC_INTERVAL", 1))DEFAULT_COOLDOWN_TIME_SECONDS: Final = int(os.getenv("DEFAULT_COOLDOWN_TIME_SECONDS", 5))-RUNTIME_UPDATABLE_ROUTER_SETTINGS: Final[frozenset[str]] = frozenset(- {- "routing_strategy_args",- "routing_strategy",- "routing_groups",- "allowed_fails",- "cooldown_time",- "num_retries",- "timeout",- "max_retries",- "retry_after",- "fallbacks",- "context_window_fallbacks",- "retry_policy",- "model_group_retry_policy",- "model_group_alias",- "enable_weighted_failover",- "enable_tag_filtering",- "tag_routing_prefix",- "optional_pre_call_checks",- }-)DEFAULT_REPLICATE_POLLING_RETRIES: Final = int(os.getenv("DEFAULT_REPLICATE_POLLING_RETRIES", 5))DEFAULT_REPLICATE_POLLING_DELAY_SECONDS: Final = int(os.getenv("DEFAULT_REPLICATE_POLLING_DELAY_SECONDS", 1))DEFAULT_IMAGE_TOKEN_COUNT: Final = int(os.getenv("DEFAULT_IMAGE_TOKEN_COUNT", 250))diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 9de6b38265a..dbeb8486539 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -16220,27 +16220,27 @@ async def update_config(a side effect of an unrelated update."""global llm_router, llm_model_list, general_settings, proxy_config, proxy_logging_obj, master_key, prisma_client- request_body: Final[Mapping[str, JsonValue]] = TypeAdapter(Mapping[str, JsonValue]).validate_python(- await request.json()- )- raw_router_settings: Final = request_body.get("router_settings")- if isinstance(raw_router_settings, dict):- unsupported_router_settings: Final = sorted(set(raw_router_settings) - RUNTIME_UPDATABLE_ROUTER_SETTINGS)- if unsupported_router_settings:- raise HTTPException(- status_code=400,- detail={- "error": (- f"Unsupported router settings: {', '.join(unsupported_router_settings)} "- "are not runtime-updatable router settings"- )- },- )-try:if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:raise HTTPException(status_code=403, detail="Only proxy admins can update config")+ request_body: Final[Mapping[str, JsonValue]] = TypeAdapter(Mapping[str, JsonValue]).validate_python(+ await request.json()+ )+ raw_router_settings: Final = request_body.get("router_settings")+ if isinstance(raw_router_settings, dict):+ unsupported_router_settings: Final = sorted(set(raw_router_settings) - RUNTIME_UPDATABLE_ROUTER_SETTINGS)+ if unsupported_router_settings:+ raise HTTPException(+ status_code=400,+ detail={+ "error": (+ f"Unsupported router settings: {', '.join(unsupported_router_settings)} "+ "are not runtime-updatable router settings"+ )+ },+ )+if prisma_client is None:raise Exception("No DB Connected")diff --git a/tests/test_litellm/proxy/proxy_server/test_routes_config.py b/tests/test_litellm/proxy/proxy_server/test_routes_config.pyindex 0df8fb663e2..4b0954c350a 100644--- a/tests/test_litellm/proxy/proxy_server/test_routes_config.py+++ b/tests/test_litellm/proxy/proxy_server/test_routes_config.py@@ -95,10 +95,27 @@ def test_config_update_rejects_unknown_router_setting(client, auth_as, mock_pris)assert response.status_code == 400- assert "optional_precall_checks" in response.json()["detail"]["error"]+ assert "optional_precall_checks" in response.json()["error"]["message"]table.upsert.assert_not_called()+def test_config_update_unknown_router_setting_non_admin_forbidden(client, auth_as, mock_prisma, monkeypatch):+ from litellm.proxy import proxy_server as ps+ from litellm.proxy._types import LitellmUserRoles++ _install_litellm_config(mock_prisma)+ monkeypatch.setattr(ps, "prisma_client", mock_prisma)++ with auth_as(LitellmUserRoles.INTERNAL_USER):+ response = client.post(+ "/config/update",+ json={"router_settings": {"optional_precall_checks": ["prompt_caching"]}},+ )++ assert response.status_code == 403+ assert "admin" in response.json()["error"]["message"].lower()++def test_config_update_non_admin_forbidden(client, auth_as, mock_prisma, monkeypatch):"""POST /config/update by a non-admin caller is rejected; the errorsurfaces as a ProxyException with the admin-only message."""diff --git a/tests/test_litellm/test_router_retry_policy_update.py b/tests/test_litellm/test_router_retry_policy_update.pyindex 1b014cd8401..e386eebf3d9 100644--- a/tests/test_litellm/test_router_retry_policy_update.py+++ b/tests/test_litellm/test_router_retry_policy_update.py@@ -26,6 +26,7 @@ from unittest.mock import AsyncMock, MagicMockimport pytestfrom pydantic import ValidationError+import litellmfrom litellm.router_utils.pre_call_checks.prompt_caching_deployment_check import PromptCachingDeploymentCheckfrom litellm.types.router import RetryPolicy, UpdateRouterConfig@@ -241,7 +242,7 @@ async def test_config_update_persists_and_reads_back_retry_policy(monkeypatch):"""The exact global retry_policy save the UI performs must survive thereal ``/config/update`` -> DB -> apply -> ``/get/config/callbacks`` path,not snap back to the ``num_retries`` fallback the ticket reported."""- from litellm.proxy import proxy_server+ import litellm.proxy.proxy_server as proxy_serverfrom litellm.proxy._types import ConfigYAML, LitellmUserRoles, UserAPIKeyAuthrouter = _build_router()