NousResearch/hermes-agent · error · ImportError

The 'anthropic' package is required for Azure Foundry Anthro

Error message

The 'anthropic' package is required for Azure Foundry Anthropic-style endpoints with Entra ID auth. Install with: pip install 'anthropic>=0.39.0'

What it means

ImportError raised when building an Azure Foundry Anthropic-style client with Entra ID bearer auth: _get_anthropic_sdk() returned None, meaning the optional 'anthropic' package is not importable in this environment. The >=0.39.0 floor exists because the Entra bearer http_client hook depends on SDK behavior from that version onward.

Source

Thrown at agent/anthropic_adapter.py:734

    """Anthropic-on-Foundry Entra ID variant of :func:`build_anthropic_client`.

    Anthropic SDK 0.86.0 stores ``api_key`` / ``auth_token`` as static
    strings; there is no callable-token contract. To get per-request
    bearer refresh (Microsoft's documented Foundry pattern), we hand
    the SDK a custom ``httpx.Client`` whose request event hook mints a
    fresh JWT from the Entra credential chain and rewrites
    ``Authorization: Bearer <jwt>`` on every outbound request. The SDK
    ignores its own auth logic when ``http_client`` is provided (the
    hook strips any pre-set Authorization).

    The placeholder ``auth_token`` is required because the SDK raises
    ``AnthropicError`` at construction if neither ``api_key`` nor
    ``auth_token`` is set — but the hook overrides it per-request so
    the placeholder value never reaches Azure.
    """
    _anthropic_sdk = _get_anthropic_sdk()
    if _anthropic_sdk is None:
        raise ImportError(
            "The 'anthropic' package is required for Azure Foundry Anthropic-style "
            "endpoints with Entra ID auth. Install with: pip install 'anthropic>=0.39.0'"
        )

    normalize_proxy_env_vars()

    from httpx import Timeout
    from agent.azure_identity_adapter import build_bearer_http_client

    _read_timeout = timeout if (isinstance(timeout, (int, float)) and timeout > 0) else 900.0
    timeout_obj = Timeout(timeout=float(_read_timeout), connect=10.0)

    # Strip any trailing /v1 — the Anthropic SDK appends /v1/messages.
    normalized_base_url = _normalize_base_url_text(base_url)
    if normalized_base_url:
        import re as _re
        normalized_base_url = _re.sub(r"/v1/?$", "", normalized_base_url.rstrip("/"))

View on GitHub (pinned to c896c09c42)

Solutions

  1. Install it in hermes' venv: pip install 'anthropic>=0.39.0'
  2. Verify: python -c "import anthropic; print(anthropic.__version__)"
  3. If it should already be present, check for a conflicting site-packages or wrong interpreter (which python)

Example fix

# before: ImportError at client build
pip install 'anthropic>=0.39.0'

# after
python -c "import anthropic; print(anthropic.__version__)"  # >= 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

# before configuring azure-foundry with Entra ID:
if entra_auth and not anthropic_sdk_available():
    raise SystemExit("pip install 'anthropic>=0.39.0' before using Entra ID auth")

Try / catch

try:
    client = _build_anthropic_client_with_bearer_hook(...)
except ImportError as e:
    if "anthropic" in str(e):
        subprocess.run([sys.executable, "-m", "pip", "install", "anthropic>=0.39.0"], check=True)
        client = _build_anthropic_client_with_bearer_hook(...)  # retry once
    else:
        raise

Prevention

When it happens

Trigger: Configuring an azure-foundry Anthropic-style endpoint with Entra ID auth (callable api_key) and invoking the bearer-hook client builder while `import anthropic` fails — package absent, broken install, or wrong interpreter.

Common situations: Slim install without the anthropic extra; virtualenv recreated without optional deps; pip dependency resolution uninstalled anthropic; running under a different Python than the one with the package.

Related errors


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