hermes - 💡(How to fix) Fix [Bug]: fallback_providers with provider: custom + explicit base_url falls back to OpenRouter when main model.provider is a named provider [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Additional Logs / Traceback (optional)

Root Cause

Root Cause Analysis (optional)

Fix Action

Fixed

Code Example

--

---
RAW_BUFFERClick to expand / collapse

Bug Description

环境:Hermes Agent v0.13.0 (2026.5.7)

 配置示例:

 yaml
 model:
   provider: zai                          # 任意 named provider
   base_url: https://open.bigmodel.cn/api/paas/v4
   default: GLM-4.1V-Thinking-FlashX

 fallback_providers:
   - provider: custom                     # ← 这里用 custom
     base_url: https://token.sensenova.cn/v1   # ← 有明确的 base_url
     api_key: sk-xxx
     model: deepseek-v4-flash

 预期行为: fallback 触发时,使用 fallback 条目中指定的base_url(sensenova)和 api_key。

 实际行为: fallback 解析到 https://openrouter.ai/api/v1,连接失败。

 根因分析:

 在 hermes_cli/runtime_provider.py 的 _resolve_explicit_runtime()中,base_url 的解析链为:

 python
 base_url = (
     (explicit_base_url or "").strip()
     or env_custom_base_url
     or (cfg_base_url.strip() if use_config_base_url else "")
     or env_openrouter_base_url
     or OPENROUTER_BASE_URL          # ← 最终兜底
 )

 其中 use_config_base_url 由_config_base_url_trustworthy_for_bare_custom() 决定:

 python
 def _config_base_url_trustworthy_for_bare_custom(cfg_base_url,
 cfg_provider):
     cfg_provider_norm = (cfg_provider or "").strip().lower()
     if cfg_provider_norm == "custom":    # ← 只有 provider 是 "custom"
 才信任
         return True
     if base_url_host_matches(bu, "openrouter.ai"):
         return False
     return _loopback_hostname(base_url_hostname(bu))  # ← 非 loopback
 也返回 False

 当主配置的 model.provider 是 zai(或其他 named provider)时,use_config_base_url = False。此时即使 explicit_base_url被正确传入(gateway/run.py 的 _try_resolve_fallback_provider确实传了),但 cfg_base_url 被跳过,且如果 CUSTOM_BASE_URL环境变量未设置,最终落到 OPENROUTER_BASE_URL。

 影响范围: 任何使用 named provider 作为主模型、同时在 fallback 中使用provider: custom 的用户都会遇到此问题。
  1. 在 _resolve_explicit_runtime() 中,当 explicit_base_url已传入时,直接使用它,不依赖 use_config_base_url 的判断。或者:

  2. 在 _config_base_url_trustworthy_for_bare_custom() 中,放宽对 named provider 的限制——当 explicit_base_url 已提供时,不应再检查 config 的base_url 可信度。

    临时绕过方案: 将 model.provider 改为 custom,或将 fallback 条目的provider 改为对应的 named provider(如 sensetime)。

Steps to Reproduce

任何使用 named provider 作为主模型、同时在 fallback 中使用provider: custom 的用户都会遇到此问题。

Expected Behavior

预期行为: fallback 触发时,使用 fallback 条目中指定的base_url和 api_key。

Actual Behavior

fallback 解析到 https://openrouter.ai/api/v1,连接失败。

Affected Component

Configuration (config.yaml, .env, hermes setup)

Messaging Platform (if gateway-related)

N/A (CLI only)

Debug Report

--

Operating System

wsl

Python Version

python: 3.11.15

Hermes Version

0.13.0 (2026.5.7) [ae83a54b]

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING