The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(runtime): declared Anthropic transport applies only on the provider's own endpoint
kshitijk4poorae2a8cd81906
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.pyindex 9a39758e658..a81d92f03cd 100644--- a/hermes_cli/runtime_provider.py+++ b/hermes_cli/runtime_provider.py@@ -32,7 +32,7 @@ from hermes_cli.auth import ( # resolve_external_process_provider_credentials ifrom hermes_cli import config as _config_modfrom hermes_cli import models as _models # attribute access keeps ``hermes_cli.models.<name>`` patches effectivefrom hermes_constants import OPENROUTER_BASE_URL-from hermes_cli.providers import determine_api_mode, is_actual_route, is_official_openai_host, nous_api_mode+from hermes_cli.providers import determine_api_mode, get_provider, is_actual_route, is_official_openai_host, nous_api_modefrom utils import base_url_host_matches, base_url_hostname, env_int@@ -143,7 +143,30 @@ def _fallback_api_mode(provider: str, base_url: str, model: str = "") -> str:``chat_completions``."""if is_actual_route(provider, base_url):return "chat_completions"- return _detect_api_mode_for_url(base_url) or determine_api_mode(provider, base_url, model) or "chat_completions"+ detected = _detect_api_mode_for_url(base_url)+ if detected:+ return detected+ declared = determine_api_mode(provider, base_url, model) or "chat_completions"+ if declared == "anthropic_messages" and not _on_declared_anthropic_endpoint(provider, base_url):+ # The declared Anthropic transport describes the provider's own endpoint. A base_url+ # override at a foreign host (OpenAI-compatible relay, LiteLLM, egress proxy) or at the+ # provider's OpenAI-compatible path (api.minimax.io/v1) speaks chat/completions; sending+ # Messages-shaped requests with x-api-key there is a 401 on every turn (#76836).+ return "chat_completions"+ return declared+++def _on_declared_anthropic_endpoint(provider: str, base_url: str) -> bool:+ """True when ``base_url`` is the provider's own Anthropic-protocol endpoint: same host as the+ catalog default and either the bare host or a path under ``/anthropic``. Unknown default ⇒ True+ (nothing to compare against, keep the declared transport)."""+ default = (getattr(get_provider(provider), "base_url", "") or "").strip()+ if not default:+ return True+ if not base_url_host_matches(base_url, base_url_hostname(default)):+ return False+ path = urlparse((base_url or "").strip().lower()).path.rstrip("/")+ return path == "" or path.startswith("/anthropic")def _resolve_plain_custom_api_mode(model_cfg: Dict[str, Any], base_url: str) -> str:diff --git a/tests/hermes_cli/test_runtime_transport_precedence.py b/tests/hermes_cli/test_runtime_transport_precedence.pyindex b54052e11fe..653ea251005 100644--- a/tests/hermes_cli/test_runtime_transport_precedence.py+++ b/tests/hermes_cli/test_runtime_transport_precedence.py@@ -43,6 +43,25 @@ class TestFallbackApiMode:== "codex_responses")+ @pytest.mark.parametrize("provider, base_url", [+ ("minimax", "http://127.0.0.1:8787/v1"), # OpenAI-compatible relay in front of MiniMax+ ("minimax-cn", "https://egress.corp.test/v1"), # corporate egress gateway+ ("minimax", "https://api.minimax.io/v1"), # provider's own OpenAI-compatible path+ ])+ def test_anthropic_transport_is_not_assumed_off_the_provider_endpoint(self, provider, base_url):+ # #76836: the declared anthropic_messages transport is a statement about the provider's+ # own /anthropic endpoint. Anywhere else the override speaks chat/completions; Messages-+ # shaped requests with x-api-key there 401 on every turn (or silently reroute to a fallback).+ assert _fallback_api_mode(provider, base_url, "MiniMax-M3") == "chat_completions"++ @pytest.mark.parametrize("provider, base_url", [+ ("minimax", "https://api.minimax.io"), # bare host, no /anthropic hint (#53054 kept)+ ("minimax", "https://api.minimax.io/anthropic"), # URL-detected native path+ ("minimax-cn", "https://api.minimaxi.com/anthropic/v1"),+ ])+ def test_anthropic_transport_holds_on_the_provider_endpoint(self, provider, base_url):+ assert _fallback_api_mode(provider, base_url, "MiniMax-M3") == "anthropic_messages"+def test_lookalike_host_is_not_treated_as_official(self):# The spoof host must not be detected AS OpenAI by the URL lane —# the provider-declared transport may still apply, but host-derived