fix(gateway): clear stale base_url on model switches

This commit is contained in:
Priyanshu Sharma 2026-06-23 13:18:56 -05:00 committed by Teknium
parent f54c52800a
commit f6deabca0d
4 changed files with 7 additions and 4 deletions

View file

@ -1361,7 +1361,7 @@ class GatewaySlashCommandsMixin:
if result.base_url:
_persist_model_cfg["base_url"] = result.base_url
if str(result.target_provider or "").strip().lower() != "custom":
clear_model_endpoint_credentials(_persist_model_cfg)
clear_model_endpoint_credentials(_persist_model_cfg, clear_base_url=True)
from hermes_cli.config import save_config
save_config(_persist_cfg)
except Exception as e:
@ -1598,7 +1598,7 @@ class GatewaySlashCommandsMixin:
if result.base_url:
model_cfg["base_url"] = result.base_url
if str(result.target_provider or "").strip().lower() != "custom":
clear_model_endpoint_credentials(model_cfg)
clear_model_endpoint_credentials(model_cfg, clear_base_url=True)
from hermes_cli.config import save_config
save_config(cfg)
except Exception as e:

View file

@ -4131,6 +4131,7 @@ def clear_model_endpoint_credentials(
*,
clear_api_key: bool = True,
clear_api_mode: bool = True,
clear_base_url: bool = False,
) -> Dict[str, Any]:
"""Remove stale inline endpoint credentials from a model config.
@ -4147,6 +4148,8 @@ def clear_model_endpoint_credentials(
model_cfg.pop("api", None)
if clear_api_mode:
model_cfg.pop("api_mode", None)
if clear_base_url:
model_cfg.pop("base_url", None)
return model_cfg

View file

@ -102,7 +102,7 @@ async def test_model_global_persists_when_config_has_flat_string_model(tmp_path,
)
assert written["model"]["default"] == "gpt-5.5"
assert written["model"]["provider"] == "openrouter"
assert written["model"]["base_url"] == "https://openrouter.ai/api/v1"
assert "base_url" not in written["model"]
@pytest.mark.asyncio

View file

@ -171,7 +171,7 @@ async def test_picker_tap_persists_by_default(tmp_path, monkeypatch, seed_model)
)
assert written["model"]["default"] == "gpt-5.5"
assert written["model"]["provider"] == "openrouter"
assert written["model"]["base_url"] == "https://openrouter.ai/api/v1"
assert "base_url" not in written["model"]
assert "api_key" not in written["model"]
assert "api_mode" not in written["model"]