NousResearch/hermes-agent · error · ImportError

anthropic.AnthropicBedrock not available. Upgrade with: pip

Error message

anthropic.AnthropicBedrock not available. Upgrade with: pip install 'anthropic>=0.39.0'

What it means

Distinct from a missing package: `anthropic` IS importable but exposes no AnthropicBedrock attribute, meaning the installed version predates the Bedrock client class. The remediation is an upgrade, not an install — the version floor (>=0.39.0) is where AnthropicBedrock with the required constructor surface exists.

Source

Thrown at agent/anthropic_adapter.py:968

    thinking, fast mode — features not available via the Converse API.

    Attaches the common Anthropic beta headers as client-level defaults so
    that Bedrock-hosted Claude models get the same enhanced features as
    native Anthropic. The ``context-1m-2025-08-07`` beta in particular
    unlocks the 1M context window for Opus 4.6/4.7 on Bedrock — without
    it, Bedrock caps these models at 200K even though the Anthropic API
    serves them with 1M natively.

    Auth uses the boto3 default credential chain (IAM roles, SSO, env vars).
    """
    _anthropic_sdk = _get_anthropic_sdk()
    if _anthropic_sdk is None:
        raise ImportError(
            "The 'anthropic' package is required for the Bedrock provider. "
            "Install it with: pip install 'anthropic>=0.39.0'"
        )
    if not hasattr(_anthropic_sdk, "AnthropicBedrock"):
        raise ImportError(
            "anthropic.AnthropicBedrock not available. "
            "Upgrade with: pip install 'anthropic>=0.39.0'"
        )
    from httpx import Timeout

    return _anthropic_sdk.AnthropicBedrock(
        aws_region=region,
        timeout=Timeout(timeout=900.0, connect=10.0),
        # Delegate retry to hermes's outer loop (honors Retry-After); the SDK
        # default max_retries=2 ignores it and double-retries. (#26293)
        max_retries=0,
        default_headers={"anthropic-beta": ",".join([*_COMMON_BETAS, _CONTEXT_1M_BETA])},
    )


def _read_claude_code_credentials_from_keychain() -> Optional[Dict[str, Any]]:
    """Read Claude Code OAuth credentials from the macOS Keychain.

View on GitHub (pinned to c896c09c42)

Solutions

  1. Upgrade: pip install --upgrade 'anthropic>=0.39.0'
  2. Verify the class exists: python -c "from anthropic import AnthropicBedrock"
  3. If a conflicting pin holds it back, inspect pip's resolution and relax the conflicting constraint

Example fix

# before: anthropic 0.30.x installed, AnthropicBedrock missing
# after
pip install --upgrade 'anthropic>=0.39.0'
python -c "from anthropic import AnthropicBedrock; print('ok')"
Defensive patterns

Strategy: validation

Validate before calling

import anthropic
from packaging.version import parse

def bedrock_client_available() -> tuple[bool, str]:
    if not hasattr(anthropic, "AnthropicBedrock"):
        return False, f"anthropic {anthropic.__version__} lacks AnthropicBedrock; upgrade to >=0.39.0"
    return True, ""

ok, why = bedrock_client_available()
if not ok:
    raise SystemExit(why)

Type guard

def has_anthropic_bedrock(sdk) -> bool:
    """True when the imported anthropic SDK exposes AnthropicBedrock."""
    return hasattr(sdk, "AnthropicBedrock")

Try / catch

try:
    client = build_bedrock_client(region=region)
except ImportError as e:
    if "AnthropicBedrock not available" in str(e):
        upgrade_and_restart("pip install --upgrade 'anthropic>=0.39.0'")
    else:
        raise

Prevention

When it happens

Trigger: Bedrock provider client construction on an environment with an old anthropic package: `import anthropic` succeeds but hasattr(anthropic, 'AnthropicBedrock') is False.

Common situations: Long-lived venv with anthropic pinned low; system package shadowing the venv's newer copy; dependency resolver kept an old version to satisfy another constraint.

Related errors


AI-assisted analysis of NousResearch/hermes-agent@c896c09c42 (2026-08-14). Data as JSON: /api/errors/4285a3fdb35dbc26. Report an issue: GitHub.