Skip to content

fix(auth): send Bearer auth for Azure Foundry anthropic_messages endpoints#27022

Closed
sharziki wants to merge 1 commit into
NousResearch:mainfrom
sharziki:fix/azure-foundry-bearer-auth
Closed

fix(auth): send Bearer auth for Azure Foundry anthropic_messages endpoints#27022
sharziki wants to merge 1 commit into
NousResearch:mainfrom
sharziki:fix/azure-foundry-bearer-auth

Conversation

@sharziki

Copy link
Copy Markdown
Contributor

Summary

  • Add azure.com to _requires_bearer_auth() so Azure AI Foundry's Anthropic-style endpoint gets Authorization: Bearer instead of x-api-key
  • The _requires_bearer_auth() check fires before the generic _is_third_party_anthropic_endpoint() branch, so Azure endpoints now take the Bearer path

Root cause

build_anthropic_client() checks _requires_bearer_auth() first (line 586), then falls through to _is_third_party_anthropic_endpoint() (line 596) which sets kwargs["api_key"] (x-api-key header). Azure endpoints matched the latter but not the former, resulting in HTTP 401.

Fixes #26970

…oints

Azure AI Foundry's Anthropic-style endpoint requires
`Authorization: Bearer` instead of `x-api-key`.  Add `azure.com` to
`_requires_bearer_auth()` so the existing Bearer path at line 586 fires
before the generic third-party branch sets `api_key` (x-api-key).

Fixes #26970
@cardtest15-coder

This comment was marked as spam.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder provider/anthropic Anthropic native Messages API area/auth Authentication, OAuth, credential pools P3 Low — cosmetic, nice to have labels May 16, 2026
teknium1 added a commit that referenced this pull request May 18, 2026
Cherry-pick of @sharziki's #27022 routed Azure Foundry through
_requires_bearer_auth, which also triggered the MiniMax-specific
beta-strip in _common_betas_for_base_url — dropping the 1M-context
beta from Azure even though Azure needs it for 1M context.

Split the strip predicate: introduce _is_minimax_anthropic_endpoint
so the fine-grained-tool-streaming and context-1m strips only fire
for MiniMax hosts, leaving Azure's bearer-auth header swap intact
without losing 1M context.

Also add a regression test that asserts Azure gets Bearer auth,
the api-version query param, and the context-1m-2025-08-07 beta.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #28084. Your commit was cherry-picked onto current main with your authorship preserved in git log (commit 73407b1). We also pushed a small follow-up on top to keep the 1M-context beta active for Azure Foundry — _requires_bearer_auth matching azure.com was folding Azure into MiniMax's beta-strip branch, which would have silently dropped context-1m-2025-08-07. The strip is now scoped to MiniMax-only via a new _is_minimax_anthropic_endpoint predicate.

Thanks for the fix!

Lillard01 pushed a commit to Lillard01/hermes-agent that referenced this pull request May 21, 2026
Cherry-pick of @sharziki's NousResearch#27022 routed Azure Foundry through
_requires_bearer_auth, which also triggered the MiniMax-specific
beta-strip in _common_betas_for_base_url — dropping the 1M-context
beta from Azure even though Azure needs it for 1M context.

Split the strip predicate: introduce _is_minimax_anthropic_endpoint
so the fine-grained-tool-streaming and context-1m strips only fire
for MiniMax hosts, leaving Azure's bearer-auth header swap intact
without losing 1M context.

Also add a regression test that asserts Azure gets Bearer auth,
the api-version query param, and the context-1m-2025-08-07 beta.
Mucky010 pushed a commit to Mucky010/hermes-agent that referenced this pull request May 24, 2026
Cherry-pick of @sharziki's NousResearch#27022 routed Azure Foundry through
_requires_bearer_auth, which also triggered the MiniMax-specific
beta-strip in _common_betas_for_base_url — dropping the 1M-context
beta from Azure even though Azure needs it for 1M context.

Split the strip predicate: introduce _is_minimax_anthropic_endpoint
so the fine-grained-tool-streaming and context-1m strips only fire
for MiniMax hosts, leaving Azure's bearer-auth header swap intact
without losing 1M context.

Also add a regression test that asserts Azure gets Bearer auth,
the api-version query param, and the context-1m-2025-08-07 beta.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Cherry-pick of @sharziki's NousResearch#27022 routed Azure Foundry through
_requires_bearer_auth, which also triggered the MiniMax-specific
beta-strip in _common_betas_for_base_url — dropping the 1M-context
beta from Azure even though Azure needs it for 1M context.

Split the strip predicate: introduce _is_minimax_anthropic_endpoint
so the fine-grained-tool-streaming and context-1m strips only fire
for MiniMax hosts, leaving Azure's bearer-auth header swap intact
without losing 1M context.

Also add a regression test that asserts Azure gets Bearer auth,
the api-version query param, and the context-1m-2025-08-07 beta.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent loop, run_agent.py, prompt builder P3 Low — cosmetic, nice to have provider/anthropic Anthropic native Messages API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Azure Foundry provider sends x-api-key instead of Bearer auth for anthropic_messages endpoints (HTTP 401)

4 participants