openai/openai-python · error · OpenAIError

The Bedrock `base_url` must not be empty.

Error message

The Bedrock `base_url` must not be empty.

What it means

A `base_url` argument was provided to `bedrock()` as a string containing only whitespace. Since base_url overrides endpoint construction, an explicitly empty value is treated as a configuration mistake and rejected.

Source

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

    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
    )
    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."
        )

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass a real URL or None (or NotGiven) so environment/AWS defaults apply
  2. Guard env-derived URLs: `base_url = os.environ.get('AWS_BEDROCK_BASE_URL') or None`

Example fix

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

Strategy: validation

Validate before calling

base_url = os.environ.get('AWS_BEDROCK_BASE_URL') or None
bedrock(base_url=base_url)

Type guard

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

Prevention

When it happens

Trigger: Calling bedrock(base_url='') or base_url=' '; typically when the value comes from a template variable or env var that resolved to blank.

Common situations: EMPTY_AWS_BEDROCK_BASE_URL-style env plumbing, or Docker/Kubernetes configs where a variable is set but empty.

Related errors


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