openai/openai-python · error · OpenAIError
Bedrock requires an AWS region. Pass `region` to `bedrock(..
Error message
Bedrock requires an AWS region. Pass `region` to `bedrock(...)`, or set `AWS_REGION` or `AWS_DEFAULT_REGION`.
What it means
configure() needs a region to build the default Bedrock base_url. If no base_url was configured and no region came from the argument or AWS_REGION/AWS_DEFAULT_REGION, it cannot construct an endpoint and raises this OpenAIError explaining where to supply the region.
Source
Thrown at src/openai/providers/bedrock.py:355
bearer_provider = self.token_provider
region = self.configured_region
elif self.use_environment_bearer:
bearer_provider = environment_token
region = self.configured_region
else:
aws_config, aws_auth = self._resolve_aws_auth()
region = aws_config.region
_validate_bedrock_region(region)
base_url = self.configured_base_url or _default_bedrock_base_url(self.endpoint, region)
_validate_canonical_bedrock_endpoint(base_url, endpoint=self.endpoint, region=region)
auth = _BedrockSigV4Auth(config=aws_config, base_url=base_url, auth=aws_auth)
if self.configured_base_url is not None:
base_url = self.configured_base_url
elif region is not None:
base_url = _default_bedrock_base_url(self.endpoint, region)
else:
raise OpenAIError(
"Bedrock requires an AWS region. Pass `region` to `bedrock(...)`, or set `AWS_REGION` or "
"`AWS_DEFAULT_REGION`."
)
if bearer_provider is not None:
auth = _BedrockBearerAuth(bearer_provider, base_url=base_url)
assert auth is not None
if isinstance(auth, _BedrockSigV4Auth):
return _BedrockProviderRuntime(
name=self.name,
base_url=base_url,
region=region,
transform_request=_without_redirects,
prepare_request=auth.prepare_request,
prepare_async_request=auth.prepare_async_request,
)
View on GitHub (pinned to 9917c6e28e)
Solutions
- Pass region="us-east-1" (etc.) to bedrock(...).
- Export AWS_REGION or AWS_DEFAULT_REGION.
- Alternatively supply a full base_url, which removes the need for a region to derive the hostname.
Example fix
# before provider = bedrock() # after provider = bedrock(region="us-east-1") # or export AWS_REGION=us-east-1
Defensive patterns
Strategy: validation
Validate before calling
import os
region = region or os.environ.get("AWS_REGION") or os.environ.get("AWS_DEFAULT_REGION")
assert region or base_url, "Bedrock needs region or base_url" Type guard
def bedrock_region_resolved(region: str | None, base_url: str | None) -> bool:
import os
return bool(base_url or region or os.environ.get("AWS_REGION") or os.environ.get("AWS_DEFAULT_REGION")) Try / catch
try:
provider = bedrock()
except OpenAIError as e:
if "requires an AWS region" in str(e):
provider = bedrock(region="us-east-1")
else:
raise Prevention
- Always pass region explicitly in application code rather than relying on ambient env.
- Set AWS_REGION in Dockerfiles/CI templates.
- Include provider construction in smoke tests.
When it happens
Trigger: Calling bedrock() with neither region nor base_url while AWS_REGION and AWS_DEFAULT_REGION are both unset; or configuring only bearer credentials without a region.
Common situations: Fresh environments without AWS CLI configuration; containers/CI with no AWS env; ~/.aws/config missing a default region.
Related errors
- The Bedrock AWS `region` is invalid. Use a standard AWS regi
- The Bedrock endpoint region `{canonical_region}` does not ma
- Could not find credentials for Bedrock. Set `AWS_BEARER_TOKE
- Pass refreshable Bedrock credentials via `bedrock_token_prov
- The Bedrock {canonical_family} hostname does not match the s
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/117dc96f65b0a79c.
Report an issue: GitHub.