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
This commit is contained in:
@@ -654,16 +654,20 @@ def _try_anthropic() -> Tuple[Optional[Any], Optional[str]]:
|
|||||||
if not token:
|
if not token:
|
||||||
return None, None
|
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
|
base_url = _ANTHROPIC_DEFAULT_BASE_URL
|
||||||
try:
|
try:
|
||||||
from hermes_cli.config import load_config
|
from hermes_cli.config import load_config
|
||||||
cfg = load_config()
|
cfg = load_config()
|
||||||
model_cfg = cfg.get("model")
|
model_cfg = cfg.get("model")
|
||||||
if isinstance(model_cfg, dict):
|
if isinstance(model_cfg, dict):
|
||||||
cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/")
|
cfg_provider = str(model_cfg.get("provider") or "").strip().lower()
|
||||||
if cfg_base_url:
|
if cfg_provider == "anthropic":
|
||||||
base_url = cfg_base_url
|
cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/")
|
||||||
|
if cfg_base_url:
|
||||||
|
base_url = cfg_base_url
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -359,9 +359,14 @@ def resolve_runtime_provider(
|
|||||||
"No Anthropic credentials found. Set ANTHROPIC_TOKEN or ANTHROPIC_API_KEY, "
|
"No Anthropic credentials found. Set ANTHROPIC_TOKEN or ANTHROPIC_API_KEY, "
|
||||||
"run 'claude setup-token', or authenticate with 'claude /login'."
|
"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()
|
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"
|
base_url = cfg_base_url or "https://api.anthropic.com"
|
||||||
return {
|
return {
|
||||||
"provider": "anthropic",
|
"provider": "anthropic",
|
||||||
|
|||||||
Reference in New Issue
Block a user