{"record":{"id":"59aefb3363e5745c","repo":"BerriAI/litellm","slug":"api-key-is-required-for-azure-ai-speech-transcript","errorCode":null,"errorMessage":"api_key is required for Azure AI Speech transcription.","messagePattern":"api_key is required for Azure AI Speech transcription\\.","errorType":"validation","errorClass":"AzureSpeechAudioTranscriptionException","httpStatus":401,"severity":"error","filePath":"litellm/llms/azure/audio_transcription/transformation.py","lineNumber":72,"sourceCode":"        supported_params: Final = self.get_supported_openai_params(model=model)\n        for key, value in non_default_params.items():\n            if key in supported_params:\n                optional_params[key] = value\n        return optional_params\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        api_key = api_key or get_secret_str(\"AZURE_SPEECH_API_KEY\")\n        if not api_key:\n            raise AzureSpeechAudioTranscriptionException(\n                message=\"api_key is required for Azure AI Speech transcription.\",\n                status_code=401,\n            )\n\n        validated_headers: Final = headers.copy()\n        validated_headers[\"Ocp-Apim-Subscription-Key\"] = api_key\n        validated_headers[\"Content-Type\"] = validated_headers.get(\"Content-Type\", \"audio/wav\")\n        validated_headers[\"Accept\"] = \"application/json\"\n        return validated_headers\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        api_key: str | None,\n        model: str,\n        optional_params: dict,\n        litellm_params: dict,\n        stream: bool | None = None,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/audio_transcription/transformation.py#L54-L90","documentation":"LiteLLM's Azure AI Speech transcription handler requires an API key before it can build request headers. The key is passed as the `api_key` argument or read from the AZURE_SPEECH_API_KEY environment variable; if neither is set, this 401 error is raised before any network call happens. The key is sent as the `Ocp-Apim-Subscription-Key` header to the Azure Speech endpoint.","triggerScenarios":"Calling `litellm.transcription(model='azure/...', ...)` (or the /v1/audio/transcriptions proxy route with an Azure Speech model) without an `api_key` parameter while AZURE_SPEECH_API_KEY is unset in the process environment.","commonSituations":"Working locally with the key in a .env file that was never loaded; deploying behind a proxy where the key was configured under AZURE_API_KEY (Azure OpenAI) instead of AZURE_SPEECH_API_KEY; rotating secrets and the new variable name differing.","solutions":["Set AZURE_SPEECH_API_KEY in the environment: export AZURE_SPEECH_API_KEY=<your Cognitive Services key>.","Or pass the key explicitly: litellm.transcription(model=..., api_key=<key>, api_base=<endpoint>).","If using the LiteLLM proxy, add api_key to the model's deployment config in config.yaml.","Verify with a quick check that the variable is visible to the same process running LiteLLM (printenv AZURE_SPEECH_API_KEY)."],"exampleFix":"// before\nlitellm.transcription(model='azure/whisper', file=open('a.wav','rb'), api_base='https://eastus.stt.speech.microsoft.com')\n\n// after\nlitellm.transcription(model='azure/whisper', file=open('a.wav','rb'), api_base='https://eastus.stt.speech.microsoft.com', api_key=os.environ['AZURE_SPEECH_API_KEY'])","handlingStrategy":"validation","validationCode":"import os\n\nkey = os.environ.get('AZURE_SPEECH_API_KEY')\nif not key:\n    raise RuntimeError('Set AZURE_SPEECH_API_KEY or pass api_key before calling Azure Speech transcription.')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize Azure Speech credentials in one config loader that asserts AZURE_SPEECH_API_KEY is present at startup.","Don't confuse AZURE_API_KEY (Azure OpenAI) with AZURE_SPEECH_API_KEY — they are different variables."],"tags":["azure","speech","authentication","configuration","env-vars"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}