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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(azure): price azure_ai transcriptions at the azure_ai cost-map entry
mateo-berri831a2a13fbd8
diff --git a/litellm/llms/azure/audio_transcriptions.py b/litellm/llms/azure/audio_transcriptions.pyindex 4a5ed2ccb0c..564ec94ba6b 100644--- a/litellm/llms/azure/audio_transcriptions.py+++ b/litellm/llms/azure/audio_transcriptions.py@@ -37,6 +37,7 @@ class AzureAudioTranscription(AzureChatCompletion):azure_ad_token: str | None = None,atranscription: bool = False,litellm_params: dict | None = None,+ custom_llm_provider: str = "azure",) -> TranscriptionResponse | Coroutine[Any, Any, TranscriptionResponse]:data: Final = {"model": model, "file": audio_file, **optional_params}@@ -53,6 +54,7 @@ class AzureAudioTranscription(AzureChatCompletion):logging_obj=logging_obj,model=model,litellm_params=litellm_params,+ custom_llm_provider=custom_llm_provider,)azure_client: Final = self.get_azure_openai_client(@@ -99,7 +101,7 @@ class AzureAudioTranscription(AzureChatCompletion):additional_args={"complete_input_dict": data},original_response=stringified_response,)- hidden_params: Final = {"model": model, "custom_llm_provider": "azure"}+ hidden_params: Final = {"model": model, "custom_llm_provider": custom_llm_provider}final_response: Final[TranscriptionResponse] = convert_to_model_response_object(response_object=stringified_response,model_response_object=model_response,@@ -122,6 +124,7 @@ class AzureAudioTranscription(AzureChatCompletion):client=None,max_retries=None,litellm_params: dict | None = None,+ custom_llm_provider: str = "azure",) -> TranscriptionResponse:response = Nonetry:@@ -178,7 +181,7 @@ class AzureAudioTranscription(AzureChatCompletion):},original_response=stringified_response,)- hidden_params: Final = {"model": model, "custom_llm_provider": "azure"}+ hidden_params: Final = {"model": model, "custom_llm_provider": custom_llm_provider}response = convert_to_model_response_object(_response_headers=headers,response_object=stringified_response,diff --git a/litellm/main.py b/litellm/main.pyindex 75b7f7f10a5..11b30c240aa 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -7805,6 +7805,7 @@ def transcription(azure_ad_token=azure_ad_token,max_retries=max_retries,litellm_params=litellm_params_dict,+ custom_llm_provider=custom_llm_provider,)elif custom_llm_provider == "openai" or (custom_llm_provider in litellm.openai_compatible_providers):api_base = (diff --git a/tests/test_litellm/llms/azure/test_audio_transcriptions.py b/tests/test_litellm/llms/azure/test_audio_transcriptions.pynew file mode 100644index 00000000000..cd5fcbd85a9--- /dev/null+++ b/tests/test_litellm/llms/azure/test_audio_transcriptions.py@@ -0,0 +1,61 @@+import json+from pathlib import Path+from typing import Final++import httpx+import pytest+from openai import AzureOpenAI++import litellm+from litellm.cost_calculator import completion_cost+from litellm.litellm_core_utils.audio_utils.utils import calculate_request_duration++AUDIO_FILE: Final = Path(__file__).parents[3] / "gettysburg.wav"+WHISPER_COST_PER_SECOND: Final = 0.0001+++def _transcription_client() -> AzureOpenAI:+ def handler(request: httpx.Request) -> httpx.Response:+ return httpx.Response(200, json={"text": "Four score and seven years ago"})++ return AzureOpenAI(+ api_key="test-key",+ api_version="2024-06-01",+ azure_endpoint="https://example.cognitiveservices.azure.com",+ http_client=httpx.Client(transport=httpx.MockTransport(handler)),+ )+++def test_azure_ai_transcription_is_priced_at_the_azure_ai_entry():+ with AUDIO_FILE.open("rb") as audio:+ response = litellm.transcription(+ model="azure_ai/whisper",+ file=audio,+ api_base="https://example.cognitiveservices.azure.com",+ api_key="test-key",+ api_version="2024-06-01",+ client=_transcription_client(),+ )+ with AUDIO_FILE.open("rb") as audio:+ duration = calculate_request_duration(audio)++ assert duration is not None and duration > 0+ assert response._hidden_params["custom_llm_provider"] == "azure_ai"+ assert completion_cost(completion_response=response, call_type="transcription") == pytest.approx(+ WHISPER_COST_PER_SECOND * duration+ )+++def test_azure_transcription_keeps_the_azure_provider():+ with AUDIO_FILE.open("rb") as audio:+ response = litellm.transcription(+ model="azure/whisper-1",+ file=audio,+ api_base="https://example.openai.azure.com",+ api_key="test-key",+ api_version="2024-06-01",+ client=_transcription_client(),+ )++ assert response._hidden_params["custom_llm_provider"] == "azure"+ assert json.loads(response.model_dump_json())["text"] == "Four score and seven years ago"