From f8fb61d4ad44e92eb78bf99ba644cfa27994378c Mon Sep 17 00:00:00 2001 From: Teknium Date: Sat, 21 Mar 2026 16:16:17 -0700 Subject: [PATCH] fix(provider): prevent Anthropic fallback from inheriting non-Anthropic base_url Only honor config.model.base_url for Anthropic resolution when config.model.provider is actually "anthropic". This prevents a Codex (or other provider) base_url from leaking into Anthropic runtime and auxiliary client paths, which would send requests to the wrong endpoint. Closes #2384 --- agent/auxiliary_client.py | 12 ++++++++---- hermes_cli/runtime_provider.py | 9 +++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index b6d6e110a..d6012a40f 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -654,16 +654,20 @@ def _try_anthropic() -> Tuple[Optional[Any], Optional[str]]: if not token: return None, None - # Allow base URL override from config.yaml model.base_url + # Allow base URL override from config.yaml model.base_url, but only + # when the configured provider is anthropic — otherwise a non-Anthropic + # base_url (e.g. Codex endpoint) would leak into Anthropic requests. base_url = _ANTHROPIC_DEFAULT_BASE_URL try: from hermes_cli.config import load_config cfg = load_config() model_cfg = cfg.get("model") if isinstance(model_cfg, dict): - cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/") - if cfg_base_url: - base_url = cfg_base_url + cfg_provider = str(model_cfg.get("provider") or "").strip().lower() + if cfg_provider == "anthropic": + cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/") + if cfg_base_url: + base_url = cfg_base_url except Exception: pass diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py index 8c2979b6b..7a4105762 100644 --- a/hermes_cli/runtime_provider.py +++ b/hermes_cli/runtime_provider.py @@ -359,9 +359,14 @@ def resolve_runtime_provider( "No Anthropic credentials found. Set ANTHROPIC_TOKEN or ANTHROPIC_API_KEY, " "run 'claude setup-token', or authenticate with 'claude /login'." ) - # Allow base URL override from config.yaml model.base_url + # Allow base URL override from config.yaml model.base_url, but only + # when the configured provider is anthropic — otherwise a non-Anthropic + # base_url (e.g. Codex endpoint) would leak into Anthropic requests. model_cfg = _get_model_config() - cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/") + cfg_provider = str(model_cfg.get("provider") or "").strip().lower() + cfg_base_url = "" + if cfg_provider == "anthropic": + cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/") base_url = cfg_base_url or "https://api.anthropic.com" return { "provider": "anthropic",