From 2e5d70570ea8c003fc0d650cf17f13aed4186996 Mon Sep 17 00:00:00 2001 From: oss-agent-shin <279349115+oss-agent-shin@users.noreply.github.com> Date: Sat, 9 May 2026 00:02:17 +0000 Subject: [PATCH] fix(azure): address speech transcription review Co-authored-by: ishaan-berri --- ...odel_prices_and_context_window_backup.json | 1 + litellm/utils.py | 38 ++++++++++++++++++- model_prices_and_context_window.json | 1 + .../test_azure_speech_audio_transcription.py | 4 ++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 461d26b63bb..716a3ef4a7b 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -5652,6 +5652,7 @@ "source": "https://azure.microsoft.com/en-us/pricing/calculator/" }, "azure/speech/azure-stt": { + "audio_transcription_config": "azure_speech", "input_cost_per_second": 0.0002777778, "litellm_provider": "azure", "mode": "audio_transcription", diff --git a/litellm/utils.py b/litellm/utils.py index bf1a9c1e508..9eff321259e 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -8060,6 +8060,35 @@ def validate_openai_optional_params( return stop +@lru_cache(maxsize=1) +def _get_bundled_model_cost_map() -> Dict[str, Any]: + try: + model_cost_path = resources.files("litellm").joinpath( + "model_prices_and_context_window_backup.json" + ) + return json.loads(model_cost_path.read_text()) + except Exception: + return {} + + +def _get_model_cost_entry_for_provider_config( + model: str, + provider: LlmProviders, +) -> Dict[str, Any]: + candidate_keys = (model, f"{provider.value}/{model}") + for model_key in candidate_keys: + model_info = litellm.model_cost.get(model_key) + if model_info is not None: + return model_info + + bundled_model_cost = _get_bundled_model_cost_map() + for model_key in candidate_keys: + model_info = bundled_model_cost.get(model_key) + if model_info is not None: + return model_info + return {} + + class ProviderConfigManager: # Dictionary mapping for O(1) provider lookup # Stores tuples of (factory_function, needs_model_parameter) @@ -8500,7 +8529,14 @@ class ProviderConfigManager: model: str, provider: LlmProviders, ) -> Optional[BaseAudioTranscriptionConfig]: - if litellm.LlmProviders.AZURE == provider and model.startswith("speech/"): + model_cost_entry = _get_model_cost_entry_for_provider_config( + model=model, + provider=provider, + ) + if ( + litellm.LlmProviders.AZURE == provider + and model_cost_entry.get("audio_transcription_config") == "azure_speech" + ): from litellm.llms.azure.audio_transcription.transformation import ( AzureSpeechAudioTranscriptionConfig, ) diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 215b55d4e2d..0a351fcd45f 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -5652,6 +5652,7 @@ "source": "https://azure.microsoft.com/en-us/pricing/calculator/" }, "azure/speech/azure-stt": { + "audio_transcription_config": "azure_speech", "input_cost_per_second": 0.0002777778, "litellm_provider": "azure", "mode": "audio_transcription", 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 7192835c678..e42b304c7b7 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 @@ -215,3 +215,7 @@ def test_azure_speech_stt_has_non_zero_input_pricing(): pricing = json.loads(pricing_path.read_text()) assert pricing["azure/speech/azure-stt"]["input_cost_per_second"] > 0 + assert ( + pricing["azure/speech/azure-stt"]["audio_transcription_config"] + == "azure_speech" + )