From f1a1b58319da7ef66d50e8408ffbf8a150d48362 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Mon, 9 Mar 2026 03:14:22 -0700 Subject: [PATCH] fix: hermes setup doesn't update provider when switching to OpenRouter When switching FROM Codex/Nous/custom TO OpenRouter via 'hermes setup', the old provider stayed active because setup only saved the API key but never updated config.yaml or auth.json. This caused resolve_provider() to keep returning the old provider (e.g. openai-codex) even after the user selected OpenRouter. Fix: the OpenRouter path in setup now deactivates any OAuth provider in auth.json and writes model.provider='openrouter' to config.yaml, matching what all other provider paths already do. --- hermes_cli/setup.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hermes_cli/setup.py b/hermes_cli/setup.py index ffb10c149..c10caec9b 100644 --- a/hermes_cli/setup.py +++ b/hermes_cli/setup.py @@ -632,6 +632,29 @@ def setup_model_provider(config: dict): save_env_value("OPENAI_BASE_URL", "") save_env_value("OPENAI_API_KEY", "") + # Update config.yaml and deactivate any OAuth provider so the + # resolver doesn't keep returning the old provider (e.g. Codex). + try: + from hermes_cli.auth import deactivate_provider + deactivate_provider() + except Exception: + pass + import yaml + config_path = Path(os.environ.get("HERMES_HOME", Path.home() / ".hermes")) / "config.yaml" + try: + disk_cfg = {} + if config_path.exists(): + disk_cfg = yaml.safe_load(config_path.read_text()) or {} + model_section = disk_cfg.get("model", {}) + if isinstance(model_section, str): + model_section = {"default": model_section} + model_section["provider"] = "openrouter" + model_section.pop("base_url", None) # OpenRouter uses default URL + disk_cfg["model"] = model_section + config_path.write_text(yaml.safe_dump(disk_cfg, sort_keys=False)) + except Exception as e: + logger.debug("Could not save provider to config.yaml: %s", e) + elif provider_idx == 3: # Custom endpoint selected_provider = "custom" print()