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
perf: increase default LRU cache size to reduce multi-model thrash (#21139)
Emerson Gomes93b848494d8b
diff --git a/docs/my-website/docs/proxy/config_settings.md b/docs/my-website/docs/proxy/config_settings.mdindex 775cdf6876a..7a927c57e6e 100644--- a/docs/my-website/docs/proxy/config_settings.md+++ b/docs/my-website/docs/proxy/config_settings.md@@ -540,7 +540,7 @@ router_settings:| DEFAULT_IMAGE_WIDTH | Default width for images. Default is 300| DEFAULT_IN_MEMORY_TTL | Default time-to-live for in-memory cache in seconds. Default is 5| DEFAULT_MANAGEMENT_OBJECT_IN_MEMORY_CACHE_TTL | Default time-to-live in seconds for management objects (User, Team, Key, Organization) in memory cache. Default is 60 seconds.-| DEFAULT_MAX_LRU_CACHE_SIZE | Default maximum size for LRU cache. Default is 16+| DEFAULT_MAX_LRU_CACHE_SIZE | Default maximum size for LRU cache. Default is 64| DEFAULT_MAX_RECURSE_DEPTH | Default maximum recursion depth. Default is 100| DEFAULT_MAX_RECURSE_DEPTH_SENSITIVE_DATA_MASKER | Default maximum recursion depth for sensitive data masker. Default is 10| DEFAULT_MAX_RETRIES | Default maximum retry attempts. Default is 2diff --git a/litellm/constants.py b/litellm/constants.pyindex 458f48cb0b6..05aa96d190c 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -287,7 +287,9 @@ MIN_NON_ZERO_TEMPERATURE = float(os.getenv("MIN_NON_ZERO_TEMPERATURE", 0.0001))REPEATED_STREAMING_CHUNK_LIMIT = int(os.getenv("REPEATED_STREAMING_CHUNK_LIMIT", 100)) # catch if model starts looping the same chunk while streaming. Uses high default to prevent false positives.-DEFAULT_MAX_LRU_CACHE_SIZE = int(os.getenv("DEFAULT_MAX_LRU_CACHE_SIZE", 16))+# Shared maxsize for functools.lru_cache usage across hot paths.+# Defaulted to 64 to avoid cache thrash in multi-model production workloads.+DEFAULT_MAX_LRU_CACHE_SIZE = int(os.getenv("DEFAULT_MAX_LRU_CACHE_SIZE", 64))_REALTIME_BODY_CACHE_SIZE = 1000 # Keep realtime helper caches bounded; workloads rarely exceed 1k models/intentsINITIAL_RETRY_DELAY = float(os.getenv("INITIAL_RETRY_DELAY", 0.5))MAX_RETRY_DELAY = float(os.getenv("MAX_RETRY_DELAY", 8.0))