The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auxiliary): the inherited main key comes from the same source as the anchor endpoint
John Paul Solivae6ec4aa9ed92
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 41e5a9b3376..f92a80572f6 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -2508,16 +2508,24 @@ def _read_main_model_for_aux() -> str:return model-def _read_main_api_key_if_same_host(aux_base_url: str) -> str:+def _read_main_api_key_if_same_host(aux_base_url: str) -> Any:"""Main api_key only when *aux_base_url* has the main base_url's exact origin.Unconditional inheritance would leak the credential to any misconfigured host; mismatch keeps ``no-key-required`` → 401.Origin, not hostname: another scheme (``http://``) or port on the same host is a different endpoint.+ Anchor and key come from ONE source: the live runtime a turn bound, else config.yaml. The+ per-field readers fall back to config field by field, so a keyless or key_cmd live main would+ pair its own base_url with config's key and send that key to the live endpoint."""aux_origin = base_url_origin(aux_base_url)- if not aux_origin[1] or aux_origin != base_url_origin(_read_main_base_url()):+ live_base, live_key = _runtime_main_value("base_url"), _runtime_main_value("api_key")+ if live_base or live_key:+ main_base, main_key = live_base, _normalize_api_key(live_key)+ else:+ main_base, main_key = _read_main_base_url(), _read_main_api_key()+ if not aux_origin[1] or aux_origin != base_url_origin(main_base):return ""- return _read_main_api_key()+ return main_key# Compatibility mirrors for older readers/tests; the ContextVar below isdiff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.pyindex d8fafcb11d8..6f0267478d3 100644--- a/tests/agent/test_auxiliary_client.py+++ b/tests/agent/test_auxiliary_client.py@@ -4816,6 +4816,33 @@ class TestCustomEndpointApiKeyInheritance:assert model == "aux-model"assert (client.api_key == "sk-main-config-key") is inherits+ @pytest.mark.parametrize("live_key", ["", lambda: "sk-live-cmd-key"], ids=["keyless", "key_cmd"])+ def test_inherited_key_belongs_to_the_anchor_endpoint(self, tmp_path, monkeypatch, live_key):+ """The live main runtime (a /model switch, a keyless local server, a key_cmd) is the+ anchor; config.yaml's key belongs to config.yaml's base_url and must not ride along to+ the live endpoint."""+ import hermes_yaml as yaml+ from agent.auxiliary_client import reset_runtime_main, set_runtime_main++ monkeypatch.delenv("OPENAI_API_KEY", raising=False)+ monkeypatch.delenv("OPENAI_BASE_URL", raising=False)+ home = tmp_path / ".hermes"+ home.mkdir()+ (home / "config.yaml").write_text(yaml.safe_dump({+ "model": {"provider": "custom", "base_url": "https://gw.example.com/v1",+ "api_key": "sk-main-config-key", "default": "main-model"},+ "auxiliary": {"compression": {"provider": "custom", "base_url": "http://127.0.0.1:8080/v1",+ "model": "aux-model"}},+ }))+ monkeypatch.setenv("HERMES_HOME", str(home))+ token = set_runtime_main("custom", "local-model", base_url="http://127.0.0.1:8080/v1", api_key=live_key)+ try:+ client, _ = get_text_auxiliary_client("compression")+ finally:+ reset_runtime_main(token)++ assert client.api_key != "sk-main-config-key"+class TestNoProgressTimeoutTaskConfigGating:"""#108104: ``auxiliary.<task>.no_progress_timeout`` must only reach the request kwargsdiff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex 49663af2983..4af7149a3f0 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -1760,7 +1760,7 @@ auxiliary:model: "qwen2.5-vl"```-`base_url` takes precedence over `provider`, so this is the most explicit way to route an auxiliary task to a specific endpoint. For direct endpoint overrides, Hermes uses the configured `api_key` or falls back to `OPENAI_API_KEY`; it does not reuse `OPENROUTER_API_KEY` for that custom endpoint.+`base_url` takes precedence over `provider`, so this is the most explicit way to route an auxiliary task to a specific endpoint. For direct endpoint overrides, Hermes uses the configured `api_key` or falls back to `OPENAI_API_KEY`; it does not reuse `OPENROUTER_API_KEY` for that custom endpoint. With neither set, the main model's key is reused only when `base_url` has the main endpoint's exact origin (scheme, host and port). The main endpoint is the one the session is running on (after a `/model` switch, that one), paired with its own key, never with a key from a different endpoint.**Using OpenAI API key for vision:**```yamldiff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/configuration.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/configuration.mdindex c6cea794b6f..e481130c710 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/configuration.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/configuration.md@@ -1030,7 +1030,7 @@ auxiliary:model: "qwen2.5-vl"```-`base_url` 优先于 `provider`,因此这是将辅助任务路由到特定端点的最明确方式。对于直接端点覆盖,Hermes 使用配置的 `api_key` 或回退到 `OPENAI_API_KEY`;它不会为该自定义端点重用 `OPENROUTER_API_KEY`。+`base_url` 优先于 `provider`,因此这是将辅助任务路由到特定端点的最明确方式。对于直接端点覆盖,Hermes 使用配置的 `api_key` 或回退到 `OPENAI_API_KEY`;它不会为该自定义端点重用 `OPENROUTER_API_KEY`。两者都未设置时,只有当 `base_url` 与主端点的源(scheme、主机和端口)完全相同时,才会重用主模型的密钥。主端点是会话当前运行的端点(`/model` 切换后即为切换后的端点),并且只与它自己的密钥配对,绝不会使用另一个端点的密钥。**使用 OpenAI API 密钥进行视觉:**```yaml