{"record":{"id":"c45f9691d4c566ad","repo":"openai/openai-python","slug":"the-default-headers-and-set-default-headers-ar","errorCode":null,"errorMessage":"The `default_headers` and `set_default_headers` arguments are mutually exclusive","messagePattern":"The `default_headers` and `set_default_headers` arguments are mutually exclusive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/_client.py","lineNumber":706,"sourceCode":"        websocket_base_url: str | httpx2.URL | None = None,\n        base_url: str | httpx2.URL | None | NotGiven = not_given,\n        data_residency: DataResidency | None = None,\n        timeout: float | Timeout | None | NotGiven = not_given,\n        http_client: httpx2.Client | None = None,\n        max_retries: int | NotGiven = not_given,\n        default_headers: Mapping[str, str] | None = None,\n        set_default_headers: Mapping[str, str] | None = None,\n        default_query: Mapping[str, object] | None = None,\n        set_default_query: Mapping[str, object] | None = None,\n        _enforce_credentials: bool | None = None,\n        _extra_kwargs: Mapping[str, Any] = {},\n    ) -> Self:\n        \"\"\"\n        Create a new client instance re-using the same options given to the current client with optional overriding.\n        `data_residency` replaces the inherited HTTP and WebSocket endpoints, without changing this client.\n        \"\"\"\n        if default_headers is not None and set_default_headers is not None:\n            raise ValueError(\"The `default_headers` and `set_default_headers` arguments are mutually exclusive\")\n\n        if default_query is not None and set_default_query is not None:\n            raise ValueError(\"The `default_query` and `set_default_query` arguments are mutually exclusive\")\n\n        provider_changed = not isinstance(provider, NotGiven) and provider is not self._provider\n        inherited_organization = None if provider_changed else self.organization\n        inherited_project = None if provider_changed else self.project\n\n        headers: Mapping[str, str] = {} if provider_changed else self._custom_headers\n        if (\n            is_x509_workload_identity(workload_identity)\n            and not is_x509_workload_identity(self.workload_identity)\n            and self._ambient_authorizations\n        ):\n            headers = {\n                name: value\n                for name, value in headers.items()\n                if name.lower() != \"authorization\" or value not in self._ambient_authorizations","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_client.py#L688-L724","documentation":"`client.copy()` accepts either `default_headers` (merged over the existing headers) or `set_default_headers` (replaces them) — passing both is ambiguous, so it raises ValueError before creating the clone.","triggerScenarios":"`client.copy(default_headers={...}, set_default_headers={...})`; wrapper/clone helpers forwarding both kwargs from callers.","commonSituations":"Config-layer code building derived clients that forwards any header kwargs it received; refactor from one parameter to the other leaving both populated.","solutions":["Choose one: `copy(default_headers={'X-Extra': v'})` to merge, or `copy(set_default_headers={...})` to replace","In shared helpers, resolve to a single parameter before calling copy"],"exampleFix":"# before\nnew = client.copy(default_headers={'X-A': '1'}, set_default_headers={'X-B': '2'})\n\n# after\nnew = client.copy(set_default_headers={'X-A': '1', 'X-B': '2'})","handlingStrategy":"validation","validationCode":"assert not (default_headers is not None and set_default_headers is not None), \\\n    'copy(): default_headers XOR set_default_headers'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember semantics: default_headers merges, set_default_headers replaces","In clone helpers, accept a single headers mapping plus a replace flag"],"tags":["headers","copy","configuration","conflict","valueerror"],"backgroundTag":"conflicting-constructor-arguments","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}