{"record":{"id":"ec698838379f4a7a","repo":"openai/openai-python","slug":"must-provide-either-the-api-version-argument-or","errorCode":null,"errorMessage":"Must provide either the `api_version` argument or the `OPENAI_API_VERSION` environment variable","messagePattern":"Must provide either the `api_version` argument or the `OPENAI_API_VERSION` environment variable","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"src/openai/lib/azure.py","lineNumber":310,"sourceCode":"                Not supported with Assistants APIs.\n        \"\"\"\n        if is_x509_workload_identity(workload_identity):\n            raise OpenAIError(\"X.509 workload identity is not supported by Azure clients\")\n\n        api_key, azure_ad_token, azure_ad_token_provider = _resolve_azure_auth(\n            api_key, azure_ad_token, azure_ad_token_provider\n        )\n\n        if _enforce_credentials and api_key is None and azure_ad_token is None and azure_ad_token_provider is None:\n            raise OpenAIError(\n                \"Missing credentials. Please pass one of `api_key`, `azure_ad_token`, `azure_ad_token_provider`, or the `AZURE_OPENAI_API_KEY` or `AZURE_OPENAI_AD_TOKEN` environment variables.\"\n            )\n\n        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:","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/azure.py#L292-L328","documentation":"AzureOpenAI needs an API version to build request URLs and the default api-version query param. If neither the api_version constructor argument nor the OPENAI_API_VERSION environment variable is present, construction raises ValueError.","triggerScenarios":"new AzureOpenAI() without api_version and without OPENAI_API_VERSION exported (e.g. fresh container, CI runner, or notebook).","commonSituations":"Works locally (var set in shell) but fails in Docker/cron/CI; upgrading from older SDK versions that had a default; typos like OPENAI_APIVERSION.","solutions":["Pass api_version explicitly: AzureOpenAI(api_version='2024-10-21', ...)","Or set OPENAI_API_VERSION in the process environment","Use a supported stable date-version from the Azure OpenAI API reference for the features you use"],"exampleFix":"# before\nclient = AzureOpenAI(azure_endpoint=..., api_key=...)\n# after\nclient = AzureOpenAI(azure_endpoint=..., api_key=..., api_version=\"2024-10-21\")","handlingStrategy":"validation","validationCode":"api_version = os.environ.get(\"OPENAI_API_VERSION\") or \"2024-10-21\"\nclient = AzureOpenAI(api_version=api_version, ...)","typeGuard":null,"tryCatchPattern":"try:\n    client = AzureOpenAI(...)\nexcept ValueError as e:\n    if \"api_version\" in str(e):\n        client = AzureOpenAI(api_version=\"2024-10-21\", ...)\n    else:\n        raise","preventionTips":["Always pass api_version explicitly instead of relying on env","Set OPENAI_API_VERSION in Docker/CI where shells differ","Pin a documented stable Azure API version per release"],"tags":["azure","config","api-version","env-vars"],"backgroundTag":"missing-required-config","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}