{"record":{"id":"2065fdc0d2a9671e","repo":"BerriAI/litellm","slug":"api-base-is-required-for-azure-ai-agents-set-it-v","errorCode":null,"errorMessage":"api_base is required for Azure AI Agents. Set it via AZURE_AI_API_BASE env var or api_base parameter.","messagePattern":"api_base is required for Azure AI Agents\\. Set it via AZURE_AI_API_BASE env var or api_base parameter\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/agents/transformation.py","lineNumber":163,"sourceCode":"        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,\n    ) -> str:\n        \"\"\"\n        Get the base URL for Azure AI Agent Service.\n\n        The actual endpoint will vary based on the operation:\n        - /openai/threads for creating threads\n        - /openai/threads/{thread_id}/messages for adding messages\n        - /openai/threads/{thread_id}/runs for creating runs\n\n        This returns the base URL that will be modified for each operation.\n        \"\"\"\n        if api_base is None:\n            raise ValueError(\n                \"api_base is required for Azure AI Agents. Set it via AZURE_AI_API_BASE env var or api_base parameter.\"\n            )\n\n        # Remove trailing slash if present\n        api_base = api_base.rstrip(\"/\")\n\n        # Return base URL - actual endpoints will be constructed during request\n        return api_base\n\n    def _get_agent_id(self, model: str, optional_params: dict) -> str:\n        \"\"\"\n        Get the agent ID from model or optional_params.\n\n        model format: \"azure_ai/agents/<agent_id>\" or \"agents/<agent_id>\" or just \"<agent_id>\"\n        \"\"\"\n        agent_id: Final = optional_params.get(\"agent_id\") or optional_params.get(\"assistant_id\")\n        if agent_id:\n            return agent_id","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/agents/transformation.py#L145-L181","documentation":"The Azure AI Agents transformation builds operation URLs (threads, messages, runs) from a base URL. If api_base resolves to None — neither passed as a parameter nor via AZURE_AI_API_BASE — it raises this ValueError before any request is made. Azure AI Foundry has no default regional endpoint LiteLLM can infer, so the base URL is mandatory.","triggerScenarios":"Calling completion on an azure_ai_agents model without api_base and without the AZURE_AI_API_BASE env var; setting it under a different name (AZURE_API_BASE is a different provider's variable); passing None explicitly via litellm_params.","commonSituations":"Config written for Azure OpenAI (AZURE_API_BASE) reused for Foundry agents; env var defined in .env locally but not in the deployed container; typo in the variable name in docker-compose or CI secrets.","solutions":["Pass api_base explicitly: litellm.completion(model='azure_ai_agents/<agent>', api_base='https://<resource>.services.ai.azure.com/api/projects/<proj>', api_key=..., messages=...).","Or export AZURE_AI_API_BASE in the runtime environment of the process calling litellm.","Verify the value with a curl to {api_base}/openai/threads to prove the base URL is reachable before blaming litellm.","In proxy config, set api_base on the deployment's litellm_params, not at top level."],"exampleFix":"# before\nos.environ['AZURE_API_BASE'] = 'https://x.services.ai.azure.com'  # wrong var\nlitellm.completion(model='azure_ai_agents/agent1', messages=m, api_key=k)\n\n# after\nlitellm.completion(\n    model='azure_ai_agents/agent1', messages=m, api_key=k,\n    api_base='https://x.services.ai.azure.com/api/projects/proj1',\n)","handlingStrategy":"validation","validationCode":"import os\n\ndef agents_api_base() -> str:\n    base = os.getenv('AZURE_AI_API_BASE')\n    if not base:\n        raise RuntimeError('AZURE_AI_API_BASE must be set for azure_ai_agents calls')\n    return base","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model='azure_ai_agents/agent', api_base=agents_api_base(), ...)\nexcept ValueError as e:\n    if 'AZURE_AI_API_BASE' in str(e):\n        raise ConfigurationError(str(e)) from e\n    raise","preventionTips":["Fail fast on missing AZURE_AI_API_BASE during app bootstrap.","Note that AZURE_API_BASE (OpenAI) and AZURE_AI_API_BASE (Foundry) are different variables.","Store per-provider env requirements in a checklist used by your deployment pipeline."],"tags":["azure","agents","configuration","api-base","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}