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:
parent
da44c196b6
commit
f8fb61d4ad
2 changed files with 15 additions and 6 deletions
|
|
@ -654,13 +654,17 @@ 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_provider = str(model_cfg.get("provider") or "").strip().lower()
|
||||||
|
if cfg_provider == "anthropic":
|
||||||
cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/")
|
cfg_base_url = (model_cfg.get("base_url") or "").strip().rstrip("/")
|
||||||
if cfg_base_url:
|
if cfg_base_url:
|
||||||
base_url = cfg_base_url
|
base_url = cfg_base_url
|
||||||
|
|
|
||||||
|
|
@ -359,8 +359,13 @@ 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_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("/")
|
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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue