{"record":{"id":"8459c79d173e7fb7","repo":"BerriAI/litellm","slug":"missing-azure-ai-api-base-set-azure-ai-api-base","errorCode":null,"errorMessage":"Missing Azure AI API Base - Set AZURE_AI_API_BASE environment variable or pass api_base parameter","messagePattern":"Missing Azure AI API Base - Set AZURE_AI_API_BASE environment variable or pass api_base parameter","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/ocr/transformation.py","lineNumber":66,"sourceCode":"        Validate environment and return headers for Azure AI OCR.\n\n        Azure AI uses Bearer token authentication with AZURE_AI_API_KEY.\n        \"\"\"\n        # Get API key from environment if not provided\n        if api_key is None:\n            api_key = get_secret_str(AZURE_AI_OCR_API_KEY_ENV_VAR)\n\n        if api_key is None:\n            raise ValueError(\n                \"Missing Azure AI API Key - A call is being made to Azure AI but no key is set either in the environment variables or via params\"\n            )\n\n        # Validate API base is provided\n        if api_base is None:\n            api_base = get_secret_str(\"AZURE_AI_API_BASE\")\n\n        if api_base is None:\n            raise ValueError(\n                \"Missing Azure AI API Base - Set AZURE_AI_API_BASE environment variable or pass api_base parameter\"\n            )\n\n        headers = {\n            \"Authorization\": f\"Bearer {api_key}\",\n            \"Content-Type\": \"application/json\",\n            **headers,\n        }\n\n        return headers\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        model: str,\n        optional_params: dict,\n        litellm_params: dict | None = None,\n        **kwargs,","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/ocr/transformation.py#L48-L84","documentation":"Thrown by the Azure AI OCR config's validate_environment when building request headers: no API base URL could be resolved. LiteLLM needs the Azure AI services endpoint (e.g. https://<resource>.services.ai.azure.com) to know where to send the OCR request, and it looked both in the explicit api_base parameter and the AZURE_AI_API_BASE environment variable before giving up.","triggerScenarios":"Calling litellm.ocr(...) with an azure_ai/mistral-ocr model while neither api_base is passed (or router model_info entry) nor AZURE_AI_API_BASE is set in the environment. The header builder resolves the API key first, so a missing key fails earlier; this fires only when the key exists but the base URL does not.","commonSituations":"Copying an OCR example that hardcodes only the API key; deploying to a new environment (container/CI) where AZURE_AI_API_BASE was not exported; using the proxy where the model entry in config.yaml lacks api_base.","solutions":["Set the environment variable: export AZURE_AI_API_BASE=https://<your-resource>.services.ai.azure.com","Or pass api_base explicitly: litellm.ocr(model='azure_ai/mistral-ocr', document=..., api_base='https://<resource>.services.ai.azure.com', api_key=...)","If using LiteLLM proxy, add api_base (and api_key) to the model's litellm_params in config.yaml and restart"],"exampleFix":"# before\nlitellm.ocr(model='azure_ai/mistral-ocr', document={'type':'document_url','document_url':url}, api_key=os.environ['AZURE_AI_API_KEY'])\n\n# after\nlitellm.ocr(model='azure_ai/mistral-ocr', document={'type':'document_url','document_url':url}, api_key=os.environ['AZURE_AI_API_KEY'], api_base='https://my-resource.services.ai.azure.com')","handlingStrategy":"validation","validationCode":"import os\napi_base = os.environ.get('AZURE_AI_API_BASE')\nif not api_base:\n    raise SystemExit('Configure AZURE_AI_API_BASE before running OCR jobs')","typeGuard":null,"tryCatchPattern":"try:\n    litellm.ocr(model='azure_ai/mistral-ocr', document=doc)\nexcept ValueError as e:\n    if 'Missing Azure AI API Base' in str(e):\n        raise ConfigurationError('Azure AI endpoint not set') from e\n    raise","preventionTips":["Centralize Azure AI credentials in one config module that asserts AZURE_AI_API_BASE and AZURE_AI_API_KEY at startup","Add config smoke tests that call a cheap Azure AI endpoint in CI"],"tags":["azure","ocr","configuration","missing-parameter"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}