{"record":{"id":"9bca01d965d9dabe","repo":"NousResearch/hermes-agent","slug":"the-anthropic-package-is-required-for-azure-foun","errorCode":null,"errorMessage":"The 'anthropic' package is required for Azure Foundry Anthropic-style endpoints with Entra ID auth. Install with: pip install 'anthropic>=0.39.0'","messagePattern":"The 'anthropic' package is required for Azure Foundry Anthropic-style endpoints with Entra ID auth\\. Install with: pip install 'anthropic>=0\\.39\\.0'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"agent/anthropic_adapter.py","lineNumber":734,"sourceCode":"    \"\"\"Anthropic-on-Foundry Entra ID variant of :func:`build_anthropic_client`.\n\n    Anthropic SDK 0.86.0 stores ``api_key`` / ``auth_token`` as static\n    strings; there is no callable-token contract. To get per-request\n    bearer refresh (Microsoft's documented Foundry pattern), we hand\n    the SDK a custom ``httpx.Client`` whose request event hook mints a\n    fresh JWT from the Entra credential chain and rewrites\n    ``Authorization: Bearer <jwt>`` on every outbound request. The SDK\n    ignores its own auth logic when ``http_client`` is provided (the\n    hook strips any pre-set Authorization).\n\n    The placeholder ``auth_token`` is required because the SDK raises\n    ``AnthropicError`` at construction if neither ``api_key`` nor\n    ``auth_token`` is set — but the hook overrides it per-request so\n    the placeholder value never reaches Azure.\n    \"\"\"\n    _anthropic_sdk = _get_anthropic_sdk()\n    if _anthropic_sdk is None:\n        raise ImportError(\n            \"The 'anthropic' package is required for Azure Foundry Anthropic-style \"\n            \"endpoints with Entra ID auth. Install with: pip install 'anthropic>=0.39.0'\"\n        )\n\n    normalize_proxy_env_vars()\n\n    from httpx import Timeout\n    from agent.azure_identity_adapter import build_bearer_http_client\n\n    _read_timeout = timeout if (isinstance(timeout, (int, float)) and timeout > 0) else 900.0\n    timeout_obj = Timeout(timeout=float(_read_timeout), connect=10.0)\n\n    # Strip any trailing /v1 — the Anthropic SDK appends /v1/messages.\n    normalized_base_url = _normalize_base_url_text(base_url)\n    if normalized_base_url:\n        import re as _re\n        normalized_base_url = _re.sub(r\"/v1/?$\", \"\", normalized_base_url.rstrip(\"/\"))\n","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/agent/anthropic_adapter.py#L716-L752","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install it in hermes' venv: pip install 'anthropic>=0.39.0'","Verify: python -c \"import anthropic; print(anthropic.__version__)\"","If it should already be present, check for a conflicting site-packages or wrong interpreter (which python)"],"exampleFix":"# before: ImportError at client build\npip install 'anthropic>=0.39.0'\n\n# after\npython -c \"import anthropic; print(anthropic.__version__)\"  # >= 0.39.0","handlingStrategy":"validation","validationCode":"def anthropic_sdk_available() -> bool:\n    try:\n        import anthropic  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\n# before configuring azure-foundry with Entra ID:\nif entra_auth and not anthropic_sdk_available():\n    raise SystemExit(\"pip install 'anthropic>=0.39.0' before using Entra ID auth\")","typeGuard":null,"tryCatchPattern":"try:\n    client = _build_anthropic_client_with_bearer_hook(...)\nexcept ImportError as e:\n    if \"anthropic\" in str(e):\n        subprocess.run([sys.executable, \"-m\", \"pip\", \"install\", \"anthropic>=0.39.0\"], check=True)\n        client = _build_anthropic_client_with_bearer_hook(...)  # retry once\n    else:\n        raise","preventionTips":["Install the anthropic extra whenever Azure Foundry/Entra or native Anthropic is in the config","Add a dependency preflight to deployment scripts for setups using Anthropic-style endpoints","Pin anthropic >=0.39.0 in the environment spec, not ad hoc"],"tags":["anthropic","azure","entra-id","dependency"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}