fix: Azure AI Foundry / Azure Anthropic endpoint compatibility#4599
Closed
HangGlidersRule wants to merge 5 commits into
Closed
fix: Azure AI Foundry / Azure Anthropic endpoint compatibility#4599HangGlidersRule wants to merge 5 commits into
HangGlidersRule wants to merge 5 commits into
Conversation
added 5 commits
April 2, 2026 10:16
…I keys, not OAuth tokens
…en priority chain
…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
3 tasks
Contributor
|
Merged via #15845 along with the other open Azure PRs as one consolidated salvage + an auto-detection feature on top (URL sniff + Your commits were cherry-picked with authorship preserved ( |
3 tasks
Collaborator
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()inruntime_provider.pyonly excludedsk-ant-apiprefix keys, treating Azure keys (which don't start withsk-ant-at all) as OAuth tokens → wrong auth header sent.2. OAuth token priority chain overrides Azure key
resolve_anthropic_token()checks~/.claude/.credentials.jsonat priority 3, beforeANTHROPIC_API_KEYat 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_runtimeintercepts theanthropicproviderWhen
requested="anthropic"+ an Azure base_url is passed, the custom runtime resolver intercepts it and returnsprovider="custom"with noapi_modeset → falls through tochat_completionspath.4.
_try_refresh_anthropic_client_credentialsoverwrites Azure key mid-sessionCalled 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-versionappended tobase_urlproduces malformed URLsPrevious fix attempt added
api-version=2025-04-15directly to the base URL string. The Anthropic SDK then appended/v1/messagesto that, producing:instead of:
Azure returns 404 on the malformed path.
Fixes
3125ea6fsk-ant-keys are regular API keys, not OAuth tokens896d8157AZURE_ANTHROPIC_KEY/ANTHROPIC_API_KEYdirectly for Azure endpointsad3fcf3bprovider=anthropic+ Azure URLf3640168run_agent.py7c00e15aapi-versionviadefault_query, not baked intobase_urlConfiguration
After this fix, Azure AI Foundry works with the following
config.yaml:With
AZURE_ANTHROPIC_KEYset to the Azure AI Foundry API key (nosk-ant-prefix).