A local-first multi-agent app development platform, built on PenguinHarness
Custom models: protocol detection from the base URL
- Date: 2026-08-18
- Type: feature
- Scope:
core,server,web,model-catalog - PR: #324
Custom and user-defined groups are no longer pinned to one protocol: a new custom model starts with no protocol selected, and a Detect action in the Web dialog probes which of AgentHub 0.4.2's generic protocol clients a custom base URL serves and stores it as the entry's client_type. The probe order is openai-responses (OpenAI Responses API) first, then ant-messages (Anthropic Messages API), then openai-chat (Chat Completions; bare openai stays its alias), and the first hit wins.
Server
- New
POST /api/projects/:id/models/detect(owner): probes the base URL sequentially in the order above — the paths and auth headers are exactly what the AgentHub clients construct (POST {base}/responsesandPOST {base}/chat/completionswithAuthorization: Bearer;POST {base}/v1/messageswithx-api-key+Authorization: Bearer+anthropic-version) — and stops at the first protocol the endpoint serves, reporting per-probe outcomes for debugging. - Probes are minimal invalid requests (
{}bodies, 5s timeout each, response bodies read up to 64 KiB so a flooding endpoint is abandoned rather than buffered): zero tokens billed, no model id needed, and keyless probing works — a 401/403 in the protocol's error shape proves the route. Classification separates route-exists (structured API errors, tolerant of OpenAI / Anthropic / vLLM / FastAPI dialects) from route-missing (404/405 by status alone), gateway junk (HTML / non-JSON / shapeless bodies, catch-all 200s), and 5xx (proves nothing about the path). Credential resolution has three layers: the key sent in the request, else the stored key named by the optional paired reference, else the environment variable belonging to the protocol that probe speaks —ANTHROPIC_API_KEYforant-messages,OPENAI_API_KEYfor the two OpenAI protocols, resolved through the sameresolveModelEnvmapping the saved model reads. Resolution is per probe because the protocol is precisely what is being determined. Env values are read server-side only and never reach the browser, the response, or the logs.
Web App
Detect sits at the top-right of the base URL field, next to its label — the same placement idiom as the API key field's "get API key" link — and is always clickable: no API key is needed, because the server resolves the probe credential itself (below). Detection is now only ever user-initiated (this button) or the save-time backstop below: the earlier implicit run on base-URL blur is gone, because with dialogs as the feedback channel a passive trigger would either interrupt the user mid-form or fail with no explanation.
Saving detects first. Confirming the dialog while the protocol is still unset runs detection and then continues the save with the result, with the confirm button locked and reading "Detecting…" for the round-trip. A probe that finds nothing aborts the save and leaves the dialog open, with the toast carrying the reason, so the protocol can be picked by hand or the URL corrected — never a silent save. This is load-bearing: AgentHub resolves an unmatched client type by throwing rather than defaulting, so an entry persisted without a protocol is a model that cannot start.
rowToEntrykeeps the same guarantee for the paths that do not probe (set-default, set-vision-proxy, remove), and preset / vendor entries still persist an empty value so AgentHub keeps inferring from the model id.Both outcomes are toasts — the same non-blocking channel the connectivity test in this dialog already uses (the Toaster portals to
document.bodyatz-[100]against the Modal'sz-50, so a toast raised from inside the open dialog renders above it). A hit names the protocol that was applied; every failure — unreachable, timed out, gateway junk, none of the three served, an unusable URL — shows the SAME short message naming the two things the user can act on, the API key and the base URL. Nothing enumerates protocol names or describes what the endpoint did: "the endpoint responded but…" read as success. The per-probe outcomes stay in the detect endpoint's response for debugging. The success toast belongs to the manual Detect button only — on the save path a hit proceeds silently, since the save it was serving carries straight on. No verdict is rendered in the form at all: the earlier line under the base URL field is gone, so the idle and post-detection layouts are identical.No protocol is preselected in the UI, not just in the data. The suffix shows a "Select protocol" placeholder instead of a path, and no menu row is checked, until a pick or a detection lands (
protocolSelectorValuenow returns null for an unset protocol rather than mapping it toopenai-chat, which had been rendering/chat/completionsas a choice the user never made). The reserved in-field padding measures display width, so the localized placeholder is not under-reserved.The path suffix the dialog already showed inside the right edge of the base URL field (
/responses,/v1/messages,/chat/completions) became the manual protocol picker: the passive grey text turned into a borderless in-field trigger listing the three protocols with the path each appends and a checkmark on the current one, so protocol selection took no new form row. Selection needs no API key, which keeps a keyless endpoint configurable by hand.The suffix tracks the choice live and reflects a run in progress (spinner, and amber when nothing matched or the probe failed) at unchanged width, so the input's reserved padding never shifts. The verdict ("Detected OpenAI Responses; applied", or why nothing matched) appears in the field's own message line only after a run.
Legacy entries keep their stored value:
openaidisplays as Chat Completions without being rewritten until the user picks or a detection applies; vendor-pinned client types outside the generic family keep the read-only note. Moving a model to Custom now keeps a generic protocol client type instead of forcingopenai-chatthe way the earlier grouping fix did.Custom groups infer nothing from the model id. Typing
claude-sonnet-5into a custom group no longer implies the Anthropic client or itsANTHROPIC_*key in the dialog's API-key hint: custom and user-defined groups always fall back to the compatible client. Vendor groups keep routing by id, which is how they actually work.A failed save-time detection no longer blocks the save. It falls back to
openai-chatand saves, with a toast saying that is what happened — detection is an accuracy improvement, not a gate, and refusing to save stranded anyone whose endpoint simply cannot be probed. Nothing unstartable is written either way, since the fallback is a real client.Vision detection, beside the vision switch: sends one 1x1 PNG and a one-word prompt, and turns the switch on when the model answers. A model that answers specifically that it will not take an image turns the switch off (a definitive answer, not an error); a probe that fails on auth or the network leaves the setting untouched and shows the same "check the API key and the base URL". Always clickable, single-flight, toast-only — the protocol control's idiom. New custom models start with vision off. Unlike the protocol probes this is a real, billed completion (an image request cannot be made free), so it runs only on an explicit press, never on save. Server-side
POST /api/projects/:p/models/detect-vision, owner only, with the connectivity test's credential chain.ModelEntry.visionstays a plain boolean: an absent value already means "supported" throughout core, the CLI and the web app, so making it tri-state would have silently downgraded every existing un-annotated entry.
Core
resolveModelEnvroutesant-messagesto theANTHROPIC_*env pair (openai-responses/openai-chatalready resolved toOPENAI_*), so the dialog's env-fallback hint follows the detected protocol per PRN-021.
Docs: the models page (en/zh) gained a "Protocol detection for custom models" section; the configuration and server-api references picked up the new client types and the new endpoint.