From 1bca6f393002da217a3e64a437a4fc5aac16dc9d Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Tue, 31 Mar 2026 01:36:15 -0700 Subject: [PATCH] fix: save API key to model config for custom endpoints (#4182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Custom cloud endpoints (Together.ai, RunPod, Groq, etc.) lost their API key after #4165 removed OPENAI_API_KEY .env saves. The key was only saved to the custom_providers list which is unreachable at runtime for plain 'custom' provider resolution. Save model.api_key to config.yaml alongside model.provider and model.base_url in all three custom endpoint code paths: - _model_flow_custom (new endpoint with model name) - _model_flow_custom (new endpoint without model name) - _model_flow_named_custom (switching to a saved endpoint) The runtime resolver already reads model.api_key (runtime_provider.py line 224-228), so the key is picked up automatically. Each custom endpoint carries its own key in config — no shared OPENAI_API_KEY env var needed. --- hermes_cli/main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hermes_cli/main.py b/hermes_cli/main.py index a12879a8ba..f2845869ae 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -1288,6 +1288,8 @@ def _model_flow_custom(config): cfg["model"] = model model["provider"] = "custom" model["base_url"] = effective_url + if effective_key: + model["api_key"] = effective_key model.pop("api_mode", None) # let runtime auto-detect from URL save_config(cfg) deactivate_provider() @@ -1309,6 +1311,8 @@ def _model_flow_custom(config): _caller_model = {"default": _caller_model} if _caller_model else {} _caller_model["provider"] = "custom" _caller_model["base_url"] = effective_url + if effective_key: + _caller_model["api_key"] = effective_key _caller_model.pop("api_mode", None) config["model"] = _caller_model print("Endpoint saved. Use `/model` in chat or `hermes model` to set a model.") @@ -1460,6 +1464,8 @@ def _model_flow_named_custom(config, provider_info): cfg["model"] = model model["provider"] = "custom" model["base_url"] = base_url + if api_key: + model["api_key"] = api_key save_config(cfg) deactivate_provider() @@ -1531,6 +1537,8 @@ def _model_flow_named_custom(config, provider_info): cfg["model"] = model model["provider"] = "custom" model["base_url"] = base_url + if api_key: + model["api_key"] = api_key save_config(cfg) deactivate_provider()