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]: optimize SSL/TLS handshake performance with prioritized cipher (#15398)
Alexsander Hamir1c7463f42fd2
diff --git a/docs/my-website/docs/proxy/config_settings.md b/docs/my-website/docs/proxy/config_settings.mdindex c674af1237d..5135f708e01 100644--- a/docs/my-website/docs/proxy/config_settings.md+++ b/docs/my-website/docs/proxy/config_settings.md@@ -353,7 +353,10 @@ router_settings:| AGENTOPS_SERVICE_NAME | Service Name for AgentOps logging integration| AISPEND_ACCOUNT_ID | Account ID for AI Spend| AISPEND_API_KEY | API Key for AI Spend+| AIOHTTP_CONNECTOR_LIMIT | Connection limit for aiohttp connector. When set to 0, no limit is applied. **Default is 0**+| AIOHTTP_KEEPALIVE_TIMEOUT | Keep-alive timeout for aiohttp connections in seconds. **Default is 120**| AIOHTTP_TRUST_ENV | Flag to enable aiohttp trust environment. When this is set to True, aiohttp will respect HTTP(S)_PROXY env vars. **Default is False**+| AIOHTTP_TTL_DNS_CACHE | DNS cache time-to-live for aiohttp in seconds. **Default is 300**| ALLOWED_EMAIL_DOMAINS | List of email domains allowed for access| ARIZE_API_KEY | API key for Arize platform integration| ARIZE_SPACE_KEY | Space key for Arize platform@@ -506,6 +509,8 @@ router_settings:| EMAIL_SIGNATURE | Custom HTML footer/signature for all emails. Can include HTML tags for formatting and links.| EMAIL_SUBJECT_INVITATION | Custom subject template for invitation emails.| EMAIL_SUBJECT_KEY_CREATED | Custom subject template for key creation emails.+| ENKRYPTAI_API_BASE | Base URL for EnkryptAI Guardrails API. **Default is https://api.enkryptai.com**+| ENKRYPTAI_API_KEY | API key for EnkryptAI Guardrails service| EXPERIMENTAL_MULTI_INSTANCE_RATE_LIMITING | Flag to enable new multi-instance rate limiting. **Default is False**| FIREWORKS_AI_4_B | Size parameter for Fireworks AI 4B model. Default is 4| FIREWORKS_AI_16_B | Size parameter for Fireworks AI 16B model. Default is 16@@ -629,6 +634,7 @@ router_settings:| LITELLM_MODE | Operating mode for LiteLLM (e.g., production, development)| LITELLM_RATE_LIMIT_WINDOW_SIZE | Rate limit window size for LiteLLM. Default is 60| LITELLM_SALT_KEY | Salt key for encryption in LiteLLM+| LITELLM_SSL_CIPHERS | SSL/TLS cipher configuration for faster handshakes. Controls cipher suite preferences for OpenSSL connections.| LITELLM_SECRET_AWS_KMS_LITELLM_LICENSE | AWS KMS encrypted license for LiteLLM| LITELLM_TOKEN | Access token for LiteLLM integration| LITELLM_PRINT_STANDARD_LOGGING_PAYLOAD | If true, prints the standard logging payload to the console - useful for debuggingdiff --git a/litellm/constants.py b/litellm/constants.pyindex d41266a0001..392abbee2d8 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -92,6 +92,30 @@ AIOHTTP_CONNECTOR_LIMIT = int(os.getenv("AIOHTTP_CONNECTOR_LIMIT", 0))AIOHTTP_KEEPALIVE_TIMEOUT = int(os.getenv("AIOHTTP_KEEPALIVE_TIMEOUT", 120))AIOHTTP_TTL_DNS_CACHE = int(os.getenv("AIOHTTP_TTL_DNS_CACHE", 300))+# SSL/TLS cipher configuration for faster handshakes+# Strategy: Strongly prefer fast modern ciphers, but allow fallback to commonly supported ones+# This balances performance with broad compatibility+DEFAULT_SSL_CIPHERS = os.getenv(+ "LITELLM_SSL_CIPHERS",+ # Priority 1: TLS 1.3 ciphers (fastest, ~50ms handshake)+ "TLS_AES_256_GCM_SHA384:" # Fastest observed in testing+ "TLS_AES_128_GCM_SHA256:" # Slightly faster than 256-bit+ "TLS_CHACHA20_POLY1305_SHA256:" # Fast on ARM/mobile+ # Priority 2: TLS 1.2 ECDHE+GCM (fast, ~100ms handshake, widely supported)+ "ECDHE-RSA-AES256-GCM-SHA384:"+ "ECDHE-RSA-AES128-GCM-SHA256:"+ "ECDHE-ECDSA-AES256-GCM-SHA384:"+ "ECDHE-ECDSA-AES128-GCM-SHA256:"+ # Priority 3: Additional modern ciphers (good balance)+ "ECDHE-RSA-CHACHA20-POLY1305:"+ "ECDHE-ECDSA-CHACHA20-POLY1305:"+ # Priority 4: Widely compatible fallbacks (slower but universally supported)+ "ECDHE-RSA-AES256-SHA384:" # Common fallback+ "ECDHE-RSA-AES128-SHA256:" # Very widely supported+ "AES256-GCM-SHA384:" # Non-PFS fallback (compatibility)+ "AES128-GCM-SHA256", # Last resort (maximum compatibility)+)+########### v2 Architecture constants for managing writing updates to the database ###########REDIS_UPDATE_BUFFER_KEY = "litellm_spend_update_buffer"REDIS_DAILY_SPEND_UPDATE_BUFFER_KEY = "litellm_daily_spend_update_buffer"diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.pyindex 1c8664e368a..a3ad2c67272 100644--- a/litellm/llms/custom_httpx/http_handler.py+++ b/litellm/llms/custom_httpx/http_handler.py@@ -17,6 +17,7 @@ from litellm.constants import (AIOHTTP_CONNECTOR_LIMIT,AIOHTTP_KEEPALIVE_TIMEOUT,AIOHTTP_TTL_DNS_CACHE,+ DEFAULT_SSL_CIPHERS)from litellm.litellm_core_utils.logging_utils import track_llm_api_timingfrom litellm.types.llms.custom_http import *@@ -99,10 +100,19 @@ def get_ssl_configuration(if ssl_verify is not False:custom_ssl_context = ssl.create_default_context(cafile=cafile)- # If security level is set, apply it to the SSL context++ # Optimize SSL handshake performance+ # Set minimum TLS version to 1.2 for better performance+ custom_ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2++ # Configure cipher suites for optimal performanceif ssl_security_level and isinstance(ssl_security_level, str):- # Create a custom SSL context with reduced security level+ # User provided custom cipher configuration (e.g., via SSL_SECURITY_LEVEL env var)custom_ssl_context.set_ciphers(ssl_security_level)+ else:+ # Use optimized cipher list that strongly prefers fast ciphers+ # but falls back to widely compatible ones+ custom_ssl_context.set_ciphers(DEFAULT_SSL_CIPHERS)# Use our custom SSL context instead of the original ssl_verify valuereturn custom_ssl_context