openai/openai-python · error · OpenAIError

The Bedrock AWS `profile` must not be empty.

Error message

The Bedrock AWS `profile` must not be empty.

What it means

A `profile` argument was supplied to `bedrock()` but it is empty or whitespace-only. The profile name selects a shared-credentials entry, so an explicitly empty string is rejected as a misconfiguration.

Source

Thrown at src/openai/providers/bedrock.py:428

        environment_base_url = _normalize_optional_string(os.environ.get("AWS_BEDROCK_BASE_URL"))
        configured_base_url = _normalize_base_url(environment_base_url) if environment_base_url else None
    elif base_url is None:
        configured_base_url = None
    else:
        if isinstance(base_url, str) and not base_url.strip():
            raise OpenAIError("The Bedrock `base_url` must not be empty.")
        configured_base_url = _normalize_base_url(base_url)

    canonical_endpoint = (
        _parse_bedrock_endpoint_hostname(configured_base_url.host) if configured_base_url is not None else None
    )
    resolved_endpoint: BedrockEndpoint = endpoint or (
        canonical_endpoint[0] if canonical_endpoint is not None else "mantle"
    )

    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

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass a real profile name or None to use the default credential chain
  2. Normalize env-derived values: `os.environ.get('AWS_PROFILE') or None`

Example fix

# before
bedrock(profile=os.environ.get('AWS_PROFILE', ''))
# after
bedrock(profile=os.environ.get('AWS_PROFILE') or None)
Defensive patterns

Strategy: validation

Validate before calling

profile = os.environ.get('AWS_PROFILE') or None
bedrock(profile=profile)

Type guard

def is_nonempty_profile(v: object) -> bool:
    return v is None or (isinstance(v, str) and bool(v.strip()))

Prevention

When it happens

Trigger: Calling bedrock(profile='') or profile=' ', often from a blank AWS_PROFILE-style setting forwarded into the provider.

Common situations: profile = os.environ.get('AWS_PROFILE', '') forwarded unconditionally, or CI config with an empty profile key.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/3b5231c622c321a1. Report an issue: GitHub.