Merge pull request #41882 from BerriAI/litellm_azure_speech_api_base_prefix

fix(proxy): classify Azure Speech short audio behind a prefixed api base
This commit is contained in:
Yassin Kortam 2026-09-18 14:50:28 -07:00 committed by GitHub
commit 47209d37f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -8,6 +8,7 @@ import httpx
from litellm._logging import verbose_proxy_logger
from litellm.constants import (
AZURE_SPEECH_BATCH_MODEL,
AZURE_SPEECH_BATCH_PATH_PREFIX,
AZURE_SPEECH_CUSTOM_LLM_PROVIDER,
AZURE_SPEECH_FAST_TRANSCRIPTION_MODEL,
AZURE_SPEECH_FAST_TRANSCRIPTION_PATH,
@ -30,7 +31,8 @@ from litellm.types.utils import StandardPassThroughResponseObject
class AzureSpeechPassthroughLoggingHandler:
@staticmethod
def _is_short_audio_route(url_route: str) -> bool:
return urlparse(url_route).path.startswith(AZURE_SPEECH_SHORT_AUDIO_PATH_PREFIX)
path: Final = urlparse(url_route).path
return path.rfind(AZURE_SPEECH_SHORT_AUDIO_PATH_PREFIX) > path.rfind(AZURE_SPEECH_BATCH_PATH_PREFIX)
@staticmethod
def _is_fast_transcription_route(url_route: str) -> bool:

View file

@ -21,6 +21,11 @@ SHORT_AUDIO_URL = (
)
BATCH_URL = "https://eastus.api.cognitive.microsoft.com/speechtotext/v3.2/transcriptions"
FAST_URL = "https://eastus.api.cognitive.microsoft.com/speechtotext/transcriptions:transcribe?api-version=2024-11-15"
PREFIXED_SHORT_AUDIO_URL = (
"https://apim.example.com/speech-proxy/speech/recognition/conversation/cognitiveservices/v1?language=en-US"
)
PREFIXED_BATCH_URL = "https://apim.example.com/speech/speechtotext/v3.2/transcriptions"
PREFIXED_FAST_URL = "https://apim.example.com/speech/speechtotext/transcriptions:transcribe?api-version=2024-11-15"
FAST_BODY = {"durationMilliseconds": 5061, "combinedPhrases": [{"text": "Hello world."}]}
FAST_AUDIO_SECONDS = 5.061
TRANSCRIPT_BODY = {
@ -87,6 +92,9 @@ class TestAzureSpeechPassthroughHandler:
(FAST_URL, "azure_speech/fast-transcription", FAST_AUDIO_SECONDS * PRICE_PER_SECOND),
(BATCH_URL, "azure_speech/batch-transcription", 0.0),
(f"{BATCH_URL}/8a5d3f2c-0b1e-4c7d-9e6f-1234567890ab/files", "azure_speech/batch-transcription", 0.0),
(PREFIXED_SHORT_AUDIO_URL, "azure_speech/short-audio", TRANSCRIPT_AUDIO_SECONDS * PRICE_PER_SECOND),
(PREFIXED_FAST_URL, "azure_speech/fast-transcription", FAST_AUDIO_SECONDS * PRICE_PER_SECOND),
(PREFIXED_BATCH_URL, "azure_speech/batch-transcription", 0.0),
],
)
def test_records_model_provider_and_cost(self, url_route: str, expected_model: str, expected_cost: float):