hermes - 💡(How to fix) Fix [Bug]: Azure Foundry provider sends x-api-key instead of Bearer auth for anthropic_messages endpoints (HTTP 401)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  1. Observe HTTP 401 with "Auth method: x-api-key" in the error output Every request fails with HTTP 401. Error output shows "Auth method: x-api-key (API key)" confirming the SDK sends the key via x-api-key header instead of Authorization: Bearer. Azure rejects this with "Access denied due to invalid subscription key or wrong API endpoint."

Additional Logs / Traceback (optional)

Root Cause

Root cause: build_anthropic_client() in agent/anthropic_adapter.py routes Azure endpoints through the _is_third_party_anthropic_endpoint branch (line ~596), which sets kwargs["api_key"] — causing the SDK to send x-api-key. Azure should either be added to _requires_bearer_auth() (which currently only covers MiniMax) or use the AnthropicFoundry client class from the SDK.

Fix Action

Fix / Workaround

Workaround: Use provider: anthropic with direct Anthropic API key instead of Azure Foundry.

Code Example

hermes config set model.provider azure-foundry
   hermes config set model.default claude-opus-4-6
   hermes config set model.base_url https://<resource>.openai.azure.com/anthropic
   hermes config set model.api_mode anthropic_messages

---

Report     https://paste.rs/EzYjh
  agent.log  https://paste.rs/SjE3i

---

Key code path in agent/anthropic_adapter.py:

_is_third_party_anthropic_endpoint() returns True for Azure URLs (line ~364)
build_anthropic_client() routes Azure into the third-party branch (line ~596):
    kwargs["api_key"] = api_key  # sends x-api-key header

Azure portal code samples show Authorization: Bearer is required.
AnthropicFoundry SDK class also uses Bearer auth.

Fix suggestion: Add Azure to _requires_bearer_auth() (line ~470):
    return normalized.startswith((...)) or "azure.com" in normalized
RAW_BUFFERClick to expand / collapse

Bug Description

When using provider: azure-foundry with api_mode: anthropic_messages, Hermes sends the API key via the x-api-key header. However, Azure AI Foundry's Anthropic-style endpoint (https://<resource>.openai.azure.com/anthropic) requires Authorization: Bearer authentication, as documented in Azure's portal code samples and used by the AnthropicFoundry SDK class.

This causes every request to fail with HTTP 401:

Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.

The same API key and endpoint work correctly when using:

  • curl with Authorization: Bearer header
  • The AnthropicFoundry Python SDK class
  • Direct Anthropic API (provider: anthropic) with the same Hermes installation

Root cause: build_anthropic_client() in agent/anthropic_adapter.py routes Azure endpoints through the _is_third_party_anthropic_endpoint branch (line ~596), which sets kwargs["api_key"] — causing the SDK to send x-api-key. Azure should either be added to _requires_bearer_auth() (which currently only covers MiniMax) or use the AnthropicFoundry client class from the SDK.

Workaround: Use provider: anthropic with direct Anthropic API key instead of Azure Foundry.

Steps to Reproduce

  1. Deploy Claude models (Opus 4.6, Sonnet 4.6, Haiku 4.5) on Azure AI Foundry (AIServices kind, S0 SKU)
  2. Configure Hermes:
   hermes config set model.provider azure-foundry
   hermes config set model.default claude-opus-4-6
   hermes config set model.base_url https://<resource>.openai.azure.com/anthropic
   hermes config set model.api_mode anthropic_messages
  1. Set AZURE_FOUNDRY_API_KEY in ~/.hermes/.env
  2. Run hermes chat "Hello"
  3. Observe HTTP 401 with "Auth method: x-api-key" in the error output

Expected Behavior

Hermes should authenticate with Authorization: Bearer <key> for Azure Foundry Anthropic-style endpoints, matching the behavior of Azure's own portal code samples and the AnthropicFoundry SDK class.

Actual Behavior

Every request fails with HTTP 401. Error output shows "Auth method: x-api-key (API key)" confirming the SDK sends the key via x-api-key header instead of Authorization: Bearer. Azure rejects this with "Access denied due to invalid subscription key or wrong API endpoint."

Affected Component

Agent Core (conversation loop, context compression, memory)

Messaging Platform (if gateway-related)

No response

Debug Report

Report     https://paste.rs/EzYjh
  agent.log  https://paste.rs/SjE3i

Operating System

Ubuntu 24.04 LTS

Python Version

Python 3.12.3

Hermes Version

Hermes Agent v0.14.0 (2026.5.16)

Additional Logs / Traceback (optional)

Key code path in agent/anthropic_adapter.py:

_is_third_party_anthropic_endpoint() returns True for Azure URLs (line ~364)
build_anthropic_client() routes Azure into the third-party branch (line ~596):
    kwargs["api_key"] = api_key  # sends x-api-key header

Azure portal code samples show Authorization: Bearer is required.
AnthropicFoundry SDK class also uses Bearer auth.

Fix suggestion: Add Azure to _requires_bearer_auth() (line ~470):
    return normalized.startswith((...)) or "azure.com" in normalized

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [Bug]: Azure Foundry provider sends x-api-key instead of Bearer auth for anthropic_messages endpoints (HTTP 401)