Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/anthropic/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,16 @@ def deepcopy_minimal(item: _T) -> _T:

- mappings, e.g. `dict`
- list
- tuple (recursively copies contents)

This is done for performance reasons.
"""
if is_mapping(item):
return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()})
if is_list(item):
return cast(_T, [deepcopy_minimal(entry) for entry in item])
if isinstance(item, tuple):
return cast(_T, tuple(deepcopy_minimal(entry) for entry in item))
return item


Expand Down
16 changes: 11 additions & 5 deletions src/anthropic/lib/bedrock/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ def _prepare_options(input_options: FinalRequestOptions) -> FinalRequestOptions:
def _infer_region() -> str:
"""
Infer the AWS region from the environment variables or
from the boto3 session if available.
from the boto3 client if available.
"""
aws_region = os.environ.get("AWS_REGION")
if aws_region is None:
try:
import boto3

session = boto3.Session()
if session.region_name:
aws_region = session.region_name
import botocore.exceptions

# Use boto3 client to properly detect region from config/profile
try:
aws_region = boto3.client("bedrock").meta.region_name
except botocore.exceptions.NoRegionError:
# Fall back to session-based detection
session = boto3.Session()
if session.region_name:
aws_region = session.region_name
except ImportError:
pass

Expand Down