From 39001f75cdb1a894216e4cfec422a44b2e97974f Mon Sep 17 00:00:00 2001 From: Kathan Gabani Date: Thu, 25 Jun 2026 11:45:10 -0700 Subject: [PATCH] fix(audio): log audio filename on async transcription errors --- litellm/llms/azure/audio_transcriptions.py | 2 +- litellm/llms/openai/transcriptions/handler.py | 2 +- .../azure/test_azure_exception_mapping.py | 33 +++++++++++++++++++ .../test_whisper_transformation.py | 29 ++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/litellm/llms/azure/audio_transcriptions.py b/litellm/llms/azure/audio_transcriptions.py index a39f86fd5b1..21112aaac97 100644 --- a/litellm/llms/azure/audio_transcriptions.py +++ b/litellm/llms/azure/audio_transcriptions.py @@ -191,7 +191,7 @@ class AzureAudioTranscription(AzureChatCompletion): except Exception as e: ## LOGGING logging_obj.post_call( - input=input, + input=get_audio_file_name(audio_file), api_key=api_key, original_response=str(e), ) diff --git a/litellm/llms/openai/transcriptions/handler.py b/litellm/llms/openai/transcriptions/handler.py index 76178051ca1..83fecb3b9f7 100644 --- a/litellm/llms/openai/transcriptions/handler.py +++ b/litellm/llms/openai/transcriptions/handler.py @@ -226,7 +226,7 @@ class OpenAIAudioTranscription(OpenAIChatCompletion): except Exception as e: ## LOGGING logging_obj.post_call( - input=input, + input=get_audio_file_name(audio_file), api_key=api_key, original_response=str(e), ) diff --git a/tests/test_litellm/llms/azure/test_azure_exception_mapping.py b/tests/test_litellm/llms/azure/test_azure_exception_mapping.py index b172c401e2f..68b28ff25d2 100644 --- a/tests/test_litellm/llms/azure/test_azure_exception_mapping.py +++ b/tests/test_litellm/llms/azure/test_azure_exception_mapping.py @@ -427,3 +427,36 @@ class TestAzureExceptionMapping: error = exc_info.value assert "encrypted_content_affinity" in error.message assert "enable_pre_call_checks" in error.message + + @pytest.mark.asyncio + async def test_async_audio_transcription_error_path_logs_audio_filename( + self, + ): + from litellm.litellm_core_utils.audio_utils.utils import get_audio_file_name + from litellm.llms.azure.audio_transcriptions import AzureAudioTranscription + from litellm.utils import TranscriptionResponse + + audio_file = ("test.wav", b"fake audio", "audio/wav") + expected_error = RuntimeError("azure upstream failure") + handler = AzureAudioTranscription() + handler.get_azure_openai_client = MagicMock(side_effect=expected_error) + logging_obj = MagicMock() + + with pytest.raises(RuntimeError) as exc_info: + await handler.async_audio_transcriptions( + audio_file=audio_file, + model="whisper-1", + data={"model": "whisper-1", "file": audio_file}, + model_response=TranscriptionResponse(), + timeout=1, + logging_obj=logging_obj, + api_key="test-api-key", + api_base="https://example.openai.azure.com", + litellm_params={}, + ) + + assert exc_info.value is expected_error + logging_obj.post_call.assert_called_once() + kwargs = logging_obj.post_call.call_args.kwargs + assert kwargs["input"] == get_audio_file_name(audio_file) + assert kwargs["original_response"] == str(expected_error) diff --git a/tests/test_litellm/llms/openai/transcriptions/test_whisper_transformation.py b/tests/test_litellm/llms/openai/transcriptions/test_whisper_transformation.py index 2dc24b1b313..e1d85bae87f 100644 --- a/tests/test_litellm/llms/openai/transcriptions/test_whisper_transformation.py +++ b/tests/test_litellm/llms/openai/transcriptions/test_whisper_transformation.py @@ -104,3 +104,32 @@ class TestWhisperTransformResponse: is_json=False, ) ) + + +@pytest.mark.asyncio +async def test_async_transcription_error_path_logs_audio_filename(): + from litellm.litellm_core_utils.audio_utils.utils import get_audio_file_name + from litellm.llms.openai.transcriptions.handler import OpenAIAudioTranscription + from litellm.utils import TranscriptionResponse + + audio_file = ("test.wav", b"fake audio", "audio/wav") + expected_error = RuntimeError("upstream failure") + handler = OpenAIAudioTranscription() + handler._get_openai_client = MagicMock(side_effect=expected_error) + logging_obj = MagicMock() + + with pytest.raises(RuntimeError) as exc_info: + await handler.async_audio_transcriptions( + audio_file=audio_file, + data={"model": "whisper-1", "file": audio_file}, + model_response=TranscriptionResponse(), + timeout=1, + logging_obj=logging_obj, + api_key="test-api-key", + ) + + assert exc_info.value is expected_error + logging_obj.post_call.assert_called_once() + kwargs = logging_obj.post_call.call_args.kwargs + assert kwargs["input"] == get_audio_file_name(audio_file) + assert kwargs["original_response"] == str(expected_error)