diff --git a/litellm/llms/azure/audio_transcription/transformation.py b/litellm/llms/azure/audio_transcription/transformation.py index cda4f238263..e478c8ebf35 100644 --- a/litellm/llms/azure/audio_transcription/transformation.py +++ b/litellm/llms/azure/audio_transcription/transformation.py @@ -133,6 +133,17 @@ class AzureSpeechAudioTranscriptionConfig(BaseAudioTranscriptionConfig): raw_response: httpx.Response, ) -> TranscriptionResponse: response_json = raw_response.json() + recognition_status = response_json.get("RecognitionStatus") + if recognition_status is not None and recognition_status != "Success": + raise AzureSpeechAudioTranscriptionException( + message=( + "Azure AI Speech transcription failed with " + f"RecognitionStatus={recognition_status}." + ), + status_code=raw_response.status_code, + headers=raw_response.headers, + ) + text = self._extract_text(response_json) response = TranscriptionResponse(text=text) response._hidden_params = response_json diff --git a/tests/test_litellm/llms/azure/test_azure_speech_audio_transcription.py b/tests/test_litellm/llms/azure/test_azure_speech_audio_transcription.py index e42b304c7b7..6ed6be6f34f 100644 --- a/tests/test_litellm/llms/azure/test_azure_speech_audio_transcription.py +++ b/tests/test_litellm/llms/azure/test_azure_speech_audio_transcription.py @@ -183,6 +183,24 @@ def test_azure_speech_audio_transcription_response_transform(payload, expected_t assert result._hidden_params == payload +def test_azure_speech_audio_transcription_response_raises_on_failed_status(): + config = AzureSpeechAudioTranscriptionConfig() + response = httpx.Response( + 200, + json={ + "RecognitionStatus": "NoMatch", + "Offset": 0, + "Duration": 0, + }, + ) + + with pytest.raises( + AzureSpeechAudioTranscriptionException, + match="RecognitionStatus=NoMatch", + ): + config.transform_audio_transcription_response(response) + + def test_azure_speech_transcription_routes_through_provider_config(monkeypatch): expected = TranscriptionResponse(text="hello") audio_handler = MagicMock(return_value=expected)