openai/openai-python · error · OpenAIError

The `data_residency` and `provider` arguments are mutually e

Error message

The `data_residency` and `provider` arguments are mutually exclusive

What it means

resolve_data_residency raises OpenAIError when `data_residency` is combined with a `provider` (e.g. a cloud/managed provider runtime). Provider runtimes dictate their own base URL and auth pipeline, which cannot be overridden by a named OpenAI data-residency endpoint.

Source

Thrown at src/openai/_data_residency.py:37

}


def resolve_data_residency(
    data_residency: DataResidency | None,
    base_url: str | httpx2.URL | None | NotGiven,
    *,
    provider: object | None = None,
    websocket_base_url: str | httpx2.URL | None = None,
) -> str | httpx2.URL | None:
    """Resolve a named endpoint before inherited or environment options are applied."""
    if data_residency is None:
        return None if isinstance(base_url, NotGiven) else base_url
    if not isinstance(base_url, NotGiven):
        raise ValueError("The `data_residency` and `base_url` arguments are mutually exclusive")
    if websocket_base_url is not None:
        raise ValueError("The `data_residency` and `websocket_base_url` arguments are mutually exclusive")
    if provider is not None:
        raise OpenAIError("The `data_residency` and `provider` arguments are mutually exclusive")
    if not isinstance(cast(object, data_residency), str) or data_residency not in _DATA_RESIDENCY_BASE_URLS:
        raise ValueError("Invalid `data_residency`; expected one of 'global', 'us', 'eu', or 'ae'")
    return _DATA_RESIDENCY_BASE_URLS[data_residency]

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Remove data_residency when using a provider runtime; the provider defines its endpoint and region.
  2. Or drop the provider to use OpenAI-direct endpoints with data_residency.

Example fix

# before
client = OpenAI(provider=provider_runtime, data_residency="eu")

# after
client = OpenAI(provider=provider_runtime)
Defensive patterns

Strategy: validation

Validate before calling

def build_client_opts(provider=None, data_residency=None):
    if provider is not None and data_residency is not None:
        raise ValueError("provider runtime defines its endpoint; drop data_residency")
    return {"provider": provider, "data_residency": data_residency}

Prevention

When it happens

Trigger: OpenAI(provider=SomeProvider(...), data_residency="eu") or client.copy(provider=..., data_residency=...) — any non-None provider together with a data_residency value.

Common situations: Configuring a managed/third-party provider (gateway or partner runtime) while keeping data_residency from an earlier OpenAI-direct config; merged config files where both keys survive.

Related errors


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