NousResearch/hermes-agent · error · ImportError

The 'anthropic' package is required for the Anthropic provid

Error message

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

What it means

ImportError raised by the main Anthropic client builder: _get_anthropic_sdk() is None, so the optional 'anthropic' dependency is missing from the runtime environment. Every path that builds a native Anthropic client — static API key or the callable Entra bearer variant — hits this guard before any SDK object is constructed.

Source

Thrown at agent/anthropic_adapter.py:825

      header. The SDK never sees the callable directly.

    If *timeout* is provided it overrides the default 900s read timeout.  The
    connect timeout stays at 10s.  Callers pass this from the per-provider /
    per-model ``request_timeout_seconds`` config so Anthropic-native and
    Anthropic-compatible providers respect the same knob as OpenAI-wire
    providers.

    ``drop_context_1m_beta=True`` strips ``context-1m-2025-08-07`` from the
    client-level ``anthropic-beta`` header. Used by the reactive OAuth retry
    path in ``run_agent.py`` when a subscription rejects the beta; leave at
    its default on fresh clients so 1M-capable subscriptions keep the
    capability.

    Returns an anthropic.Anthropic instance.
    """
    _anthropic_sdk = _get_anthropic_sdk()
    if _anthropic_sdk is None:
        raise ImportError(
            "The 'anthropic' package is required for the Anthropic provider. "
            "Install it with: pip install 'anthropic>=0.39.0'"
        )

    # Callable api_key → Entra ID bearer provider path. Delegated to a
    # helper so the existing static-key code below stays unchanged.
    if callable(api_key) and not isinstance(api_key, str):
        return _build_anthropic_client_with_bearer_hook(
            api_key, base_url, timeout,
            drop_context_1m_beta=drop_context_1m_beta,
        )

    normalize_proxy_env_vars()

    from httpx import Timeout

    normalized_base_url = _normalize_base_url_text(base_url)
    if normalized_base_url:

View on GitHub (pinned to c896c09c42)

Solutions

  1. pip install 'anthropic>=0.39.0' into the environment hermes runs in
  2. Confirm with: python -c "import anthropic; print(anthropic.__version__)"
  3. Recreate/sync the venv (uv sync) if the install is broken

Example fix

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

Strategy: validation

Validate before calling

def anthropic_sdk_available() -> bool:
    try:
        import anthropic  # noqa: F401
        return True
    except ImportError:
        return False

if provider == "anthropic" and not anthropic_sdk_available():
    raise SystemExit("pip install 'anthropic>=0.39.0' before selecting the anthropic provider")

Try / catch

try:
    client = build_anthropic_client(api_key=key, base_url=url)
except ImportError as e:
    if "anthropic" in str(e):
        install_and_prompt("pip install 'anthropic>=0.39.0'")
    raise

Prevention

When it happens

Trigger: Selecting the anthropic provider (or any code path that calls this builder) on an environment where `import anthropic` fails: package not installed, broken install, or interpreter mismatch.

Common situations: Fresh checkout without optional extras installed; venv rebuilt; dependency conflict removed anthropic; running under system Python while the package lives in the project venv.

Related errors


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