{"record":{"id":"0dc34ec94a1b5fb7","repo":"openai/openai-python","slug":"data-residency-is-only-supported-by-openai-clien","errorCode":null,"errorMessage":"`data_residency` is only supported by OpenAI clients","messagePattern":"`data_residency` is only supported by OpenAI clients","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/azure.py","lineNumber":397,"sourceCode":"        azure_ad_token: str | None = None,\n        azure_ad_token_provider: AzureADTokenProvider | None = None,\n        base_url: str | httpx2.URL | None | NotGiven = NOT_GIVEN,\n        data_residency: DataResidency | None = None,\n        timeout: float | Timeout | None | NotGiven = NOT_GIVEN,\n        http_client: httpx2.Client | None = None,\n        max_retries: int | NotGiven = NOT_GIVEN,\n        default_headers: Mapping[str, str] | None = None,\n        set_default_headers: Mapping[str, str] | None = None,\n        default_query: Mapping[str, object] | None = None,\n        set_default_query: Mapping[str, object] | None = None,\n        _enforce_credentials: bool | None = None,\n        _extra_kwargs: Mapping[str, Any] = {},\n    ) -> Self:\n        \"\"\"\n        Create a new client instance re-using the same options given to the current client with optional overriding.\n        \"\"\"\n        if data_residency is not None:\n            raise OpenAIError(\"`data_residency` is only supported by OpenAI clients\")\n        base_url = None if isinstance(base_url, NotGiven) else base_url\n        if not isinstance(provider, NotGiven):\n            raise OpenAIError(\"Configure `provider` on `OpenAI`, not on `AzureOpenAI.with_options()`.\")\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 = _copy_azure_auth(\n            api_key,\n            azure_ad_token,\n            azure_ad_token_provider,\n            current_api_key=self._api_key_provider or self.api_key,\n            current_token=self._azure_ad_token,\n            current_provider=self._azure_ad_token_provider,\n        )\n\n        return super().copy(\n            api_key=api_key,\n            admin_api_key=admin_api_key,","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/azure.py#L379-L415","documentation":"with_options() on AzureOpenAI rejects the data_residency override because that option only exists on the plain OpenAI client. Azure endpoints are pinned to a specific Azure region, so data residency cannot be reconfigured on an Azure client.","triggerScenarios":"Calling AzureOpenAI(...).with_options(data_residency='eu') or passing data_residency through a generic copy/helper that applies the same kwargs to both client types.","commonSituations":"Shared wrapper code that builds options for both OpenAI and AzureOpenAI; migrating from OpenAI to AzureOpenAI without removing data_residency.","solutions":["Remove data_residency from the with_options() call for Azure clients","Only set data_residency when constructing/copying an OpenAI client","Branch your config logic by client type"],"exampleFix":"# before\nclient = azure_client.with_options(data_residency='eu')\n# after\nclient = azure_client.with_options(timeout=30.0)","handlingStrategy":"validation","validationCode":"opts = {k: v for k, v in shared_opts.items() if k != \"data_residency\"} if isinstance(client, AzureOpenAI) else shared_opts\nclient = client.with_options(**opts)","typeGuard":"from openai import AzureOpenAI\ndef is_azure_client(c) -> bool:\n    return isinstance(c, AzureOpenAI)","tryCatchPattern":null,"preventionTips":["Branch option dicts by client type","Keep Azure-specific and OpenAI-specific options separated"],"tags":["azure","with-options","invalid-argument"],"backgroundTag":"unsupported-client-option","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}