{"record":{"id":"3e21ecef9fd4a660","repo":"BerriAI/litellm","slug":"api-base-is-required-for-azure-openai-calls","errorCode":null,"errorMessage":"api_base is required for Azure OpenAI calls","messagePattern":"api_base is required for Azure OpenAI calls","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure/realtime/handler.py","lineNumber":107,"sourceCode":"        model: str,\n        websocket: Any,\n        logging_obj: LiteLLMLogging,\n        api_base: str | None = None,\n        api_key: str | None = None,\n        api_version: str | None = None,\n        azure_ad_token: str | None = None,\n        client: Any | None = None,\n        timeout: float | None = None,\n        realtime_protocol: str | None = None,\n        query_params: RealtimeQueryParams | None = None,\n        user_api_key_dict: Any | None = None,\n        litellm_metadata: dict | None = None,\n    ):\n        import websockets\n        from websockets.asyncio.client import ClientConnection\n\n        if api_base is None:\n            raise ValueError(\"api_base is required for Azure OpenAI calls\")\n        backend_uses_beta_protocol: Final = realtime_protocol is None or realtime_protocol.upper() not in (\"GA\", \"V1\")\n        if api_version is None and backend_uses_beta_protocol:\n            raise ValueError(\"api_version is required for Azure OpenAI calls\")\n\n        url: Final = self._construct_url(\n            api_base,\n            model,\n            api_version,\n            realtime_protocol=realtime_protocol,\n            query_params=query_params,\n        )\n\n        try:\n            ssl_context: Final = get_shared_realtime_ssl_context()\n            async with websockets.connect(\n                url,\n                additional_headers={\n                    \"api-key\": api_key,","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/realtime/handler.py#L89-L125","documentation":"The Azure Realtime API handler opens a WebSocket to Azure OpenAI, which requires the resource endpoint URL; unlike chat calls there is no default base to fall back on. If api_base is None this ValueError is raised before websockets.connect is attempted. Azure realtime endpoints look like wss://<resource>.openai.azure.com/openai/realtime?... and cannot be guessed from the model name.","triggerScenarios":"Calling the Azure realtime handler with model='azure/<deployment>' but no api_base argument and no resolved litellm_params api_base; audio streaming setups that configure only the key and deployment.","commonSituations":"Voice-agent integrations that copy OpenAI realtime examples (wss://api.openai.com) and swap only the model prefix; missing AZURE_API_BASE in containerized audio services; configs where api_base was added to the wrong model entry.","solutions":["Pass api_base='https://<resource>.openai.azure.com' (the handler converts the scheme for WebSocket use).","Set api_base in the model's litellm_params so it flows through to the realtime handler.","Also ensure api_version is set when not using the GA/V1 realtime protocol (see the companion api_version check).","Verify the deployment has realtime enabled on the Azure resource."],"exampleFix":"# before\nawait azure_realtime.connect(model='azure/my-voice-deployment', api_key=key)  # raises\n\n# after\nawait azure_realtime.connect(\n    model='azure/my-voice-deployment',\n    api_key=key,\n    api_base='https://myresource.openai.azure.com',\n    api_version='2024-10-01-preview',\n)","handlingStrategy":"validation","validationCode":"def validate_realtime_config(api_base: str | None, api_version: str | None, realtime_protocol: str | None) -> None:\n    if not api_base:\n        raise ValueError('Azure realtime requires api_base (https://<resource>.openai.azure.com)')\n    beta = realtime_protocol is None or realtime_protocol.upper() not in ('GA', 'V1')\n    if beta and not api_version:\n        raise ValueError('Azure realtime beta protocol requires api_version')","typeGuard":null,"tryCatchPattern":"try:\n    async with azure_realtime_session(...) as s:\n        ...\nexcept ValueError as e:\n    if 'api_base is required' in str(e):\n        raise ValueError('configure the Azure resource endpoint for realtime') from e\n    raise","preventionTips":["Store realtime connection params (api_base, api_version, deployment) together in one config object.","Smoke-test the WebSocket URL construction at service startup."],"tags":["azure","openai","realtime","websocket","api-base","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}