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
refactor(proxy): raise the sign-in block explicitly and type the empty settings mapping
yuchengb6bb212248ff
diff --git a/litellm/proxy/auth/login_throttle.py b/litellm/proxy/auth/login_throttle.pyindex 012d557f334..2ad75463629 100644--- a/litellm/proxy/auth/login_throttle.py+++ b/litellm/proxy/auth/login_throttle.py@@ -17,7 +17,7 @@ import timefrom collections.abc import Mappingfrom dataclasses import dataclassfrom functools import cache-from typing import Final, Literal, NamedTuple, NoReturn, Protocol, TypeAlias+from typing import Final, Literal, NamedTuple, Protocol, TypeAliasfrom fastapi import Request, statusfrom pydantic import TypeAdapter, ValidationError@@ -256,7 +256,7 @@ class LoginThrottle:general_settings: Mapping[str, object] | None,redis_cache: RedisCache | None,) -> LoginThrottle:- settings: Final = general_settings if general_settings is not None else EMPTY_MAPPING+ settings: Final[Mapping[str, object]] = general_settings if general_settings is not None else EMPTY_MAPPINGproxies: Final = declared_proxy_ranges(settings)resolved, _ = resolve_client_ip(request, TrustedProxyConfig(use_forwarded_for=bool(proxies), trusted_proxy_cidrs=proxies or ())@@ -298,7 +298,7 @@ class LoginThrottle:username,self.client_ip,)- self.refuse(block.retry_after)+ raise self.refused(block.retry_after)async def _active_block(self, keys: _Keys) -> Block | None:local: Final = self._local_block_ttls(keys)@@ -375,8 +375,8 @@ class LoginThrottle:)@staticmethod- def refuse(retry_after: int) -> NoReturn:- raise ProxyException(+ def refused(retry_after: int) -> ProxyException:+ return ProxyException(message="Too many failed sign-in attempts. Try again later.",type=ProxyErrorTypes.auth_error,param="username",diff --git a/tests/test_litellm/proxy/auth/test_login_utils.py b/tests/test_litellm/proxy/auth/test_login_utils.pyindex d6a094d56cb..4d4a10a9fa4 100644--- a/tests/test_litellm/proxy/auth/test_login_utils.py+++ b/tests/test_litellm/proxy/auth/test_login_utils.py@@ -1436,8 +1436,8 @@ async def test_a_failed_redis_delete_still_clears_this_workers_counter(monkeypat@pytest.mark.asyncioasync def test_counters_do_not_share_the_key_authentication_cache(monkeypatch):"""Regression: throttle entries must not evict cached credentials from user_api_key_cache."""- from litellm.proxy import proxy_server as psfrom litellm.constants import LOGIN_THROTTLE_CACHE_KEY_PREFIX+ from litellm.proxy import proxy_server as psfrom litellm.proxy.auth.login_throttle import LoginThrottlemonkeypatch.setenv("UI_USERNAME", "admin")