Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

fix(runner): resolve hermes provider to anthropic for custom Messages connections (closes #374) (#443)

Shobhit agnihotri4284d0c4ffd3
diff --git a/runner/server.py b/runner/server.py
index 479a0f8e..ff24773b 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -5135,6 +5135,16 @@ def _hermes_relay_route(base_url: str, api_key: str, drop_fields: tuple[str, ...
return f"http://127.0.0.1:{_HERMES_RELAY['port']}/v1", tok
+def _hermes_resolve_provider(provider: str | None, auth: Auth) -> str:
+ """The hermes provider a turn runs on. A custom endpoint declared in the Anthropic Messages
+ format arrives as openai-api (the gateway's ("custom", "hermes") wiring) and is hermes's
+ anthropic provider. config.yaml and the --provider flag MUST both take this one name: the flag
+ wins over the file, so a turn configured for anthropic but launched with openai-api asked for
+ an OPENAI_API_KEY nobody set (#374)."""
+ p = (provider or "bedrock").lower()
+ return "anthropic" if _anthropic_native(p, auth) else p
+
+
def _hermes_prepare_env(provider: str | None, auth: Auth, cwd: str, env: dict,
model: str = "", max_turns: int | None = None,
mcp_servers: list[dict] | None = None,
@@ -5145,9 +5155,7 @@ def _hermes_prepare_env(provider: str | None, auth: Auth, cwd: str, env: dict,
The model/provider MUST be in config.yaml, not only flags: the chat path's first-run guard
treats a default-model config as 'unconfigured' and exits into the setup wizard (verified on
0.19.0 — bedrock bearer creds alone don't satisfy it). The -z/-m flags still take precedence."""
- p = (provider or "bedrock").lower()
- if str(auth.api_format or "").strip().lower() == "anthropic":
- p = "anthropic" # a custom endpoint in the Messages format is hermes's anthropic provider
+ p = _hermes_resolve_provider(provider, auth)
if p not in HERMES_PROVIDERS:
raise HTTPException(400, f"unknown hermes provider '{p}' (one of {sorted(HERMES_PROVIDERS)})")
hermes_home = pathlib.Path(env.get("HOME") or cwd) / ".hermes"
@@ -10233,7 +10241,7 @@ def turn(req: TurnReq, identifier: str = "") -> dict:
mcp_toml=mcp_toml, resume_session_id=req.resume_session_id, tools_disabled=req.tools_disabled)
elif backend == "hermes":
model = model or HERMES_DEFAULT_MODEL
- hermes_provider = (req.provider or "bedrock").lower()
+ hermes_provider = _hermes_resolve_provider(req.provider, auth)
hermes_mcp = _hermes_prepare_env(hermes_provider, auth, cwd, env, model=model,
max_turns=req.max_turns, mcp_servers=req.mcp_servers,
vision_auth=req.vision_auth)
diff --git a/runner/tests/test_messages_route.py b/runner/tests/test_messages_route.py
index 71076413..85ae4cfe 100644
--- a/runner/tests/test_messages_route.py
+++ b/runner/tests/test_messages_route.py
@@ -190,3 +190,24 @@ def test_the_hermes_result_carries_the_relays_served_model_and_cache_split():
body = src[src.index("def _run_hermes_bg("):src.index("# ── HTTP surface")]
assert "served = _relay_served_model(env)" in body and "_fill_relay_usage(ev, env)" in body
assert body.index("_fill_relay_usage(ev, env)") < body.rindex("append(ev)") # stamped before the result is appended
+
+
+def test_a_hermes_turn_is_launched_on_the_provider_its_config_names(monkeypatch, tmp_path):
+ """The --provider flag wins over config.yaml, so the two must name one provider. A custom
+ endpoint in the Messages format arrives as openai-api; it was configured as anthropic and
+ launched as openai-api, and hermes refused it for want of an OPENAI_API_KEY (#374)."""
+ launched = []
+ monkeypatch.setattr(server, "_run_hermes_bg", lambda *args: launched.append(args))
+ wirings = [("openai-api", "anthropic", "anthropic", "ANTHROPIC_BASE_URL"), # custom, Messages format
+ ("openai-api", "openai", "openai-api", "OPENAI_BASE_URL"), # custom, Chat Completions
+ ("anthropic", None, "anthropic", "ANTHROPIC_BASE_URL"),
+ ("openrouter", None, "openrouter", "OPENROUTER_BASE_URL")]
+ for i, (provider, fmt, want, base_env) in enumerate(wirings):
+ cwd = tmp_path / str(i)
+ cwd.mkdir()
+ server.turn(server.TurnReq(backend="hermes", provider=provider, model="claude-haiku-4.5", prompt="hi",
+ auth=Auth(api_key="sk-test", base_url="https://proxy.example/v1", api_format=fmt),
+ cwd=str(cwd)))
+ env, flag = launched[-1][2], launched[-1][4]
+ cfg = yaml.safe_load((pathlib.Path(env["HERMES_HOME"]) / "config.yaml").read_text())
+ assert flag == cfg["model"]["provider"] == want and base_env in env, (provider, fmt)