openai/openai-python · error · OpenAIError

The Bedrock AWS `region` must not be empty.

Error message

The Bedrock AWS `region` must not be empty.

What it means

A `region` argument was supplied to `bedrock()` but it normalizes to an empty value (empty string or whitespace-only). Because region is how the SDK builds the AWS endpoint host, an empty-but-present region is rejected rather than silently used.

Source

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

    endpoint: BedrockEndpoint | None = None,
    region: str | None = None,
    base_url: str | httpx2.URL | None | NotGiven = NOT_GIVEN,
    api_key: str | None | NotGiven = NOT_GIVEN,
    token_provider: BedrockTokenProvider | None = None,
    access_key_id: str | None = None,
    secret_access_key: str | None = None,
    session_token: str | None = None,
    profile: str | None = None,
    credential_provider: AwsCredentialsProvider | None = None,
) -> _Provider:
    """Configure the standard OpenAI client for Amazon Bedrock Mantle or Runtime."""

    if endpoint is not None and endpoint not in {"mantle", "runtime"}:
        raise OpenAIError("The Bedrock `endpoint` must be either `mantle` or `runtime`.")

    normalized_region = _normalize_optional_string(region)
    if region is not None and normalized_region is None:
        raise OpenAIError("The Bedrock AWS `region` must not be empty.")
    _validate_bedrock_region(normalized_region)

    region_source: Literal["explicit", "environment"] | None = "explicit" if normalized_region is not None else None

    configured_base_url: httpx2.URL | None
    if isinstance(base_url, NotGiven):
        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
    )

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass a real region like 'us-east-1', or pass None to use environment detection
  2. Trim/validate config values before forwarding them to bedrock()

Example fix

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

Strategy: validation

Validate before calling

region = (region or '').strip() or None
bedrock(region=region)

Type guard

def is_nonempty_str(v: object) -> bool:
    return isinstance(v, str) and bool(v.strip())

Prevention

When it happens

Trigger: Calling bedrock(region='') or bedrock(region=' '); commonly happens when region is read from a config/env variable that is defined but blank.

Common situations: region = os.environ.get('AWS_REGION', '') passed straight through, or a YAML/TOML config with `region = ""`.

Related errors


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