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): warn about per-worker login counters even without general_settings
yuchengc3a7b7c3eeb7
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 24532cc051c..138657fd5c3 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -5748,6 +5748,13 @@ class ProxyConfig:general_settings = config.get("general_settings", {})if general_settings is None:general_settings = {}++ ### FAILED-LOGIN ACCOUNTING MULTI-INSTANCE PREREQUISITE CHECK ###+ # Failed Admin UI sign-in counters live in redis_usage_cache when available so a+ # brute-force run is counted once across workers instead of once per worker.+ if os.getenv("NUM_WORKERS", "1") != "1" and redis_usage_cache is None:+ warn_login_counters_are_per_worker(os.getenv("NUM_WORKERS", "1"))+_bg_hc_model_groups: Final = parse_background_health_check_model_groups(general_settings)_enable_hc_routing = False_hc_staleness = None@@ -5844,12 +5851,6 @@ class ProxyConfig:"or ensure sticky sessions for single-instance deployments.")- ### FAILED-LOGIN ACCOUNTING MULTI-INSTANCE PREREQUISITE CHECK ###- # Failed Admin UI sign-in counters live in redis_usage_cache when available so a- # brute-force run is counted once across workers instead of once per worker.- if os.getenv("NUM_WORKERS", "1") != "1" and redis_usage_cache is None:- warn_login_counters_are_per_worker(os.getenv("NUM_WORKERS", "1"))-### STORE MODEL IN DB ### feature flag for `/model/new`store_model_in_db = general_settings.get("store_model_in_db", False)if store_model_in_db is None:diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.pyindex 2f8d5cbc43a..9a41b3a7006 100644--- a/tests/test_litellm/proxy/test_proxy_server.py+++ b/tests/test_litellm/proxy/test_proxy_server.py@@ -3411,6 +3411,30 @@ async def test_load_config_user_url_validation_handles_null_and_string_false(tmpassert litellm.user_url_validation is False+async def test_load_config_warns_per_worker_login_counters_without_general_settings(tmp_path, monkeypatch, caplog):+ """Regression: the failed-login throttle is on by default, so a multi-worker proxy with no+ Redis must hear that its counters are per worker even when the config has no general_settings."""+ import logging++ import litellm.proxy.proxy_server as proxy_server+ from litellm.proxy.auth.login_throttle import warn_login_counters_are_per_worker+ from litellm.proxy.proxy_server import ProxyConfig++ for redis_var in ("REDIS_HOST", "REDIS_URL", "REDIS_CLUSTER_NODES", "REDIS_SENTINEL_NODES"):+ monkeypatch.delenv(redis_var, raising=False)+ monkeypatch.setenv("NUM_WORKERS", "4")+ monkeypatch.setattr(proxy_server, "redis_usage_cache", None)+ warn_login_counters_are_per_worker.cache_clear()+ config_file = tmp_path / "config.yaml"+ config_file.write_text("model_list: []\n")++ with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):+ await ProxyConfig().load_config(router=MagicMock(), config_file_path=str(config_file))++ assert "Running 4 workers but Redis is not configured" in caplog.text++@pytest.mark.asyncioasync def test_load_environment_variables_direct_and_os_environ():"""