Skip to content

fix: Azure AI Foundry / Azure Anthropic endpoint compatibility#4599

Closed
HangGlidersRule wants to merge 5 commits into
NousResearch:mainfrom
HangGlidersRule:fix/azure-anthropic-endpoint
Closed

fix: Azure AI Foundry / Azure Anthropic endpoint compatibility#4599
HangGlidersRule wants to merge 5 commits into
NousResearch:mainfrom
HangGlidersRule:fix/azure-anthropic-endpoint

Conversation

@HangGlidersRule

Copy link
Copy Markdown
Contributor

Problem

Hermes is completely broken when configured to use Azure AI Foundry's Anthropic-compatible endpoint. Multiple overlapping bugs cause every request to fail with HTTP 404 or HTTP 401.

Root Causes (5 bugs, fixed in order of discovery)

1. Azure AI Foundry keys misidentified as OAuth tokens

_is_oauth_token() in runtime_provider.py only excluded sk-ant-api prefix keys, treating Azure keys (which don't start with sk-ant- at all) as OAuth tokens → wrong auth header sent.

2. OAuth token priority chain overrides Azure key

resolve_anthropic_token() checks ~/.claude/.credentials.json at priority 3, before ANTHROPIC_API_KEY at priority 4. If the user has Claude Code installed, the OAuth token wins every time, regardless of what's in the environment.

3. _resolve_named_custom_runtime intercepts the anthropic provider

When requested="anthropic" + an Azure base_url is passed, the custom runtime resolver intercepts it and returns provider="custom" with no api_mode set → falls through to chat_completions path.

4. _try_refresh_anthropic_client_credentials overwrites Azure key mid-session

Called before every request. Finds the OAuth token in ~/.claude/.credentials.json, sees it differs from the Azure key, and swaps it in → correct Azure key gets silently replaced on message 2+.

5. api-version appended to base_url produces malformed URLs

Previous fix attempt added api-version=2025-04-15 directly to the base URL string. The Anthropic SDK then appended /v1/messages to that, producing:

.../anthropic?api-version=2025-04-15/v1/messages

instead of:

.../anthropic/v1/messages?api-version=2025-04-15

Azure returns 404 on the malformed path.

Fixes

Commit Fix
3125ea6f Non-sk-ant- keys are regular API keys, not OAuth tokens
896d8157 Use AZURE_ANTHROPIC_KEY/ANTHROPIC_API_KEY directly for Azure endpoints
ad3fcf3b Short-circuit custom runtime resolver for provider=anthropic + Azure URL
f3640168 Skip OAuth credential refresh for Azure endpoints in run_agent.py
7c00e15a Pass api-version via default_query, not baked into base_url

Configuration

After this fix, Azure AI Foundry works with the following config.yaml:

model:
  provider: anthropic
  base_url: https://<resource>.services.ai.azure.com/anthropic
  api_key_env: AZURE_ANTHROPIC_KEY
  default: claude-sonnet-4-6

With AZURE_ANTHROPIC_KEY set to the Azure AI Foundry API key (no sk-ant- prefix).

Clawdbot added 5 commits April 2, 2026 10:16
…ss custom runtime when provider=anthropic + azure.com URL
…s ~/.claude/.credentials.json from overwriting Azure key mid-session
…as producing malformed URLs like /anthropic?api-version=.../v1/messages
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #15845 along with the other open Azure PRs as one consolidated salvage + an auto-detection feature on top (URL sniff + /models probe + Anthropic Messages fallback + context-length resolution).

Your commits were cherry-picked with authorship preserved (6ef3a47ce, d8e4c7214, 7bfa9442d, c15064fa3 on main). Thanks @HangGlidersRule — this landed because of your work.

@teknium1 teknium1 closed this Apr 26, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels Apr 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Superseded by #15845 which merged — consolidates fixes from #9029, #4599, #10086, and #8766.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants