openai/openai-python · error · ValueError
The `default_headers` and `set_default_headers` arguments ar
Error message
The `default_headers` and `set_default_headers` arguments are mutually exclusive
What it means
`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.
Source
Thrown at src/openai/lib/bedrock.py:575
max_retries: int | NotGiven = NOT_GIVEN,
default_headers: Mapping[str, str] | None = None,
set_default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
set_default_query: Mapping[str, object] | None = None,
_enforce_credentials: bool | None = None,
_extra_kwargs: Mapping[str, Any] = {},
) -> Self:
if data_residency is not None:
raise OpenAIError("`data_residency` is only supported by OpenAI clients")
base_url = None if isinstance(base_url, NotGiven) else base_url
if callable(api_key):
raise OpenAIError("Pass refreshable Bedrock credentials via `bedrock_token_provider`, not `api_key`.")
if not isinstance(provider, NotGiven):
raise OpenAIError("Configure `provider` on `OpenAI`, not on `BedrockOpenAI.with_options()`.")
if admin_api_key is not None or workload_identity is not None:
raise OpenAIError("BedrockOpenAI only supports Bedrock bearer token or AWS credential authentication.")
if default_headers is not None and set_default_headers is not None:
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
if default_query is not None and set_default_query is not None:
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
headers = self._custom_headers
if default_headers is not None:
headers = {**headers, **default_headers}
elif set_default_headers is not None:
headers = set_default_headers
params = self._custom_query
if default_query is not None:
params = {**params, **default_query}
elif set_default_query is not None:
params = set_default_query
provider_kwargs, inherited_provider, inherited_state = _copy_configuration(
self,
api_key=api_key,
token_provider=bedrock_token_provider,View on GitHub (pinned to 9917c6e28e)
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
Example fix
# before
c = bedrock_client.with_options(default_headers={'X-A':'1'}, set_default_headers={'X-B':'2'})
# after
c = bedrock_client.with_options(set_default_headers={'X-A':'1','X-B':'2'}) Defensive patterns
Strategy: validation
Validate before calling
assert not (default_headers is not None and set_default_headers is not None)
Prevention
- Pass exactly one of default_headers/set_default_headers; merge dicts yourself
When it happens
Trigger: `bedrock_client.with_options(default_headers={'X-A':'1'}, set_default_headers={'X-B':'2'})` — both arguments non-None.
Common situations: 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`.
Related errors
- The `default_query` and `set_default_query` arguments are mu
- `data_residency` is only supported by OpenAI clients
- Configure `provider` on `OpenAI`, not on `BedrockOpenAI.with
- BedrockOpenAI only supports Bedrock bearer token or AWS cred
- Configure `provider` on `AsyncOpenAI`, not on `AsyncBedrockO
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/1d2e176279313154.
Report an issue: GitHub.