From b0c1119d661bb71be73fa5f5b62eb4250200e5f3 Mon Sep 17 00:00:00 2001 From: KaiyiQuan Date: Fri, 9 Oct 2026 01:43:20 +0800 Subject: [PATCH] fix(proxy): lazy-import soundfile in transcribe pass-through handler Since v1.103.0, `import soundfile` at the top of transcribe_passthrough_logging_handler.py breaks every `/v1/messages` streaming request for the Anthropic and Bedrock providers unless the `proxy` or `stt-nvidia-riva` extra is installed: success_handler imports this module at module top, and streaming_iterator imports success_handler. `soundfile` is only used by `media_file_seconds()` to measure media duration. Move the import into `media_file_seconds()` and skip the duration measurement with a warning when soundfile is unavailable, so the default streaming path no longer requires it. Fixes #45379 --- .../transcribe_passthrough_logging_handler.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py index 79f6dee90f7..18a506ff268 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py @@ -13,7 +13,6 @@ from typing import IO, Final, Protocol, TypeAlias from urllib.parse import quote import httpx -import soundfile from pydantic import ConfigDict, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict @@ -511,6 +510,17 @@ async def write_media_within_limit(response: httpx.Response, media_file: IO[byte def media_file_seconds(path: Path) -> float | None: + try: + # soundfile is only needed to measure media duration and is declared in + # extras that are not installed on the default `/v1/messages` streaming + # path; import lazily so module import never fails without it. + import soundfile + except ModuleNotFoundError: + verbose_proxy_logger.warning( + "soundfile not installed; Transcribe media duration measurement is skipped (install the 'proxy' or 'stt-nvidia-riva' extra to enable it)" + ) + return None + try: with soundfile.SoundFile(str(path)) as audio: return len(audio) / audio.samplerate