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
25 changes: 25 additions & 0 deletions agent/anthropic_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ def build_anthropic_bedrock_client(region: str):
serves them with 1M natively.

Auth uses the boto3 default credential chain (IAM roles, SSO, env vars).
When AWS_BEARER_TOKEN_BEDROCK and ANTHROPIC_BEDROCK_BASE_URL are set,
uses bearer token auth with a custom base URL instead of SigV4.
"""
_anthropic_sdk = _get_anthropic_sdk()
if _anthropic_sdk is None:
Expand All @@ -788,6 +790,29 @@ def build_anthropic_bedrock_client(region: str):
)
from httpx import Timeout

bearer_token = os.environ.get("AWS_BEARER_TOKEN_BEDROCK", "").strip()
custom_base_url = os.environ.get("ANTHROPIC_BEDROCK_BASE_URL", "").strip()

if bearer_token and custom_base_url:
class _BearerBedrockClient(_anthropic_sdk.AnthropicBedrock):
"""AnthropicBedrock subclass that uses Bearer token instead of SigV4."""
def __init__(self, _bearer_token, **kwargs):
self._bearer_token = _bearer_token
super().__init__(**kwargs)

def _prepare_request(self, request) -> None:
request.headers["Authorization"] = f"Bearer {self._bearer_token}"

return _BearerBedrockClient(
bearer_token,
aws_region=region,
aws_access_key="unused",
aws_secret_key="unused",
base_url=custom_base_url,
timeout=Timeout(timeout=900.0, connect=10.0),
default_headers={"anthropic-beta": ",".join([*_COMMON_BETAS, _CONTEXT_1M_BETA])},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pass max_retries=0 here as well. Current main disables Anthropic SDK retries for the normal Bedrock client (agent/anthropic_adapter.py:865-867) so Hermes's outer retry loop remains authoritative; the bearer branch otherwise regresses that invariant.

)

return _anthropic_sdk.AnthropicBedrock(
aws_region=region,
timeout=Timeout(timeout=900.0, connect=10.0),
Expand Down
3 changes: 2 additions & 1 deletion agent/bedrock_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,15 @@ def is_anthropic_bedrock_model(model_id: str) -> bool:
- ``us.anthropic.claude-*`` (US inference profiles)
- ``global.anthropic.claude-*`` (global inference profiles)
- ``eu.anthropic.claude-*`` (EU inference profiles)
- ``claude-*`` (Anthropic native model names via proxies)
"""
model_lower = model_id.lower()
# Strip regional prefix if present
for prefix in ("us.", "global.", "eu.", "ap.", "jp."):
if model_lower.startswith(prefix):
model_lower = model_lower[len(prefix):]
break
return model_lower.startswith("anthropic.claude")
return model_lower.startswith("anthropic.claude") or model_lower.startswith("claude")


# ---------------------------------------------------------------------------
Expand Down