The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(models): canonical-URL check covers OpenRouter and equivalent spellings
kshitijk4poor48ac94872a3c
diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex 20f388319ed..a1416c0458a 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -27,6 +27,7 @@ from typing import Any, Optional, TYPE_CHECKINGif TYPE_CHECKING:from typing import TypeGuard+from hermes_cli.route_identity import normalize_route_base_urlfrom hermes_cli.urllib_security import open_credentialed_urlfrom hermes_cli.version_info import get_version_infofrom hermes_cli.models_catalog_static import (@@ -1606,7 +1607,7 @@ def _configured_relay_base_url(provider: str) -> str:"""``model.base_url`` when it points the *configured* provider at a relay/proxy, else "".Discovery must probe the same endpoint inference uses (#121387): when ``model.base_url``- differs from the registered endpoint, the vendor's canonical host is NOT the catalog to list.+ differs from the provider's own endpoint, the vendor's canonical host is NOT the catalog to list.Mirrors the ``$OPENAI_BASE_URL`` -> ``model.base_url`` -> canonical precedence of``_openai_discovery_base_url`` for every built-in provider, not just OpenAI."""@@ -1618,17 +1619,25 @@ def _configured_relay_base_url(provider: str) -> str:if not cfg_provider or not provider:return ""try:- if normalize_provider(provider) != normalize_provider(cfg_provider):+ normalized = normalize_provider(provider)+ if normalized != normalize_provider(cfg_provider):return ""except Exception:return ""base_url = str(model_cfg.get("base_url") or "").strip().rstrip("/")- from hermes_cli.auth import PROVIDER_REGISTRY+ if not base_url:+ return ""+ # A base_url equal to the provider's own endpoint is not a relay (setup persists canonical+ # URLs too): keep native discovery, which OAuth providers such as Codex need because the+ # generic relay probe only speaks api_key. Profiles cover providers PROVIDER_REGISTRY lacks+ # (OpenRouter).+ try:+ from providers import get_provider_profile- registered = PROVIDER_REGISTRY.get(normalize_provider(provider))- # Setup persists canonical URLs too. They still need the provider's native discovery- # (notably Codex OAuth); the generic relay probe only supports API-key providers.- if registered and base_url == registered.inference_base_url.rstrip("/"):+ canonical = getattr(get_provider_profile(normalized), "base_url", "") or ""+ except Exception:+ return base_url # lookup failed: stay a relay, never widening where credentials go+ if canonical and normalize_route_base_url(base_url) == normalize_route_base_url(canonical):return ""return base_urldiff --git a/tests/hermes_cli/test_models_relay_base_url.py b/tests/hermes_cli/test_models_relay_base_url.pyindex a78aece8291..e83e4944f13 100644--- a/tests/hermes_cli/test_models_relay_base_url.py+++ b/tests/hermes_cli/test_models_relay_base_url.py@@ -19,13 +19,13 @@ class _RecordingProfile:return ["relay-only-model"][email protected]("provider", ["openai-codex", "copilot", "nous", "opencode-zen"])[email protected]("provider", ["openai-codex", "copilot", "nous", "opencode-zen", "openrouter"])def test_canonical_url_preserves_native_catalog_but_other_paths_stay_relays(monkeypatch, provider):- from hermes_cli.auth import PROVIDER_REGISTRYfrom hermes_cli.config import atomic_config_writefrom hermes_constants import get_hermes_home+ from providers import get_provider_profile- canonical = PROVIDER_REGISTRY[provider].inference_base_url+ canonical = get_provider_profile(provider).base_urlconfig_path = get_hermes_home() / "config.yaml"calls = []@@ -35,7 +35,11 @@ def test_canonical_url_preserves_native_catalog_but_other_paths_stay_relays(monkmonkeypatch.setitem(models._PROVIDER_CATALOG_FETCHERS, provider, native_catalog)monkeypatch.setattr(models, "_relay_model_catalog", lambda *args: None)- for base_url, expected in [(canonical, [provider]), (canonical + "/relay", [])]:+ scheme, rest = canonical.split("://", 1)+ host, _, path = rest.partition("/")+ # Same route spelled differently: scheme/host case, explicit default port, trailing slash.+ shouted = f"{scheme.upper()}://{host.upper()}:443{'/' + path if path else ''}/"+ for base_url, expected in [(canonical, [provider]), (shouted, [provider]), (canonical + "/relay", [])]:calls.clear()atomic_config_write(config_path, {"model": {"provider": provider, "base_url": base_url}})catalog = models.provider_model_ids(provider, force_refresh=True)