openai/openai-python · error · OpenAIError
The Bedrock bearer credential must not be empty.
Error message
The Bedrock bearer credential must not be empty.
What it means
An `api_key` was explicitly passed to `bedrock()` (as a bearer credential for Bedrock Mantle) but it is empty or whitespace-only. The SDK validates this before constructing the client so requests fail fast instead of sending an Authorization header AWS rejects.
Source
Thrown at src/openai/providers/bedrock.py:442
)
normalized_profile = _normalize_optional_string(profile)
if profile is not None and normalized_profile is None:
raise OpenAIError("The Bedrock AWS `profile` must not be empty.")
if (access_key_id is None) != (secret_access_key is None) or (session_token is not None and access_key_id is None):
raise OpenAIError(
"Static AWS credentials require both `access_key_id` and `secret_access_key`. "
"A `session_token` may only be used with both."
)
if access_key_id is not None and (not access_key_id.strip() or not cast(str, secret_access_key).strip()):
raise OpenAIError("Static AWS credentials require non-empty `access_key_id` and `secret_access_key` values.")
if session_token is not None and not session_token.strip():
raise OpenAIError("A static AWS `session_token` must not be empty when provided.")
explicit_api_key = not isinstance(api_key, NotGiven) and api_key is not None
if explicit_api_key and (not isinstance(api_key, str) or not api_key.strip()):
raise OpenAIError("The Bedrock bearer credential must not be empty.")
if explicit_api_key and token_provider is not None:
raise OpenAIError("The `api_key` and `token_provider` options are mutually exclusive. Configure only one.")
explicit_bearer = explicit_api_key or token_provider is not None
aws_modes = sum(
(
access_key_id is not None,
normalized_profile is not None,
credential_provider is not None,
)
)
if aws_modes > 1:
raise OpenAIError(
"Bedrock authentication is ambiguous. Configure exactly one explicit AWS mode: static credentials, "
"profile, or credential provider."
)
if explicit_bearer and aws_modes:
raise OpenAIError(View on GitHub (pinned to 9917c6e28e)
Solutions
- Pass a real bearer token or omit api_key / set it to None so other credential sources apply
- Normalize: api_key=os.environ.get('API_KEY') or None
Example fix
# before
bedrock(api_key=os.environ.get('OPENAI_API_KEY', ''))
# after
bedrock(api_key=os.environ.get('OPENAI_API_KEY') or None) Defensive patterns
Strategy: validation
Validate before calling
api_key = os.environ.get('OPENAI_API_KEY') or None
bedrock(api_key=api_key) Type guard
def bearer_key_ok(k: object) -> bool:
return k is None or (isinstance(k, str) and bool(k.strip())) Prevention
- Fail fast at startup if a required key is missing
- Never pass api_key=''
When it happens
Trigger: bedrock(api_key='') or api_key=' ', or passing api_key from an env var that is defined but blank.
Common situations: OPENAI_API_KEY-style env var set to an empty string in CI, or api_key=os.environ.get('API_KEY', '') forwarded unconditionally.
Related errors
- The `api_key` argument must not be empty.
- The Bedrock bearer credential provider must return a non-emp
- "Could not resolve authentication method. Expected either ap
- Pass refreshable Bedrock credentials via `bedrock_token_prov
- Refusing to authenticate a Bedrock request for an origin oth
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/7624de992ca4b628.
Report an issue: GitHub.