Skip to content

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]

fix(perf): add missing shared_sessions to audio/transcriptions (#16858)

Alexsander Hamir7a844696057e
diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py
index 30c07ebe7f0..6b0aef31ff6 100644
--- a/litellm/llms/custom_httpx/llm_http_handler.py
+++ b/litellm/llms/custom_httpx/llm_http_handler.py
@@ -1140,6 +1140,7 @@ class BaseLLMHTTPHandler:
atranscription: bool = False,
headers: Optional[Dict[str, Any]] = None,
provider_config: Optional[BaseAudioTranscriptionConfig] = None,
+ shared_session: Optional["ClientSession"] = None,
) -> Union[TranscriptionResponse, Coroutine[Any, Any, TranscriptionResponse]]:
if provider_config is None:
raise ValueError(
@@ -1162,6 +1163,7 @@ class BaseLLMHTTPHandler:
client=client,
headers=headers,
provider_config=provider_config,
+ shared_session=shared_session,
)
# Prepare the request
@@ -1226,6 +1228,7 @@ class BaseLLMHTTPHandler:
client: Optional[Union[HTTPHandler, AsyncHTTPHandler]] = None,
headers: Optional[Dict[str, Any]] = None,
provider_config: Optional[BaseAudioTranscriptionConfig] = None,
+ shared_session: Optional["ClientSession"] = None,
) -> TranscriptionResponse:
if provider_config is None:
raise ValueError(
@@ -1254,6 +1257,7 @@ class BaseLLMHTTPHandler:
async_httpx_client = get_async_httpx_client(
llm_provider=litellm.LlmProviders(custom_llm_provider),
params={"ssl_verify": litellm_params.get("ssl_verify", None)},
+ shared_session=shared_session,
)
else:
async_httpx_client = client
diff --git a/litellm/llms/openai/transcriptions/handler.py b/litellm/llms/openai/transcriptions/handler.py
index 4d60b8a8310..e241d2c1c7d 100644
--- a/litellm/llms/openai/transcriptions/handler.py
+++ b/litellm/llms/openai/transcriptions/handler.py
@@ -1,10 +1,13 @@
-from typing import Optional, Union, cast
+from typing import TYPE_CHECKING, Optional, Union, cast
import httpx
from openai import AsyncOpenAI, OpenAI
from pydantic import BaseModel
import litellm
+
+if TYPE_CHECKING:
+ from aiohttp import ClientSession
from litellm.litellm_core_utils.audio_utils.utils import get_audio_file_name
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
from litellm.llms.base_llm.audio_transcription.transformation import (
@@ -89,6 +92,7 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
client=None,
atranscription: bool = False,
provider_config: Optional[BaseAudioTranscriptionConfig] = None,
+ shared_session: Optional["ClientSession"] = None,
) -> TranscriptionResponse:
"""
Handle audio transcription request
@@ -116,6 +120,7 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
client=client,
max_retries=max_retries,
logging_obj=logging_obj,
+ shared_session=shared_session,
)
openai_client: OpenAI = self._get_openai_client( # type: ignore
@@ -170,6 +175,7 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
api_base: Optional[str] = None,
client=None,
max_retries=None,
+ shared_session: Optional["ClientSession"] = None,
):
try:
openai_aclient: AsyncOpenAI = self._get_openai_client( # type: ignore
@@ -179,6 +185,7 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
timeout=timeout,
max_retries=max_retries,
client=client,
+ shared_session=shared_session,
)
## LOGGING
diff --git a/litellm/main.py b/litellm/main.py
index 88c3f7bc55b..1e3826b9a60 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -5516,6 +5516,7 @@ def transcription(
atranscription = kwargs.pop("atranscription", False)
litellm_logging_obj: LiteLLMLoggingObj = kwargs.get("litellm_logging_obj") # type: ignore
extra_headers = kwargs.get("extra_headers", None)
+ shared_session = kwargs.get("shared_session", None)
kwargs.pop("tags", [])
non_default_params = get_non_default_transcription_params(kwargs)
@@ -5653,6 +5654,7 @@ def transcription(
api_key=api_key,
provider_config=provider_config,
litellm_params=litellm_params_dict,
+ shared_session=shared_session,
)
elif provider_config is not None:
response = base_llm_http_handler.audio_transcriptions(
@@ -5679,6 +5681,7 @@ def transcription(
custom_llm_provider=custom_llm_provider,
headers={},
provider_config=provider_config,
+ shared_session=shared_session,
)
# Calculate and add duration if response is missing it