From ee16416c7b23b670d8e4172b6346b077adc83d2d Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:13:11 -0700 Subject: [PATCH] fix(cli): prefer auth.py env vars over models.dev in provider detection (#6755) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit list_authenticated_providers() was using env var names from the external models.dev registry to detect credentials. This registry has incorrect mappings for 5 providers: minimax-cn, zai, opencode-zen, opencode-go, and kilocode — causing them to not appear in /model even when the correct API key is set. Now checks PROVIDER_REGISTRY from auth.py first (our source of truth), falling back to models.dev only for providers not in our registry. Fixes #6620. Based on devorun's investigation in PR #6625. --- hermes_cli/model_switch.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.py index 7d120d94f..ef35108df 100644 --- a/hermes_cli/model_switch.py +++ b/hermes_cli/model_switch.py @@ -733,6 +733,7 @@ def list_authenticated_providers( fetch_models_dev, get_provider_info as _mdev_pinfo, ) + from hermes_cli.auth import PROVIDER_REGISTRY from hermes_cli.models import OPENROUTER_MODELS, _PROVIDER_MODELS results: List[dict] = [] @@ -753,9 +754,16 @@ def list_authenticated_providers( if not isinstance(pdata, dict): continue - env_vars = pdata.get("env", []) - if not isinstance(env_vars, list): - continue + # Prefer auth.py PROVIDER_REGISTRY for env var names — it's our + # source of truth. models.dev can have wrong mappings (e.g. + # minimax-cn → MINIMAX_API_KEY instead of MINIMAX_CN_API_KEY). + pconfig = PROVIDER_REGISTRY.get(hermes_id) + if pconfig and pconfig.api_key_env_vars: + env_vars = list(pconfig.api_key_env_vars) + else: + env_vars = pdata.get("env", []) + if not isinstance(env_vars, list): + continue # Check if any env var is set has_creds = any(os.environ.get(ev) for ev in env_vars)