From 099d9b3cc89416147d125ca057b169b184c8da31 Mon Sep 17 00:00:00 2001 From: Emerson Gomes Date: Sat, 26 Sep 2026 09:03:44 -0500 Subject: [PATCH] refactor(realtime): align annotations with current lint rules --- litellm/litellm_core_utils/realtime_streaming.py | 3 +-- litellm/llms/custom_httpx/llm_http_handler.py | 2 +- .../llms/openai/transcriptions/gpt_transformation.py | 4 +--- litellm/llms/openai/transcriptions/handler.py | 8 +++++--- litellm/proxy/realtime_endpoints/endpoints.py | 10 +++------- litellm/realtime_api/main.py | 10 ++++++---- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/litellm/litellm_core_utils/realtime_streaming.py b/litellm/litellm_core_utils/realtime_streaming.py index 8d05ea17da0..d762082572a 100644 --- a/litellm/litellm_core_utils/realtime_streaming.py +++ b/litellm/litellm_core_utils/realtime_streaming.py @@ -648,9 +648,8 @@ class RealTimeStreaming: for event in self.messages: if event.get("type") != "session.closed": continue - event_usage = event.get("usage") # rebind-ok: each close event carries independent usage if ( - isinstance(event_usage, dict) + isinstance(event_usage := event.get("usage"), dict) and normalized_audio_duration_seconds(event_usage.get("output_seconds")) is not None ): self._translation_usage_finalized = True diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index dbde287b10a..cdca6ec3d4e 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -6874,7 +6874,7 @@ class BaseLLMHTTPHandler: configured_client: Final = openai_client.with_options( timeout=timeout, set_default_headers={ # mutable-ok: OpenAI SDK accepts a mutable custom-header mapping - key: str(value) # mutable-ok: SDK headers are materialized as a concrete string mapping + key: str(value) for key, value in (extra_headers or {}).items() # mutable-ok: SDK requires concrete headers }, ) diff --git a/litellm/llms/openai/transcriptions/gpt_transformation.py b/litellm/llms/openai/transcriptions/gpt_transformation.py index 81f3abd217a..c55ecf1e56c 100644 --- a/litellm/llms/openai/transcriptions/gpt_transformation.py +++ b/litellm/llms/openai/transcriptions/gpt_transformation.py @@ -40,9 +40,7 @@ class OpenAIGPTAudioTranscriptionConfig(OpenAIWhisperAudioTranscriptionConfig): class OpenAIGPTTranscribeAudioTranscriptionConfig(OpenAIGPTAudioTranscriptionConfig): - def get_supported_openai_params( # mutable-ok: base transcription interface returns a mutable parameter list - self, model: str - ) -> list[OpenAIAudioTranscriptionOptionalParams]: + def get_supported_openai_params(self, model: str) -> list[OpenAIAudioTranscriptionOptionalParams]: return [ "prompt", "response_format", diff --git a/litellm/llms/openai/transcriptions/handler.py b/litellm/llms/openai/transcriptions/handler.py index f2d46a50ddd..16b8e919fc5 100644 --- a/litellm/llms/openai/transcriptions/handler.py +++ b/litellm/llms/openai/transcriptions/handler.py @@ -56,9 +56,11 @@ class OpenAIAudioTranscription(OpenAIChatCompletion): try: sdk_data: Final = sdk_compatible_transcription_request_data(data) if data.get("stream") is True: - response = openai_client.audio.transcriptions.create(**sdk_data, timeout=timeout) - return None, response - raw_response: Final = openai_client.audio.transcriptions.with_raw_response.create(**sdk_data, timeout=timeout) + stream_response: Final = openai_client.audio.transcriptions.create(**sdk_data, timeout=timeout) + return None, stream_response + raw_response: Final = openai_client.audio.transcriptions.with_raw_response.create( + **sdk_data, timeout=timeout + ) headers: Final = dict(raw_response.headers) response: Final = raw_response.parse() return headers, response diff --git a/litellm/proxy/realtime_endpoints/endpoints.py b/litellm/proxy/realtime_endpoints/endpoints.py index 897f7a347f4..99d02fc7f4c 100644 --- a/litellm/proxy/realtime_endpoints/endpoints.py +++ b/litellm/proxy/realtime_endpoints/endpoints.py @@ -142,7 +142,7 @@ async def _authorize_and_bind_nested_transcription_models( session_data: dict, # mutable-ok: session payload is rewritten in place for provider serialization user_api_key_dict: UserAPIKeyAuth, llm_model_list: list | None, # mutable-ok: inherited auth helper accepts the proxy model list - llm_router: Any, + llm_router: "Router | None", ) -> None: nested_models: Final = tuple(_transcription_model_candidates_from_session(session_data)) for nested_model in nested_models: @@ -522,18 +522,14 @@ async def proxy_realtime_calls( session_type = _coerce_realtime_session_type(raw_session_type) if is_translation_request != (raw_session_type == "translation"): return Response( - content=json.dumps( # mutable-ok: JSON encoder requires the endpoint error payload mapping - {"error": "Token is not valid for this Realtime endpoint"} - ), + content=json.dumps({"error": "Token is not valid for this Realtime endpoint"}), status_code=http_status.HTTP_401_UNAUTHORIZED, media_type="application/json", ) else: if is_translation_request: return Response( - content=json.dumps( # mutable-ok: JSON encoder requires the endpoint error payload mapping - {"error": "Token is not valid for this Realtime endpoint"} - ), + content=json.dumps({"error": "Token is not valid for this Realtime endpoint"}), status_code=http_status.HTTP_401_UNAUTHORIZED, media_type="application/json", ) diff --git a/litellm/realtime_api/main.py b/litellm/realtime_api/main.py index 969d49b37dc..b9e0b655cc3 100644 --- a/litellm/realtime_api/main.py +++ b/litellm/realtime_api/main.py @@ -83,12 +83,14 @@ def _with_resolved_session_model(session: dict[str, object], model_name: str) -> audio = session.get("audio") audio = audio if isinstance(audio, dict) else {} # mutable-ok: nested session model is rebuilt locally audio_input = audio.get("input") - audio_input = ( # mutable-ok: nested session model is rebuilt locally - audio_input if isinstance(audio_input, dict) else {} + audio_input = ( + audio_input if isinstance(audio_input, dict) else {} # mutable-ok: nested session model is rebuilt locally ) transcription = audio_input.get("transcription") - transcription = ( # mutable-ok: nested session model is rebuilt locally - transcription if isinstance(transcription, dict) else {} + transcription = ( + transcription + if isinstance(transcription, dict) + else {} # mutable-ok: nested session model is rebuilt locally ) return { # mutable-ok: provider routing requires an independently mutable session payload **session,