{"record":{"id":"98d2d06029a991ce","repo":"openai/openai-python","slug":"must-provide-one-of-the-base-url-or-azure-endpo","errorCode":null,"errorMessage":"Must provide one of the `base_url` or `azure_endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable","messagePattern":"Must provide one of the `base_url` or `azure_endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"src/openai/lib/azure.py","lineNumber":324,"sourceCode":"        if api_version is None:\n            api_version = os.environ.get(\"OPENAI_API_VERSION\")\n\n        if api_version is None:\n            raise ValueError(\n                \"Must provide either the `api_version` argument or the `OPENAI_API_VERSION` environment variable\"\n            )\n\n        if default_query is None:\n            default_query = {\"api-version\": api_version}\n        else:\n            default_query = {**default_query, \"api-version\": api_version}\n\n        if base_url is None:\n            if azure_endpoint is None:\n                azure_endpoint = os.environ.get(\"AZURE_OPENAI_ENDPOINT\")\n\n            if azure_endpoint is None:\n                raise ValueError(\n                    \"Must provide one of the `base_url` or `azure_endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable\"\n                )\n\n            if azure_deployment is not None:\n                base_url = f\"{azure_endpoint.rstrip('/')}/openai/deployments/{azure_deployment}\"\n            else:\n                base_url = f\"{azure_endpoint.rstrip('/')}/openai\"\n        else:\n            if azure_endpoint is not None:\n                raise ValueError(\"base_url and azure_endpoint are mutually exclusive\")\n\n        if api_key is None:\n            # define a sentinel value to avoid any typing issues\n            api_key = API_KEY_SENTINEL\n\n        super().__init__(\n            api_key=api_key,\n            admin_api_key=admin_api_key,","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/azure.py#L306-L342","documentation":"The synchronous AzureOpenAI client requires a service endpoint to build request URLs. None was supplied via the base_url argument, the azure_endpoint argument, or the AZURE_OPENAI_ENDPOINT environment variable, so the client cannot determine where to send requests and raises ValueError during construction.","triggerScenarios":"Constructing AzureOpenAI() with no azure_endpoint/base_url and no AZURE_OPENAI_ENDPOINT env var set; CI shells or stripped env where the variable was expected but absent.","commonSituations":"Env var not exported in the active shell/venv, .env file not loaded, deploying to a new environment without copying Azure config, or confusing OpenAI's OPENAI_BASE_URL with AZURE_OPENAI_ENDPOINT.","solutions":["Set AZURE_OPENAI_ENDPOINT (e.g. https://myresource.openai.azure.com) in the environment","Pass azure_endpoint=\"https://myresource.openai.azure.com\" to AzureOpenAI(...)","Alternatively pass base_url directly if you use a full custom URL"],"exampleFix":"// before\nclient = AzureOpenAI(api_version=\"2024-02-01\")\n// after\nclient = AzureOpenAI(azure_endpoint=\"https://myresource.openai.azure.com\", api_version=\"2024-02-01\")","handlingStrategy":"validation","validationCode":"import os\nif not (os.environ.get(\"AZURE_OPENAI_ENDPOINT\") or MY_AZURE_ENDPOINT):\n    raise RuntimeError(\"AZURE_OPENAI_ENDPOINT or azure_endpoint is required\")","typeGuard":null,"tryCatchPattern":"try:\n    client = AzureOpenAI(api_version=V)\nexcept ValueError as e:\n    if \"azure_endpoint\" in str(e):\n        raise ConfigError(str(e)) from e\n    raise","preventionTips":["Centralize Azure config in one settings module","Fail fast at startup on missing env vars","Document required env vars in README/deployment config"],"tags":["azure","configuration","env-var","client-init"],"backgroundTag":"missing-required-config","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}