NousResearch/hermes-agent · error · ImportError

The 'anthropic' package is required for the Bedrock provider

Error message

The 'anthropic' package is required for the Bedrock provider. Install it with: pip install 'anthropic>=0.39.0'

What it means

ImportError raised when building the Bedrock client: _get_anthropic_sdk() returned None, i.e. the optional 'anthropic' package is not installed. Bedrock-hosted Claude requires the SDK client (AnthropicBedrock) with boto3's default credential chain, hence the explicit install instruction.

Source

Thrown at agent/anthropic_adapter.py:963

def build_anthropic_bedrock_client(region: str):
    """Create an AnthropicBedrock client for Bedrock Claude models.

    Uses the Anthropic SDK's native Bedrock adapter, which provides full
    Claude feature parity: prompt caching, thinking budgets, adaptive
    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])},
    )

View on GitHub (pinned to c896c09c42)

Solutions

  1. pip install 'anthropic>=0.39.0' in hermes' environment
  2. Verify importability: python -c "import anthropic"
  3. Ensure boto3 credentials (IAM role/SSO/env) are also configured for the Bedrock path

Example fix

# before: bedrock provider selected, ImportError raised
# after
pip install 'anthropic>=0.39.0'
Defensive patterns

Strategy: validation

Validate before calling

def bedrock_ready() -> bool:
    try:
        import anthropic
    except ImportError:
        return False
    return hasattr(anthropic, "AnthropicBedrock")

if provider == "bedrock" and not bedrock_ready():
    raise SystemExit("pip install 'anthropic>=0.39.0' before using the bedrock provider")

Try / catch

try:
    client = build_bedrock_client(region=region)
except ImportError as e:
    if "Bedrock" in str(e) or "anthropic" in str(e):
        run_or_suggest("pip install 'anthropic>=0.39.0'")
    raise

Prevention

When it happens

Trigger: Selecting the bedrock provider and constructing its client on an environment where `import anthropic` fails (absent or broken install).

Common situations: Bedrock configured on a machine where only boto3 was installed; slim/hermetic install; venv recreated without the anthropic extra.

Related errors


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