fix(provider): route api.anthropic.com to anthropic_messages (#32243) - #223
Merged
Conversation
|
Review Complete Risk: 🟢 Low (5/100) — no findings · 333 LOC across 6 files No issues found. The PR modifies provider URL detection, Anthropic OAuth routing, fallback logic, and corresponding tests — all changes are well-structured and correct. Files Reviewed (6 files) |
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.
Summary
_detect_api_mode_for_urlnow returnsanthropic_messagesfor the nativeapi.anthropic.comhost, realigning it with its siblingproviders.determine_api_mode— which already maps that host. Previously the two helpers disagreed, so any URL-fallback path resolving a base_url ofapi.anthropic.comdefaulted tochat_completions→POST /v1/chat/completions, the OpenAI-compat shim that bills OAuth Pro/Max against a separate "extra usage" pool (surfacing as the misleading400 "out of extra usage").Root cause:
_detect_api_mode_for_urlonly matched the third-party/anthropicpath suffix (MiniMax, Zhipu, LiteLLM proxies) andapi.kimi.com/coding; the direct Anthropic host fell through toNone.Salvage of NousResearch#32318 (@xxxigm), widened to also cover the
try_activate_fallbacksibling call site from NousResearch#49247 (@x9x9x9x9x9x91) so the whole bug class is fixed, not just one path.Changes
hermes_cli/runtime_provider.py:_detect_api_mode_for_urlmapshostname == "api.anthropic.com"→anthropic_messages. Exact-hostname match rejects lookalike subdomains and path-segment spoofing.agent/chat_completion_helpers.py:try_activate_fallbackmatches the same native host, so a custom fallback provider onapi.anthropic.comno longer 404s on/v1/chat/completions.test_detect_api_mode_for_url.py,test_anthropic_oauth_routes_to_messages_api.py(pins all runtime branches),test_provider_fallback.py(fallback path).Scope note
The reporter's primary scenario (a
provider: anthropicOAuth pool credential) already routes correctly on main — that branch hardcodesanthropic_messages— and the specific400 "out of extra usage"symptom is separately handled on main by NousResearch#56128 (billing classification + pool rotation). This PR fixes the adjacent, real helper-disagreement affecting custom-provider / bare-api-key setups pointed at the native host.Validation
api.anthropic.com(native host)_detect_api_mode_for_urlNone→chat_completionsanthropic_messagestry_activate_fallbackcustom providerchat_completions→ 404anthropic_messagesscripts/run_tests.sh— 3 files, 53 tests passed. Live E2E confirmed native host resolves and both spoof shapes are rejected.Infographic
Mirror-of: NousResearch#56214
NousResearch#56214