openai/openai-python · error · OpenAIError

`data_residency` is only supported by OpenAI clients

Error message

`data_residency` is only supported by OpenAI clients

What it means

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.

Source

Thrown at src/openai/lib/azure.py:397

        azure_ad_token: str | None = None,
        azure_ad_token_provider: AzureADTokenProvider | None = None,
        base_url: str | httpx2.URL | None | NotGiven = NOT_GIVEN,
        data_residency: DataResidency | None = None,
        timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
        http_client: httpx2.Client | None = None,
        max_retries: int | NotGiven = NOT_GIVEN,
        default_headers: Mapping[str, str] | None = None,
        set_default_headers: Mapping[str, str] | None = None,
        default_query: Mapping[str, object] | None = None,
        set_default_query: Mapping[str, object] | None = None,
        _enforce_credentials: bool | None = None,
        _extra_kwargs: Mapping[str, Any] = {},
    ) -> Self:
        """
        Create a new client instance re-using the same options given to the current client with optional overriding.
        """
        if data_residency is not None:
            raise OpenAIError("`data_residency` is only supported by OpenAI clients")
        base_url = None if isinstance(base_url, NotGiven) else base_url
        if not isinstance(provider, NotGiven):
            raise OpenAIError("Configure `provider` on `OpenAI`, not on `AzureOpenAI.with_options()`.")
        if is_x509_workload_identity(workload_identity):
            raise OpenAIError("X.509 workload identity is not supported by Azure clients")

        api_key, azure_ad_token, azure_ad_token_provider = _copy_azure_auth(
            api_key,
            azure_ad_token,
            azure_ad_token_provider,
            current_api_key=self._api_key_provider or self.api_key,
            current_token=self._azure_ad_token,
            current_provider=self._azure_ad_token_provider,
        )

        return super().copy(
            api_key=api_key,
            admin_api_key=admin_api_key,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Remove data_residency from the with_options() call for Azure clients
  2. Only set data_residency when constructing/copying an OpenAI client
  3. Branch your config logic by client type

Example fix

# before
client = azure_client.with_options(data_residency='eu')
# after
client = azure_client.with_options(timeout=30.0)
Defensive patterns

Strategy: validation

Validate before calling

opts = {k: v for k, v in shared_opts.items() if k != "data_residency"} if isinstance(client, AzureOpenAI) else shared_opts
client = client.with_options(**opts)

Type guard

from openai import AzureOpenAI
def is_azure_client(c) -> bool:
    return isinstance(c, AzureOpenAI)

Prevention

When it happens

Trigger: 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.

Common situations: Shared wrapper code that builds options for both OpenAI and AzureOpenAI; migrating from OpenAI to AzureOpenAI without removing data_residency.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/0dc34ec94a1b5fb7. Report an issue: GitHub.