{"record":{"id":"50e838402adc3a22","repo":"BerriAI/litellm","slug":"api-base-is-required-for-azure-ai-studio-please-s-50e838","errorCode":null,"errorMessage":"api_base is required for Azure AI Studio. Please set the api_base parameter. Passed `api_base={api_base}`","messagePattern":"api_base is required for Azure AI Studio\\. Please set the api_base parameter\\. Passed `api_base=(.+?)`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/chat/transformation.py","lineNumber":120,"sourceCode":"    ) -> str:\n        \"\"\"\n        Constructs a complete URL for the API request.\n\n        Args:\n        - api_base: Base URL, e.g.,\n            \"https://litellm8397336933.services.ai.azure.com\"\n            OR\n            \"https://litellm8397336933.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview\"\n        - model: Model name.\n        - optional_params: Additional query parameters, including \"api_version\".\n        - stream: If streaming is required (optional).\n\n        Returns:\n        - A complete URL string, e.g.,\n        \"https://litellm8397336933.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview\"\n        \"\"\"\n        if api_base is None:\n            raise ValueError(\n                f\"api_base is required for Azure AI Studio. Please set the api_base parameter. Passed `api_base={api_base}`\"\n            )\n        original_url: Final = httpx.URL(api_base)\n\n        # Extract api_version or use default\n        api_version: Final = cast(str | None, litellm_params.get(\"api_version\"))\n\n        # Create a new dictionary with existing params\n        query_params: Final = dict(original_url.params)\n\n        # Add api_version if needed\n        if \"api-version\" not in query_params and api_version:\n            query_params[\"api-version\"] = api_version\n\n        # Add the path to the base URL\n        if \"services.ai.azure.com\" in api_base:\n            new_url = _add_path_to_api_base(api_base=api_base, ending_path=\"/models/chat/completions\")\n        else:","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/chat/transformation.py#L102-L138","documentation":"The Azure AI Studio (Foundry) chat transformation requires a base URL to build https://<resource>.services.ai.azure.com/models/chat/completions?api-version=.... If api_base is None it raises ValueError, echoing the (None) value you passed. Foundry has no inferable default endpoint, so this is thrown client-side before any request.","triggerScenarios":"completion(model='azure_ai/<model>', ...) without api_base and without AZURE_AI_API_BASE env var; supplying only deployment name and api_key (the pattern for plain Azure OpenAI, which resolves via AZURE_API_BASE); passing api_base=None explicitly.","commonSituations":"Copy-pasted Azure OpenAI config used against an azure_ai model; env var set after process start; proxy deployment entry missing api_base; confusion between the azure/ and azure_ai/ provider prefixes.","solutions":["Pass api_base: https://<resource>.services.ai.azure.com (optionally with /models/chat/completions?api-version=... which litellm normalizes).","Or set AZURE_AI_API_BASE in the process environment.","If you actually have an Azure OpenAI resource (not Foundry), switch the model prefix from azure_ai/ to azure/ and use AZURE_API_BASE.","In proxy config, add api_base under the deployment's litellm_params."],"exampleFix":"# before\nlitellm.completion(model='azure_ai/gpt-4o', api_key=k, messages=m)\n\n# after\nlitellm.completion(\n    model='azure_ai/gpt-4o', api_key=k, messages=m,\n    api_base='https://litellm8397336933.services.ai.azure.com',\n)","handlingStrategy":"validation","validationCode":"import os\n\ndef foundry_chat_base(api_base: str | None) -> str:\n    base = api_base or os.getenv('AZURE_AI_API_BASE')\n    if base is None:\n        raise RuntimeError('azure_ai chat requires api_base or AZURE_AI_API_BASE')\n    return base","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model='azure_ai/gpt-4o', api_base=foundry_chat_base(None), ...)\nexcept ValueError as e:\n    if 'api_base is required for Azure AI Studio' in str(e):\n        raise ConfigurationError(str(e)) from e\n    raise","preventionTips":["Choose the prefix deliberately: azure/ uses AZURE_API_BASE, azure_ai/ needs AZURE_AI_API_BASE.","Validate provider env vars at process start with a single settings loader.","In proxy configs, always set api_base on foundry deployments — never depend on ambient env."],"tags":["azure","foundry","configuration","api-base","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}