{"record":{"id":"4689dc0cba5e5e42","repo":"BerriAI/litellm","slug":"api-base-is-required-for-azure-openai-llm-provider","errorCode":null,"errorMessage":"api_base is required for Azure OpenAI LLM provider. Either set it dynamically or set the AZURE_API_BASE environment variable.","messagePattern":"api_base is required for Azure OpenAI LLM provider\\. Either set it dynamically or set the AZURE_API_BASE environment variable\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/main.py","lineNumber":1393,"sourceCode":"    api_version = ctx.api_version\n    client: Final = _dispatch_client_azure(ctx)\n    extra_headers: Final = ctx.extra_headers\n    headers = ctx.headers\n    litellm_params: Final = ctx.litellm_params\n    logger_fn: Final = ctx.logger_fn\n    logging: Final = ctx.logging\n    messages: Final = ctx.messages\n    model: Final = ctx.model\n    model_response: Final = ctx.model_response\n    optional_params: Final = ctx.optional_params\n    timeout: Final = ctx.timeout\n\n    api_type: Final = get_secret_str(\"AZURE_API_TYPE\") or \"azure\"\n\n    api_base = api_base or litellm.api_base or get_secret_str(\"AZURE_API_BASE\")\n\n    if api_base is None:\n        raise ValueError(\n            \"api_base is required for Azure OpenAI LLM provider. Either set it dynamically or set the AZURE_API_BASE environment variable.\"\n        )\n\n    api_version = api_version or litellm.api_version or get_secret_str(\"AZURE_API_VERSION\")\n\n    api_key = (\n        api_key\n        or litellm.api_key\n        or litellm.azure_key\n        or get_secret_str(\"AZURE_OPENAI_API_KEY\")\n        or get_secret_str(\"AZURE_API_KEY\")\n    )\n\n    azure_ad_token: Final = optional_params.get(\"extra_body\", {}).pop(\"azure_ad_token\", None) or get_secret_str(\n        \"AZURE_AD_TOKEN\"\n    )\n\n    azure_ad_token_provider_value: Final = litellm_params.get(\"azure_ad_token_provider\", None)","sourceCodeStart":1375,"sourceCodeEnd":1411,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/main.py#L1375-L1411","documentation":"ValueError raised on the Azure OpenAI chat path when no api_base resolves from the chain: api_base argument > litellm.api_base > AZURE_API_BASE environment variable. Azure requires the per-resource endpoint URL (https://<resource>.openai.azure.com/) to build the request, so an empty value aborts before any HTTP call.","triggerScenarios":"completion(model='azure/<deployment>') (or azure/ provider routing) with none of: api_base kwarg, litellm.api_base set, AZURE_API_BASE exported.","commonSituations":"Local script works (env set in shell) but CI/container/lambda lacks AZURE_API_BASE; key rotation scripts set only AZURE_API_KEY and forget the base; deploying with azure-ad token auth but no endpoint URL configured.","solutions":["Export AZURE_API_BASE=https://<your-resource>.openai.azure.com/","Or pass api_base='https://<resource>.openai.azure.com/' per call / in the Router model_list entry","Confirm with a quick check: litellm.get_secret_str('AZURE_API_BASE') returns the URL in the failing environment","If using azure-ad auth, still set api_base -- the endpoint URL is required regardless of auth mode"],"exampleFix":"# before\nresp = litellm.completion(model='azure/my-deploy', messages=m)  # ValueError\n\n# after\nimport os\nos.environ['AZURE_API_BASE'] = 'https://my-resource.openai.azure.com/'\nos.environ['AZURE_API_KEY'] = '...'\nresp = litellm.completion(model='azure/my-deploy', messages=m)","handlingStrategy":"validation","validationCode":"import os\napi_base = os.getenv('AZURE_API_BASE') or litellm.api_base\nif not api_base:\n    raise SystemExit('AZURE_API_BASE not set; refusing to call azure models')","typeGuard":"def azure_base_resolved(api_base: str | None) -> bool:\n    return isinstance(api_base, str) and api_base.startswith('https://')","tryCatchPattern":"try:\n    resp = litellm.completion(model='azure/my-deploy', messages=m)\nexcept ValueError as e:\n    if 'api_base is required for Azure' in str(e):\n        raise RuntimeError('Azure endpoint unconfigured: set AZURE_API_BASE') from e\n    raise","preventionTips":["Put AZURE_API_BASE and AZURE_API_KEY in the same bootstrap as other required env vars and assert them at startup","For multiple Azure resources, always pass api_base per call or use Router model_list entries instead of the global","Document that Azure needs the full endpoint URL including https:// and the resource name","Add env-var presence checks to CI smoke tests for every provider you call"],"tags":["azure","azure-openai","api-base","env-var","litellm"],"backgroundTag":"missing-api-base","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}