{"record":{"id":"a381848ead95904c","repo":"openai/openai-python","slug":"the-data-residency-and-base-url-arguments-are","errorCode":null,"errorMessage":"The `data_residency` and `base_url` arguments are mutually exclusive","messagePattern":"The `data_residency` and `base_url` arguments are mutually exclusive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/_data_residency.py","lineNumber":33,"sourceCode":"    \"global\": \"https://api.openai.com/v1\",\n    \"us\": \"https://us.api.openai.com/v1\",\n    \"eu\": \"https://eu.api.openai.com/v1\",\n    \"ae\": \"https://ae.api.openai.com/v1\",\n}\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":15,"sourceCodeEnd":41,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_data_residency.py#L15-L41","documentation":"resolve_data_residency (used by OpenAI(...) and client.copy()) raises ValueError when a named `data_residency` endpoint ('global'/'us'/'eu'/'ae') is combined with an explicit `base_url`. The named residency already determines the base URL, so an additional base_url would be contradictory.","triggerScenarios":"OpenAI(data_residency=\"eu\", base_url=\"https://custom.example.com/...\"), or client.copy(data_residency=\"us\", base_url=...) where base_url is any non-NotGiven value (including None passed explicitly as NotGiven check is bypassed when data_residency set and base_url given).","commonSituations":"Adding data residency to an existing deployment that already pinned a custom base_url for a gateway/proxy; configuring both in YAML/env-derived config dicts; regional-compliance rollout colliding with existing endpoint overrides.","solutions":["Remove base_url and let data_residency select the regional endpoint.","If you truly need the custom base_url, drop data_residency (ensure the custom URL already targets the desired residency region).","Point the custom gateway at the residency endpoint and pass only base_url, or only data_residency."],"exampleFix":"# before\nclient = OpenAI(data_residency=\"eu\", base_url=\"https://api.openai.com/v1\")\n\n# after\nclient = OpenAI(data_residency=\"eu\")","handlingStrategy":"validation","validationCode":"def build_base(data_residency=None, base_url=None):\n    if data_residency is not None and base_url is not None:\n        raise ValueError(\"choose data_residency or base_url, not both\")\n    return data_residency or base_url","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model endpoint config as one mutually exclusive field (enum or URL) in your config schema.","Document that data_residency implies both HTTP and WebSocket endpoints."],"tags":["data-residency","base-url","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"}