{"record":{"id":"4b781336c99b850a","repo":"openai/openai-python","slug":"the-data-residency-and-provider-arguments-are","errorCode":null,"errorMessage":"The `data_residency` and `provider` arguments are mutually exclusive","messagePattern":"The `data_residency` and `provider` arguments are mutually exclusive","errorType":"error_code","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"src/openai/_data_residency.py","lineNumber":37,"sourceCode":"}\n\n\ndef resolve_data_residency(\n    data_residency: DataResidency | None,\n    base_url: str | httpx2.URL | None | NotGiven,\n    *,\n    provider: object | None = None,\n    websocket_base_url: str | httpx2.URL | None = None,\n) -> str | httpx2.URL | None:\n    \"\"\"Resolve a named endpoint before inherited or environment options are applied.\"\"\"\n    if data_residency is None:\n        return None if isinstance(base_url, NotGiven) else base_url\n    if not isinstance(base_url, NotGiven):\n        raise ValueError(\"The `data_residency` and `base_url` arguments are mutually exclusive\")\n    if websocket_base_url is not None:\n        raise ValueError(\"The `data_residency` and `websocket_base_url` arguments are mutually exclusive\")\n    if provider is not None:\n        raise OpenAIError(\"The `data_residency` and `provider` arguments are mutually exclusive\")\n    if not isinstance(cast(object, data_residency), str) or data_residency not in _DATA_RESIDENCY_BASE_URLS:\n        raise ValueError(\"Invalid `data_residency`; expected one of 'global', 'us', 'eu', or 'ae'\")\n    return _DATA_RESIDENCY_BASE_URLS[data_residency]\n","sourceCodeStart":19,"sourceCodeEnd":41,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_data_residency.py#L19-L41","documentation":"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.","triggerScenarios":"OpenAI(provider=SomeProvider(...), data_residency=\"eu\") or client.copy(provider=..., data_residency=...) — any non-None provider together with a data_residency value.","commonSituations":"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.","solutions":["Remove data_residency when using a provider runtime; the provider defines its endpoint and region.","Or drop the provider to use OpenAI-direct endpoints with data_residency."],"exampleFix":"# before\nclient = OpenAI(provider=provider_runtime, data_residency=\"eu\")\n\n# after\nclient = OpenAI(provider=provider_runtime)","handlingStrategy":"validation","validationCode":"def build_client_opts(provider=None, data_residency=None):\n    if provider is not None and data_residency is not None:\n        raise ValueError(\"provider runtime defines its endpoint; drop data_residency\")\n    return {\"provider\": provider, \"data_residency\": data_residency}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make provider selection exclusive with OpenAI-direct endpoint options in your config schema.","When migrating to a provider runtime, strip legacy data_residency/base_url keys."],"tags":["data-residency","provider","mutually-exclusive","constructor"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}