Skip to content

The agent that grows with you

fix(desktop): custom endpoint Test probes the transport route, not just /v1/models

teknium1ab241af3860d
diff --git a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx
index d144ea3deec..36bce91d310 100644
--- a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx
+++ b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx
@@ -65,7 +65,8 @@ describe('CustomEndpointsSettings', () => {
],
models: ['gpt-5.6-sol', 'gpt-5.6-sol-high'],
ok: true,
- reachable: true
+ reachable: true,
+ transport_checked: 'codex_responses'
})
saveCustomEndpoint.mockResolvedValue(savedResponse)
const { CustomEndpointsSettings } = await import('./custom-endpoints-settings')
@@ -85,6 +86,10 @@ describe('CustomEndpointsSettings', () => {
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
expect(validateCustomEndpoint).toHaveBeenCalledWith(expect.objectContaining({ api_mode: 'codex_responses' }))
+ expect(notify).toHaveBeenCalledWith({
+ kind: 'success',
+ message: 'Endpoint is reachable (Responses API route served). Found 2 models.'
+ })
expect(saveCustomEndpoint).toHaveBeenCalledWith(
expect.objectContaining({
api_mode: 'codex_responses',
diff --git a/apps/desktop/src/app/settings/custom-endpoints-settings.tsx b/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
index 2fb04a9adee..5b59e6c2478 100644
--- a/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
+++ b/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
@@ -213,11 +213,13 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
setForm(current => ({ ...current, model: response.models[0] }))
}
+ // The backend also POSTed the transport the runtime will use; name it so an
+ // auto-detected mode is visible before Save (#93622).
+ const transport = API_MODE_OPTIONS.find(option => option.id === response.transport_checked)?.label
+ const reachable = transport ? `Endpoint is reachable (${transport} route served).` : 'Endpoint is reachable.'
notify({
kind: 'success',
- message: response.models.length
- ? `Endpoint is reachable. Found ${response.models.length} models.`
- : 'Endpoint is reachable.'
+ message: response.models.length ? `${reachable} Found ${response.models.length} models.` : reachable
})
} else {
notify({
diff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.ts
index 8190133a49a..694ce0b97ca 100644
--- a/apps/desktop/src/types/hermes.ts
+++ b/apps/desktop/src/types/hermes.ts
@@ -280,6 +280,8 @@ export interface CustomEndpointValidationResponse {
models: string[]
ok: boolean
reachable: boolean
+ /** The transport whose route the backend probed (pinned api_mode, or the runtime's URL auto-detect). */
+ transport_checked?: CustomEndpointApiMode
}
export interface MessagingEnvVarInfo {
diff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.py
index 515bb2ef3cb..d38b4ad91e0 100644
--- a/hermes_cli/web_routers/config_env.py
+++ b/hermes_cli/web_routers/config_env.py
@@ -18,7 +18,7 @@ from hermes_cli.web_server_config import (
_validated_main_model_selection,
)
from hermes_cli.web_server_profiles import (
- _approval_mode_of, _broadcast_gateway_session_info, _is_other_profile, _parse_model_entries, _parse_model_ids,
+ _approval_mode_of, _broadcast_gateway_session_info, _is_other_profile, _parse_model_entries,
)
from fastapi import HTTPException, Request
from hermes_cli.config import DEFAULT_CONFIG, OPTIONAL_ENV_VARS, read_raw_config, custom_endpoint_key_env, coerce_provider_id, find_provider_entry, get_compatible_custom_providers, redact_key, _deep_merge
@@ -772,19 +772,67 @@ async def validate_custom_endpoint(body: CustomEndpointUpdate):
try:
async with _endpoint_probe_client(url, 8.0) as client:
resp = await client.get(url, headers=headers)
+ if resp.status_code in (401, 403):
+ return {"ok": False, "reachable": True, "message": "The endpoint rejected the API key.", "models": []}
+ if not resp.is_success:
+ return {"ok": False, "reachable": True, "message": f"Endpoint returned HTTP {resp.status_code}.", "models": []}
+ # ``models`` stays the bare id list older clients read; ``model_details`` keeps the
+ # alias metadata (``canonical_model`` / ``reasoning_effort``) the id list flattens.
+ entries = _parse_model_entries(resp)
+ ids = [e["id"] for e in entries]
+ # /models answering proves nothing about the transport the runtime will POST to:
+ # a Responses-only host lists models fine and 404s every /chat/completions (#93622).
+ # Probe the route the saved mode (or the runtime's URL auto-detect) actually uses.
+ mode = _canonical_api_mode(body.api_mode or "").lower() or _auto_api_mode(base_url)
+ probe_model = (body.model or "").strip() or (ids[0] if ids else "")
+ missing = await _probe_transport_route(client, base_url, mode, probe_model, headers)
except Exception:
return {"ok": False, "reachable": False, "message": f"Could not reach {url}.", "models": []}
- if resp.status_code in (401, 403):
- return {"ok": False, "reachable": True, "message": "The endpoint rejected the API key.", "models": []}
- if not resp.is_success:
- return {"ok": False, "reachable": True, "message": f"Endpoint returned HTTP {resp.status_code}.", "models": []}
+ result = {"ok": True, "reachable": True, "message": "", "models": ids, "model_details": entries,
+ "transport_checked": mode}
+ if missing:
+ result.update(ok=False, message=missing)
+ return result
+
- # ``models`` stays the bare id list older clients read; ``model_details`` keeps the
- # alias metadata (``canonical_model`` / ``reasoning_effort``) the id list flattens.
- entries = _parse_model_entries(resp)
- return {"ok": True, "reachable": True, "message": "", "models": [e["id"] for e in entries],
- "model_details": entries}
+_TRANSPORT_ROUTES = {"chat_completions": "/chat/completions", "codex_responses": "/responses",
+ "anthropic_messages": "/messages"}
+_TRANSPORT_LABELS = {"chat_completions": "Chat Completions", "codex_responses": "Responses API",
+ "anthropic_messages": "Anthropic Messages"}
+
+
+def _auto_api_mode(base_url: str) -> str:
+ """The transport the runtime falls back to for an endpoint without a pinned ``api_mode``
+ (same resolver as ``runtime_provider_custom._custom_runtime``)."""
+ from hermes_cli.runtime_provider import _detect_api_mode_for_url
+ return _detect_api_mode_for_url(base_url) or "chat_completions"
+
+
+async def _probe_transport_route(client, base_url: str, mode: str, model: str, headers: Dict[str, str]) -> str:
+ """POST a 1-token request to ``mode``'s route; return a failure message when the host does
+ not serve it (404/405/501), ``""`` otherwise. Any other status — 200, 400 (bad body), 401,
+ 422, 429 — means the route exists, which is all the check needs to know; a network error or
+ timeout (a local server still loading the model) is inconclusive and does not block."""
+ route = _TRANSPORT_ROUTES.get(mode)
+ if route is None:
+ return ""
+ if mode == "anthropic_messages":
+ payload = {"model": model, "max_tokens": 1, "messages": [{"role": "user", "content": "hi"}]}
+ token = headers.get("Authorization", "").removeprefix("Bearer ")
+ headers = {**headers, "anthropic-version": "2023-06-01", **({"x-api-key": token} if token else {})}
+ elif mode == "codex_responses":
+ payload = {"model": model, "input": "hi", "max_output_tokens": 16}
+ else:
+ payload = {"model": model, "max_tokens": 1, "messages": [{"role": "user", "content": "hi"}]}
+ try:
+ resp = await client.post(base_url + route, json=payload, headers=headers)
+ except Exception:
+ return ""
+ if resp.status_code not in (404, 405, 501):
+ return ""
+ return (f"{base_url}/models answered, but POST {route} returned HTTP {resp.status_code}: this host "
+ f"does not serve the {_TRANSPORT_LABELS[mode]} API. Pick the API mode it does serve.")
def _endpoint_probe_client(url: str, timeout: float):
@@ -828,12 +876,13 @@ async def validate_provider_credential(body: EnvVarUpdate, request: Request):
resp = await client.get(url, headers=headers)
except Exception:
return {"ok": False, "reachable": False, "message": f"Could not reach {url}."}
- models = _parse_model_ids(resp)
+ entries = _parse_model_entries(resp)
+ models = [e["id"] for e in entries]
if not models and not resp.is_success:
# A proxy/gateway error page parses as "no models"; name the status instead so the
# GUI does not tell the user to "start a model" on a server that answered.
return {"ok": False, "reachable": True, "message": f"{url} answered HTTP {resp.status_code}.", "models": []}
- return {"ok": True, "reachable": True, "message": "", "models": models}
+ return {"ok": True, "reachable": True, "message": "", "models": models, "model_details": entries}
probe = _CREDENTIAL_PROBES.get(key)
if not probe:
diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.py
index d342e01de16..e3ad671fad6 100644
--- a/tests/hermes_cli/test_web_server.py
+++ b/tests/hermes_cli/test_web_server.py
@@ -2130,6 +2130,9 @@ class TestWebServerEndpoints:
async def get(self, url, headers=None):
return FakeResp()
+ async def post(self, url, json=None, headers=None):
+ return FakeResp()
+
@contextlib.asynccontextmanager
async def fake_probe_client(url, timeout):
yield FakeClient()
@@ -2144,6 +2147,60 @@ class TestWebServerEndpoints:
{"id": "gpt-5.6-sol-high", "canonical_model": "gpt-5.6-sol", "reasoning_effort": "high"},
]
+ @staticmethod
+ def _responses_only_host(monkeypatch, posted):
+ """A gateway that lists models on GET /models and serves POST /responses but 404s
+ POST /chat/completions — the #93622 reporter's host."""
+ import contextlib
+
+ from hermes_cli.web_routers import config_env
+
+ class Resp:
+ def __init__(self, status):
+ self.status_code, self.is_success = status, status < 400
+
+ def json(self):
+ return {"data": [{"id": "gpt-5.6-sol"}]}
+
+ class Client:
+ async def get(self, url, headers=None):
+ return Resp(200)
+
+ async def post(self, url, json=None, headers=None):
+ posted.append((url, json))
+ return Resp(400 if url.endswith("/responses") else 404)
+
+ @contextlib.asynccontextmanager
+ async def probe_client(url, timeout):
+ yield Client()
+
+ monkeypatch.setattr(config_env, "_endpoint_probe_client", probe_client)
+
+ def test_custom_endpoint_validate_fails_when_the_transport_route_is_missing(self, monkeypatch):
+ """Test must exercise the leg the runtime will use: a Responses-only host answers /models
+ fine, so validation also POSTs the resolved transport's route and fails on 404 (#93622)."""
+ posted = []
+ self._responses_only_host(monkeypatch, posted)
+ for api_mode in ("", "chat_completions"): # auto-detect resolves to chat_completions here
+ body = self.client.post("/api/providers/custom-endpoints/validate", json={
+ "name": "x", "base_url": "https://gw.example.com/v1", "model": "", "api_mode": api_mode}).json()
+ assert body["ok"] is False and body["reachable"] is True
+ assert body["transport_checked"] == "chat_completions"
+ assert "/chat/completions" in body["message"] and "Chat Completions" in body["message"]
+ assert body["models"] == ["gpt-5.6-sol"], "discovered models still returned so the user can re-pick"
+ assert posted[-1][0] == "https://gw.example.com/v1/chat/completions"
+ assert posted[-1][1]["model"] == "gpt-5.6-sol" and posted[-1][1]["max_tokens"] == 1
+
+ def test_custom_endpoint_validate_passes_when_the_pinned_transport_is_served(self, monkeypatch):
+ posted = []
+ self._responses_only_host(monkeypatch, posted)
+ body = self.client.post("/api/providers/custom-endpoints/validate", json={
+ "name": "x", "base_url": "https://gw.example.com/v1", "model": "", "api_mode": "codex_responses"}).json()
+ assert body["ok"] is True and body["message"] == ""
+ assert body["transport_checked"] == "codex_responses"
+ assert posted == [("https://gw.example.com/v1/responses",
+ {"model": "gpt-5.6-sol", "input": "hi", "max_output_tokens": 16})]
+
def test_custom_endpoint_save_leaves_a_hand_written_env_ref_alone(self, monkeypatch):
"""``api_key: ${MY_KEY}`` is already safe — don't copy it elsewhere.
@@ -5309,6 +5366,10 @@ class TestValidateProviderCredential:
captured["headers"] = headers
return _Resp()
+ async def post(self, url, *args, json=None, headers=None, **kwargs):
+ captured["posted"] = url
+ return _Resp()
+
monkeypatch.setattr("httpx.AsyncClient", _Client)
response = self.client.post(
@@ -5327,6 +5388,7 @@ class TestValidateProviderCredential:
"message": "",
"models": ["local-model"],
"model_details": [{"id": "local-model"}],
+ "transport_checked": "chat_completions",
}
assert captured == {
"url": "http://localhost:8000/v1/models",
@@ -5334,6 +5396,7 @@ class TestValidateProviderCredential:
"Accept": "application/json",
"Authorization": "Bearer local-secret",
},
+ "posted": "http://localhost:8000/v1/chat/completions",
}
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 4657aded112..a9cc172e582 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -194,7 +194,7 @@ Manage providers, models, tools, and credentials from a real UI instead of editi
- **Providers settings pane** — a dedicated place to manage inference providers, with an Accounts / API-keys UX for signing in and storing credentials per provider. Accounts and API keys share the Settings **Applies to** selection: credential reads and edits, OAuth account removal, and sign-in launched here target the selected profile, not the active chat profile. The sign-in flow keeps that target through credential saving and model selection. Changing **Applies to** discards unsaved credential drafts. Closing sign-in cancels polling and ignores late results; a credential write already sent may still finish in its original profile. Externally managed CLI credentials use their own CLI and are not covered by this profile selector. Its **Local Models** view installs and manages an on-device llama.cpp runtime — see [Local Models](./local-models.md).
- **Every provider and model in the menus** — the GUI surfaces the full provider list and every model that `hermes model` knows about, so you pick from the same catalog the CLI sees rather than a curated subset.
-- **Custom endpoints with an API mode** — **Settings → Providers → Custom Endpoints** has an **API Mode** selector (**Auto-detect**, **Chat Completions**, **Responses API**, **Anthropic Messages**) — the same choice `hermes model` offers for a custom provider. It is saved as `providers.<id>.api_mode` in `config.yaml`, so a Responses-only or Anthropic-compatible host is no longer called on `/chat/completions`. **Test** also keeps the alias metadata a gateway advertises in `/v1/models` (`canonical_model`, `reasoning_effort`): picking an alias such as `gpt-5.6-sol-high` saves the canonical model and pins its effort under `agent.reasoning_overrides`.
+- **Custom endpoints with an API mode** — **Settings → Providers → Custom Endpoints** has an **API Mode** selector (**Auto-detect**, **Chat Completions**, **Responses API**, **Anthropic Messages**) — the same choice `hermes model` offers for a custom provider. It is saved as `providers.<id>.api_mode` in `config.yaml`, so a Responses-only or Anthropic-compatible host is no longer called on `/chat/completions`. **Test** checks the transport you will actually use, not just `/v1/models`: it sends a one-token request to the pinned mode's route (or to the mode Auto-detect resolves to) and fails with the transport named when the host does not serve it. **Test** also keeps the alias metadata a gateway advertises in `/v1/models` (`canonical_model`, `reasoning_effort`): picking an alias such as `gpt-5.6-sol-high` saves the canonical model and pins its effort under `agent.reasoning_overrides`.
- **xAI Grok OAuth** — Grok is a first-class OAuth provider in the launcher; sign in through the browser flow like the other OAuth providers.
- **Tool-backend installs from the GUI** — run a tool backend's post-setup install steps directly from the app instead of dropping to a terminal. In the terminal backend picker, selecting a backend marked **Needs setup** asks for confirmation first; declining leaves the current backend selected.
- **Terminal font picker** — choose an installed font in **Settings → Appearance**. Nerd Fonts such as `MesloLGS NF` render Powerlevel10k separators and icons in both interactive and agent terminals; the setting is saved per profile.