BerriAI/litellm · error · BedrockError

AWS region not set: set AWS_REGION_NAME or AWS_REGION env va

Error message

AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file

What it means

Raised during Bedrock client initialization when no AWS region can be resolved: litellm checks the region_name argument, the aws_region_name litellm param, litellm.api_region_name / module-level AWS region name, and the standard AWS_REGION/AWS_DEFAULT_REGION environment variables; if all are empty it raises BedrockError 401 with this fixed message.

Source

Thrown at litellm/llms/bedrock/common_utils.py:446

        aws_session_name,
        aws_profile_name,
        aws_role_name,
        aws_web_identity_token,
    ) = params_to_check

    ssl_verify: Final = _get_bedrock_client_ssl_verify()

    ### SET REGION NAME
    if region_name:
        pass
    elif aws_region_name:
        region_name = aws_region_name
    elif litellm_aws_region_name:
        region_name = litellm_aws_region_name
    elif standard_aws_region_name:
        region_name = standard_aws_region_name
    else:
        raise BedrockError(
            message="AWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env file",
            status_code=401,
        )

    # check for custom AWS_BEDROCK_RUNTIME_ENDPOINT and use it if not passed to init_bedrock_client
    env_aws_bedrock_runtime_endpoint: Final = get_secret("AWS_BEDROCK_RUNTIME_ENDPOINT")
    if aws_bedrock_runtime_endpoint:
        endpoint_url = aws_bedrock_runtime_endpoint
    elif env_aws_bedrock_runtime_endpoint:
        endpoint_url = env_aws_bedrock_runtime_endpoint
    else:
        endpoint_url = f"https://bedrock-runtime.{region_name}.amazonaws.com"

    import boto3

    if isinstance(timeout, float):
        config = boto3.session.Config(connect_timeout=timeout, read_timeout=timeout)
    elif isinstance(timeout, httpx.Timeout):

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set AWS_REGION_NAME or AWS_REGION (e.g. export AWS_REGION=us-east-1) in the runtime environment or .env file.
  2. Or pass the region per call/deployment: litellm.completion(..., aws_region_name="us-east-1") / router model_list entry with aws_region_name.
  3. Add the region to docker-compose / Kubernetes env for the litellm proxy or SDK container.
  4. If relying on an AWS profile, also export AWS_DEFAULT_REGION since profile-only config may not be picked up on this path.

Example fix

# before
litellm.completion(model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0", messages=msgs)  # no region anywhere

# after - option 1: env
import os; os.environ["AWS_REGION_NAME"] = "us-east-1"
# option 2: per call
litellm.completion(model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0", messages=msgs, aws_region_name="us-east-1")
Defensive patterns

Strategy: validation

Validate before calling

import os
region = (
    os.environ.get("AWS_REGION_NAME")
    or os.environ.get("AWS_REGION")
    or os.environ.get("AWS_DEFAULT_REGION")
)
if not region:
    raise RuntimeError("Set AWS_REGION_NAME or AWS_REGION before any bedrock/ call")

Type guard

def bedrock_region_configured() -> bool:
    import os
    return bool(os.environ.get("AWS_REGION_NAME") or os.environ.get("AWS_REGION") or os.environ.get("AWS_DEFAULT_REGION"))

Try / catch

from litellm.exceptions import BedrockError
try:
    litellm.completion(model="bedrock/<model>", messages=msgs)
except BedrockError as e:
    if e.status_code == 401 and "AWS region not set" in str(e):
        raise RuntimeError("Deploy config: export AWS_REGION_NAME=us-east-1") from e
    raise

Prevention

When it happens

Trigger: Constructing any bedrock/ completion (client init path in common_utils.py) without AWS_REGION_NAME / AWS_REGION / AWS_DEFAULT_REGION set in the environment and without passing aws_region_name to the call or router deployment.

Common situations: Fresh containers/CI where AWS credentials are mounted but region env vars are not, deployments that rely only on an AWS profile file (this path reads env vars, not ~/.aws/config), or code that works locally (region set in shell) and fails in production.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/9776b89569269772. Report an issue: GitHub.