BerriAI/litellm · error · AzureSpeechAudioTranscriptionException

api_base is required for Azure AI Speech transcription. Use

Error message

api_base is required for Azure AI Speech transcription. Use a Cognitive Services endpoint like https://{region}.api.cognitive.microsoft.com or an STT endpoint like https://{region}.stt.speech.microsoft.com.

What it means

Azure AI Speech transcription in LiteLLM needs a Cognitive Services or STT Speech endpoint to build the full request URL. It is taken from the `api_base` argument or the AZURE_SPEECH_API_BASE environment variable. When absent, this 400 error is raised with guidance on the two accepted endpoint shapes.

Source

Thrown at litellm/llms/azure/audio_transcription/transformation.py:94

        validated_headers: Final = headers.copy()
        validated_headers["Ocp-Apim-Subscription-Key"] = api_key
        validated_headers["Content-Type"] = validated_headers.get("Content-Type", "audio/wav")
        validated_headers["Accept"] = "application/json"
        return validated_headers

    def get_complete_url(
        self,
        api_base: str | None,
        api_key: str | None,
        model: str,
        optional_params: dict,
        litellm_params: dict,
        stream: bool | None = None,
    ) -> str:
        api_base = api_base or get_secret_str("AZURE_SPEECH_API_BASE")
        if api_base is None:
            raise AzureSpeechAudioTranscriptionException(
                message=(
                    "api_base is required for Azure AI Speech transcription. "
                    "Use a Cognitive Services endpoint like "
                    "https://{region}.api.cognitive.microsoft.com or an STT "
                    "endpoint like https://{region}.stt.speech.microsoft.com."
                ),
                status_code=400,
            )

        base_url: Final = self._resolve_stt_base_url(api_base=api_base)
        query_params: Final = {
            "language": optional_params.get("language", self.DEFAULT_LANGUAGE),
            "format": self._get_azure_response_format(optional_params.get("response_format")),
        }
        return f"{base_url}{self.STT_ENDPOINT_PATH}?{urlencode(query_params)}"

    def transform_audio_transcription_request(
        self,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass api_base explicitly, e.g. 'https://eastus.api.cognitive.microsoft.com' or 'https://eastus.stt.speech.microsoft.com'.
  2. Or export AZURE_SPEECH_API_BASE=<endpoint> in the environment.
  3. Use the region matching your Speech resource; find it on the resource's Overview page in the Azure portal.
  4. In the LiteLLM proxy, set api_base on the model's deployment entry.

Example fix

# before
response = litellm.transcription(model='azure/speech', file=f, api_key=key)

# after
response = litellm.transcription(
    model='azure/speech', file=f, api_key=key,
    api_base='https://eastus.stt.speech.microsoft.com',
)
Defensive patterns

Strategy: validation

Validate before calling

import os
from urllib.parse import urlparse

base = os.environ.get('AZURE_SPEECH_API_BASE')
if not base:
    raise RuntimeError('Set AZURE_SPEECH_API_BASE (e.g. https://<region>.stt.speech.microsoft.com).')
host = urlparse(base).hostname or ''
assert host.endswith('api.cognitive.microsoft.com') or host.endswith('stt.speech.microsoft.com'), f'Unexpected Speech endpoint: {host}'

Prevention

When it happens

Trigger: Calling transcription with an Azure Speech model but no `api_base` argument and no AZURE_SPEECH_API_BASE env var; or setting AZURE_API_BASE (Azure OpenAI variable) instead of AZURE_SPEECH_API_BASE.

Common situations: Teams already using Azure OpenAI assume the same env vars cover Speech; the endpoint was configured only in a different service's config; hostname typos in region name cause devs to remove api_base entirely while debugging.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/6c946c805d8961af. Report an issue: GitHub.