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.

opencode's baseURL ends with /v1; the catalog's Anthropic base carries it too (#85)

github-actions[bot]bfa01554a51f
diff --git a/gateway/app.py b/gateway/app.py
index 7d16c932..76831a5d 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -3916,7 +3916,11 @@ async def _require_integrations_admin(request: Request) -> dict:
_PROVIDER_CATALOG: dict[str, dict] = {
"anthropic": {
"label": "Anthropic",
- "base_url": "https://api.anthropic.com",
+ # With the "/v1", like every other direct provider here and like the broker's own default
+ # (_PROVIDER_BASE): the broker joins the resource ("messages") straight onto it, and a
+ # base stored without the suffix sent a brokered Messages call to
+ # https://api.anthropic.com/messages. The claude CLI's runner path strips it again.
+ "base_url": "https://api.anthropic.com/v1",
"fields": [],
"secret": "api_key",
"secret_label": "API Key",
diff --git a/runner/server.py b/runner/server.py
index 587e0650..2f75a473 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -2950,12 +2950,23 @@ def _opencode_config(auth: Auth, model: str, cwd: str, mcp_servers: list[dict] |
npm = "@ai-sdk/openai" # /v1/responses
else:
npm = "@ai-sdk/openai-compatible" # /v1/chat/completions
+ # Every ai-sdk package appends its own resource to baseURL (@ai-sdk/anthropic "/messages",
+ # @ai-sdk/openai "/responses", openai-compatible "/chat/completions") and expects the "/v1"
+ # to be there already, the way pi's openai clients do (see _pi_models_json). A connection
+ # stored without it (the catalog's own default for a direct Anthropic key is
+ # https://api.anthropic.com) sent every opencode turn to https://api.anthropic.com/messages,
+ # which Anthropic answers "Not Found" (2026-09-06 support matrix, every claude model; the same
+ # key served pi and hermes, which normalise the suffix themselves). A custom endpoint is the
+ # user's exact URL and is left alone.
+ base = (auth.base_url or "").rstrip("/")
+ if not auth.api_format and not base.endswith("/v1"):
+ base += "/v1"
cfg: dict = {
"$schema": "https://opencode.ai/config.json",
"provider": {
"hr": {
"npm": npm,
- "options": {"baseURL": auth.base_url, "apiKey": "{env:%s}" % _OPENCODE_KEY_ENV},
+ "options": {"baseURL": base, "apiKey": "{env:%s}" % _OPENCODE_KEY_ENV},
"models": {model: {}},
}
},
diff --git a/runner/tests/test_opencode_base_url.py b/runner/tests/test_opencode_base_url.py
new file mode 100644
index 00000000..839c511d
--- /dev/null
+++ b/runner/tests/test_opencode_base_url.py
@@ -0,0 +1,27 @@
+"""opencode's baseURL ends with /v1: every ai-sdk package appends its own resource to it."""
+import json
+import pathlib
+import sys
+
+sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
+import server # noqa: E402
+
+
+def _cfg(tmp_path, **auth):
+ server._opencode_config(server.Auth(**auth), "claude-opus-5", str(tmp_path), None, None, pr=auth.get("provider", ""))
+ return json.load(open(tmp_path / ".harness" / "opencode.json"))["provider"]["hr"]
+
+
+def test_a_direct_anthropic_key_without_the_suffix_gets_it(tmp_path):
+ p = _cfg(tmp_path, provider="anthropic", base_url="https://api.anthropic.com", api_key="k")
+ assert p["npm"] == "@ai-sdk/anthropic" and p["options"]["baseURL"] == "https://api.anthropic.com/v1"
+
+
+def test_a_base_that_already_ends_in_v1_is_kept(tmp_path):
+ p = _cfg(tmp_path, provider="tokenrouter", base_url="https://api.tokenrouter.com/v1/", api_key="k")
+ assert p["options"]["baseURL"] == "https://api.tokenrouter.com/v1"
+
+
+def test_a_custom_endpoint_is_the_users_exact_url(tmp_path):
+ p = _cfg(tmp_path, provider="custom", base_url="https://relay.example/api/coding/v3", api_key="k", api_format="anthropic")
+ assert p["options"]["baseURL"] == "https://relay.example/api/coding/v3"