{"record":{"id":"1d2e176279313154","repo":"openai/openai-python","slug":"the-default-headers-and-set-default-headers-ar-1d2e17","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/lib/bedrock.py","lineNumber":575,"sourceCode":"        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        if data_residency is not None:\n            raise OpenAIError(\"`data_residency` is only supported by OpenAI clients\")\n        base_url = None if isinstance(base_url, NotGiven) else base_url\n        if callable(api_key):\n            raise OpenAIError(\"Pass refreshable Bedrock credentials via `bedrock_token_provider`, not `api_key`.\")\n        if not isinstance(provider, NotGiven):\n            raise OpenAIError(\"Configure `provider` on `OpenAI`, not on `BedrockOpenAI.with_options()`.\")\n        if admin_api_key is not None or workload_identity is not None:\n            raise OpenAIError(\"BedrockOpenAI only supports Bedrock bearer token or AWS credential authentication.\")\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        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        headers = self._custom_headers\n        if default_headers is not None:\n            headers = {**headers, **default_headers}\n        elif set_default_headers is not None:\n            headers = set_default_headers\n        params = self._custom_query\n        if default_query is not None:\n            params = {**params, **default_query}\n        elif set_default_query is not None:\n            params = set_default_query\n\n        provider_kwargs, inherited_provider, inherited_state = _copy_configuration(\n            self,\n            api_key=api_key,\n            token_provider=bedrock_token_provider,","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/bedrock.py#L557-L593","documentation":"`copy()`/`with_options()` distinguishes replacing headers (`set_default_headers`) from merging into existing ones (`default_headers`). Passing both makes the semantics ambiguous, so the sync Bedrock client raises a ValueError.","triggerScenarios":"`bedrock_client.with_options(default_headers={'X-A':'1'}, set_default_headers={'X-B':'2'})` — both arguments non-None.","commonSituations":"Delegating builder functions that forward a headers dict to both parameters; merging config presets where one sets `default_headers` and another sets `set_default_headers`.","solutions":["Pick one: `default_headers` to merge with the client's current headers, or `set_default_headers` to replace them","Combine your header dicts yourself and pass the merged dict to one argument"],"exampleFix":"# before\nc = bedrock_client.with_options(default_headers={'X-A':'1'}, set_default_headers={'X-B':'2'})\n# after\nc = bedrock_client.with_options(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)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass exactly one of default_headers/set_default_headers; merge dicts yourself"],"tags":["bedrock","headers","with-options","mutually-exclusive"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}