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
Add native_background_mode to override polling_via_cache for specific models
Xianzong Xie0b8c10c48828
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 183c25ed463..cf5d133bc33 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -1224,6 +1224,7 @@ redis_usage_cache: Optional[RedisCache] = None # redis cache used for tracking spend, tpm/rpm limitspolling_via_cache_enabled: Union[Literal["all"], List[str], bool] = False+native_background_mode: List[str] = [] # Models that should use native provider background mode instead of pollingpolling_cache_ttl: int = 3600 # Default 1 hour TTL for polling cacheuser_custom_auth = Noneuser_custom_key_generate = None@@ -2456,14 +2457,17 @@ class ProxyConfig:passelif key == "responses":# Initialize global polling via cache settings- global polling_via_cache_enabled, polling_cache_ttl+ global polling_via_cache_enabled, native_background_mode, polling_cache_ttlbackground_mode = value.get("background_mode", {})polling_via_cache_enabled = background_mode.get("polling_via_cache", False)+ native_background_mode = background_mode.get(+ "native_background_mode", []+ )polling_cache_ttl = background_mode.get("ttl", 3600)verbose_proxy_logger.debug(- f"{blue_color_code} Initialized polling via cache: enabled={polling_via_cache_enabled}, ttl={polling_cache_ttl}{reset_color_code}"+ f"{blue_color_code} Initialized polling via cache: enabled={polling_via_cache_enabled}, native_background_mode={native_background_mode}, ttl={polling_cache_ttl}{reset_color_code}")elif key == "default_team_settings":for idx, team_setting in enumerate(diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.pyindex ec1bc5497bd..44e8c42b2c1 100644--- a/litellm/proxy/response_api_endpoints/endpoints.py+++ b/litellm/proxy/response_api_endpoints/endpoints.py@@ -68,6 +68,7 @@ async def responses_api(_read_request_body,general_settings,llm_router,+ native_background_mode,polling_cache_ttl,polling_via_cache_enabled,proxy_config,@@ -95,6 +96,7 @@ async def responses_api(redis_cache=redis_usage_cache,model=data.get("model", ""),llm_router=llm_router,+ native_background_mode=native_background_mode,)# If polling is enabled, use polling modediff --git a/litellm/proxy/response_polling/polling_handler.py b/litellm/proxy/response_polling/polling_handler.pyindex c47578c8d7b..f0b850049bf 100644--- a/litellm/proxy/response_polling/polling_handler.py+++ b/litellm/proxy/response_polling/polling_handler.py@@ -3,7 +3,7 @@ Response Polling Handler for Background Responses with Cache"""import jsonfrom datetime import datetime, timezone-from typing import Any, Dict, Optional+from typing import Any, Dict, List, Optionalfrom litellm._logging import verbose_proxy_loggerfrom litellm._uuid import uuid4@@ -257,6 +257,7 @@ def should_use_polling_for_request(redis_cache, # RedisCache or Nonemodel: str,llm_router, # Router instance or None+ native_background_mode: Optional[List[str]] = None, # List of models that should use native background mode) -> bool:"""Determine if polling via cache should be used for a request.@@ -267,6 +268,8 @@ def should_use_polling_for_request(redis_cache: Redis cache instance (required for polling)model: Model name from the request (e.g., "gpt-5" or "openai/gpt-4o")llm_router: LiteLLM router instance for looking up model deployments+ native_background_mode: List of model names that should use native provider+ background mode instead of polling via cacheReturns:True if polling should be used, False otherwise@@ -275,6 +278,13 @@ def should_use_polling_for_request(if not (background_mode and polling_via_cache_enabled and redis_cache):return False+ # Check if model is in native_background_mode list - these use native provider background mode+ if native_background_mode and model in native_background_mode:+ verbose_proxy_logger.debug(+ f"Model {model} is in native_background_mode list, skipping polling via cache"+ )+ return False+# "all" enables polling for all providersif polling_via_cache_enabled == "all":return True