{"record":{"id":"f8a57de1144eff23","repo":"openai/openai-python","slug":"the-data-residency-and-websocket-base-url-argu","errorCode":null,"errorMessage":"The `data_residency` and `websocket_base_url` arguments are mutually exclusive","messagePattern":"The `data_residency` and `websocket_base_url` arguments are mutually exclusive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/_data_residency.py","lineNumber":35,"sourceCode":"    \"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":17,"sourceCodeEnd":41,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_data_residency.py#L17-L41","documentation":"resolve_data_residency raises ValueError when `data_residency` is combined with `websocket_base_url`. A named residency fixes both HTTP and WebSocket endpoints, so supplying a separate WebSocket URL is contradictory and rejected before the client is built.","triggerScenarios":"OpenAI(data_residency=\"us\", websocket_base_url=\"wss://...\") or client.copy(data_residency=..., websocket_base_url=...) with websocket_base_url not None.","commonSituations":"Enabling Realtime/WebSocket features with a previously customized websocket_base_url, then adding data_residency for compliance; config templates that always set both endpoint knobs.","solutions":["Remove websocket_base_url and rely on data_residency to derive both endpoints.","If a custom WebSocket endpoint is required, drop data_residency and set base_url/websocket_base_url explicitly to the desired region's URLs."],"exampleFix":"# before\nclient = OpenAI(data_residency=\"eu\", websocket_base_url=\"wss://eu.example.com/v1\")\n\n# after\nclient = OpenAI(data_residency=\"eu\")","handlingStrategy":"validation","validationCode":"def build_endpoints(data_residency=None, websocket_base_url=None):\n    if data_residency is not None and websocket_base_url is not None:\n        raise ValueError(\"data_residency already defines the websocket URL\")\n    return data_residency, websocket_base_url","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep WebSocket overrides out of configs that also select a named residency.","Validate endpoint config in one place before client construction."],"tags":["data-residency","websocket","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"}