From 34792dd907dfd1599417c3ae73942e4987020ae6 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sun, 8 Mar 2026 05:58:45 -0700 Subject: [PATCH] fix: resolve 'auto' provider properly via credential detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'auto' doesn't always mean openrouter — it could be nous, zai, kimi-coding, etc. depending on configured credentials. Reverted the hardcoded mapping and now both CLI and gateway call resolve_provider() to detect the actual active provider when 'auto' is set. Falls back to openrouter only if resolution fails. --- cli.py | 15 ++++++++++++++- gateway/run.py | 7 +++++++ hermes_cli/models.py | 9 ++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/cli.py b/cli.py index 038dd6af3..d7a5bcaa1 100755 --- a/cli.py +++ b/cli.py @@ -2132,7 +2132,20 @@ class HermesCLI: print(f" Warning: {message}") else: from hermes_cli.models import curated_models_for_provider, normalize_provider, _PROVIDER_LABELS - display_provider = normalize_provider(self.provider) + from hermes_cli.auth import resolve_provider as _resolve_provider + # Resolve "auto" to the actual provider using credential detection + raw_provider = normalize_provider(self.provider) + if raw_provider == "auto": + try: + display_provider = _resolve_provider( + self.requested_provider, + explicit_api_key=self._explicit_api_key, + explicit_base_url=self._explicit_base_url, + ) + except Exception: + display_provider = "openrouter" + else: + display_provider = raw_provider provider_label = _PROVIDER_LABELS.get(display_provider, display_provider) print(f"\n Current model: {self.model}") print(f" Current provider: {provider_label}") diff --git a/gateway/run.py b/gateway/run.py index c7219de90..d1dcd8976 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -1344,7 +1344,14 @@ class GatewayRunner: except Exception: pass + # Resolve "auto" to the actual provider using credential detection current_provider = normalize_provider(current_provider) + if current_provider == "auto": + try: + from hermes_cli.auth import resolve_provider as _resolve_provider + current_provider = _resolve_provider(current_provider) + except Exception: + current_provider = "openrouter" if not args: provider_label = _PROVIDER_LABELS.get(current_provider, current_provider) diff --git a/hermes_cli/models.py b/hermes_cli/models.py index 823904fa4..80e09fea1 100644 --- a/hermes_cli/models.py +++ b/hermes_cli/models.py @@ -124,10 +124,13 @@ def curated_models_for_provider(provider: Optional[str]) -> list[tuple[str, str] def normalize_provider(provider: Optional[str]) -> str: - """Normalize provider aliases to Hermes' canonical provider ids.""" + """Normalize provider aliases to Hermes' canonical provider ids. + + Note: ``"auto"`` passes through unchanged — use + ``hermes_cli.auth.resolve_provider()`` to resolve it to a concrete + provider based on credentials and environment. + """ normalized = (provider or "openrouter").strip().lower() - if normalized == "auto": - return "openrouter" return _PROVIDER_ALIASES.get(normalized, normalized)