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(realtime): move session ownership marker keys into constants
yassinb4d0f4ad2658
diff --git a/litellm/constants.py b/litellm/constants.pyindex e8aafda1797..c106be688e4 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -317,6 +317,8 @@ WEBSOCKET_CLOSE_REASON_MAX_BYTES: Final = 123BEDROCK_REALTIME_PENDING_SESSION_UPDATE_SCOPE_KEY: Final = "litellm.bedrock_realtime.pending_session_update"BEDROCK_REALTIME_SESSION_COMMITTED_SCOPE_KEY: Final = "litellm.bedrock_realtime.session_committed"BEDROCK_REALTIME_COMMITTED_FAILURE_SCOPE_KEY: Final = "litellm.bedrock_realtime.committed_failure"+REALTIME_SESSION_SUCCESS_LOGGED_KEY: Final = "realtime_session_success_logged"+REALTIME_SESSION_FAILURE_LOGGED_KEY: Final = "realtime_session_failure_logged"# SSL/TLS cipher configuration for faster handshakes# Strategy: Strongly prefer fast modern ciphers, but allow fallback to commonly supported onesdiff --git a/litellm/litellm_core_utils/realtime_streaming.py b/litellm/litellm_core_utils/realtime_streaming.pyindex 2177c999804..fa567bdf4c9 100644--- a/litellm/litellm_core_utils/realtime_streaming.py+++ b/litellm/litellm_core_utils/realtime_streaming.py@@ -10,6 +10,7 @@ from typing_extensions import ReadOnlyimport litellmfrom litellm._logging import redact_internal_details_from_client_message, verbose_logger+from litellm.constants import REALTIME_SESSION_FAILURE_LOGGED_KEY, REALTIME_SESSION_SUCCESS_LOGGED_KEYfrom litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKERfrom litellm.llms.base_llm.realtime.transformation import BaseRealtimeConfigfrom litellm.types.llms.openai import (@@ -35,10 +36,6 @@ else:CLIENT_CONNECTION_CLASS = Any-REALTIME_SESSION_SUCCESS_LOGGED_KEY: Final = "realtime_session_success_logged"-REALTIME_SESSION_FAILURE_LOGGED_KEY: Final = "realtime_session_failure_logged"--@dataclass(frozen=True, slots=True)class BackendClose:code: intdiff --git a/litellm/llms/bedrock/realtime/handler.py b/litellm/llms/bedrock/realtime/handler.pyindex e83cb743aa0..43138b2c526 100644--- a/litellm/llms/bedrock/realtime/handler.py+++ b/litellm/llms/bedrock/realtime/handler.py@@ -20,14 +20,12 @@ from litellm.constants import (BEDROCK_REALTIME_COMMITTED_FAILURE_SCOPE_KEY,BEDROCK_REALTIME_PENDING_SESSION_UPDATE_SCOPE_KEY,BEDROCK_REALTIME_SESSION_COMMITTED_SCOPE_KEY,+ REALTIME_SESSION_SUCCESS_LOGGED_KEY,)from litellm.litellm_core_utils.aws_partition import get_aws_dns_suffixfrom litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingfrom litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER-from litellm.litellm_core_utils.realtime_streaming import (- REALTIME_SESSION_SUCCESS_LOGGED_KEY,- DefaultLoggedRealTimeEventTypes,-)+from litellm.litellm_core_utils.realtime_streaming import DefaultLoggedRealTimeEventTypesfrom litellm.types.llms.openai import OpenAIRealtimeEventsfrom litellm.types.realtime import RealtimeResponseTransformInputdiff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex f499ee04506..1c931863a2f 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -274,6 +274,8 @@ from litellm.constants import (PROXY_BUDGET_RESCHEDULER_MAX_TIME,PROXY_BUDGET_RESCHEDULER_MIN_TIME,PROXY_CONFIG_RELOAD_INTERVAL_SECONDS,+ REALTIME_SESSION_FAILURE_LOGGED_KEY,+ REALTIME_SESSION_SUCCESS_LOGGED_KEY,ROUTER_SETTINGS_MANAGED_OUTSIDE_CONFIG,USER_SPEND_ALERTS_JOB_ID,WEEKLY_SPEND_REPORT_JOB_ID,@@ -12061,11 +12063,6 @@ async def realtime_websocket_endpoint(except Exception: # noqa: BLE001 # the lower layer may have closed the socket already; closing twice is not an errorverbose_proxy_logger.debug("Could not close realtime client websocket; it is already gone")finally:- from litellm.litellm_core_utils.realtime_streaming import (- REALTIME_SESSION_FAILURE_LOGGED_KEY,- REALTIME_SESSION_SUCCESS_LOGGED_KEY,- )-if not litellm_logging_obj.model_call_details.get(REALTIME_SESSION_SUCCESS_LOGGED_KEY):await _release_realtime_budget_reservation(user_api_key_dict)if not litellm_logging_obj.model_call_details.get(REALTIME_SESSION_FAILURE_LOGGED_KEY):diff --git a/tests/test_litellm/litellm_core_utils/test_realtime_streaming.py b/tests/test_litellm/litellm_core_utils/test_realtime_streaming.pyindex e1eb61b59b9..7e6d4d24905 100644--- a/tests/test_litellm/litellm_core_utils/test_realtime_streaming.py+++ b/tests/test_litellm/litellm_core_utils/test_realtime_streaming.py@@ -10,10 +10,9 @@ from websockets.exceptions import ConnectionClosedfrom websockets.frames import Closeimport litellm+from litellm.constants import REALTIME_SESSION_FAILURE_LOGGED_KEY, REALTIME_SESSION_SUCCESS_LOGGED_KEYfrom litellm.integrations.custom_guardrail import CustomGuardrailfrom litellm.litellm_core_utils.realtime_streaming import (- REALTIME_SESSION_FAILURE_LOGGED_KEY,- REALTIME_SESSION_SUCCESS_LOGGED_KEY,RealTimeStreaming,client_sent_openai_beta_realtime_header,)diff --git a/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.py b/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.pyindex 7e418817e74..6c7659d84cd 100644--- a/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.py+++ b/tests/test_litellm/llms/bedrock/realtime/test_bedrock_realtime_handler.py@@ -8,7 +8,7 @@ from unittest.mock import MagicMockimport pytestimport litellm-from litellm.litellm_core_utils.realtime_streaming import REALTIME_SESSION_SUCCESS_LOGGED_KEY+from litellm.constants import REALTIME_SESSION_SUCCESS_LOGGED_KEYfrom litellm.llms.bedrock.common_utils import BedrockErrorfrom litellm.llms.bedrock.realtime.handler import BedrockRealtimefrom litellm.llms.bedrock.realtime.transformation import BedrockRealtimeConfigdiff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.pyindex 64828ae3cb4..e09dddfec5b 100644--- a/tests/test_litellm/proxy/test_proxy_server.py+++ b/tests/test_litellm/proxy/test_proxy_server.py@@ -10020,10 +10020,7 @@ async def _lit6973_drive_realtime_session(logging object carries a real model_call_details dict so the stamp isobservable, and the reservation has empty entries so the real release touchesno counter store."""- from litellm.litellm_core_utils.realtime_streaming import (- REALTIME_SESSION_FAILURE_LOGGED_KEY,- REALTIME_SESSION_SUCCESS_LOGGED_KEY,- )+ from litellm.constants import REALTIME_SESSION_FAILURE_LOGGED_KEY, REALTIME_SESSION_SUCCESS_LOGGED_KEYfrom litellm.proxy import proxy_server as psuser_api_key_dict: Final = UserAPIKeyAuth(api_key="sk-test", token="hashed-token")