Files
hermeven/docs/bridge-api.md
T
DanandClaude Fable 5.2 9874e1bb5b Answers read aloud: Voice on the menu, ElevenLabs voices per agent via the bridge (0.5.0)
- bridge: GET /v1/speech (which agents have a voice) and GET /v1/turns/{id}/speech (MP3 of the
  caller's own finished answer, markup removed, first 900 characters). ElevenLabs adapter; key
  and voice ids from the environment; per-device budget; last three clips kept in memory.
  speech.done / speech.failed log ids, lengths and durations only.
- bridge: forceCloseConnections. A request the client had abandoned kept shutdown waiting for
  ever (also true of /v1/transcribe as deployed). Regression test for both routes.
- client: 'Voice: off/on' on the opening menu when the bridge offers it and the page can play
  sound; off at every launch. With it on, a finished answer is fetched and played; it stops
  when the answer leaves the screen; the app does not leave the glasses while it plays.
- tests: fake provider, fake loudspeaker (tests/integration/voice.test.ts).
- docs: 0006, security 3g-3i, device plan E, 0.4.1 rollout and Dan's sound check report.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-29 12:11:38 -08:00

10 KiB

Bridge API, contract v1

These endpoints are Hermeven's own. They are not Hermes or Even APIs. Schemas live in packages/contracts/src/schemas.ts and are enforced on every request; the client validates every response against the same schemas.

All routes except /healthz and /v1/pairing/claim require Authorization: Bearer <device token>. Every error has the shape:

{ "schema_version": 1, "error": { "code": "conversation_busy", "message": "...", "retryable": true } }
Method and path Purpose Success
GET /healthz Liveness only. Returns {"status":"ok","schema_version":1} and nothing else. 200
POST /v1/pairing/claim Exchange a single-use pairing code for a device credential. 201
GET /v1/device Pairing status, limits, whether the agent is reachable and STT is configured. 200
POST /v1/device/renew Rotate the device token. The old token stops working at once. 200
DELETE /v1/device Revoke this device and close its conversation. 200
GET /v1/agents The agents this device may talk to, default first: {agents: [{id, name}]}. Ids and display names only; no address, profile or key. Added after 0.1.x: an older bridge answers 404 not_found, which a client must treat as "one agent". 200
POST /v1/conversations Start a new conversation. Optional agent_id (an id from /v1/agents; omitted = the default agent; anything else is 400 invalid_request). Closes the device's previous conversation with that agent only. 201
POST /v1/turns Create one turn (text or audio). 202, or 200 for a duplicate
POST /v1/wake One stretch of speech heard while the app was open (raw audio body, same format as an audio turn; query: schema_version, locale, encoding, sample_rate, channels). Transcribed in memory and dropped. Answers {matched, agent_id, text, near_miss}: whether it began with an agent's name, which agent, and what was said after the name (empty for the name alone). When not matched text is always empty; near_miss is the first word if it was close to a name. Creates no turn and sends nothing to any agent. 404 not_found when speech-to-text is off or no agent has a usable name (also what an older bridge answers); 429 rate_limited over HERMEVEN_WAKE_CHECKS_PER_MINUTE (default 30) or while this device's previous check is still running. A failed transcription is answered as not matched. 200
POST /v1/transcribe The words in a recording that is still being made, for showing while the user speaks. Same body and query as /v1/wake. Answers {text} (empty if nothing was recognised or transcription failed). Transcribed in memory and dropped; creates no turn, sends nothing to any agent, logs no text. 404 not_found when speech-to-text is off (also what an older bridge answers); 429 rate_limited over HERMEVEN_PREVIEWS_PER_MINUTE (default 60) or while this device's previous preview is still running. 200
GET /v1/speech Whether answers can be read aloud: {available, agent_ids, max_chars}. available is false (and the list empty) unless the bridge has a speech provider key and at least one agent has a voice. Added in 0.5.0: an older bridge answers 404 not_found, which a client must treat as "not available". 200
GET /v1/turns/{request_id}/speech The answer of one of this device's own finished turns (succeeded or incomplete), read aloud in its agent's voice. The response is audio/mpeg, not JSON. The text is the answer with markup, code blocks and web addresses removed, cut to HERMEVEN_SPEECH_MAX_CHARS (default 900) at the end of a sentence where one is near; it is sent to the speech provider (ElevenLabs). Neither text nor audio is stored or logged; the last three are kept in memory so a repeat is not paid for twice. There is no way to have other text spoken. 404 not_found for an unknown, foreign or unfinished turn, an answer with nothing to read, an agent without a voice, or speech not configured (all indistinguishable); 429 rate_limited over HERMEVEN_SPEECH_PER_MINUTE (default 6) new syntheses per device; 500 internal "Speech could not be generated." when the provider fails (its message is never passed on). 200
GET /v1/turns/{request_id} Current state and result. 200
POST /v1/turns/{request_id}/cancel Request cancellation. Idempotent. 200

There is no SSE endpoint. Streaming through the Even WebView is undocumented and untested, so polling is the supported path.

More than one agent

The bridge can be given further agents besides the default one. Each is another profile served by the same Hermes gateway (gateway.multiplex_profiles), reached at <HERMES_BASE_URL>/p/<profile> with that profile's own API_SERVER_KEY; Hermes refuses the default profile's key there.

HERMEVEN_AGENT_NAME=Pepper                 # display name of the default agent (default: Agent)
HERMEVEN_AGENTS=wendy,cody                 # extra agent ids, in display order
HERMEVEN_AGENT_WENDY_API_KEY=...           # required for each extra agent
HERMEVEN_AGENT_WENDY_PROFILE=wendy         # optional; default: the id
HERMEVEN_AGENT_WENDY_NAME=Wendy            # optional; default: the id, capitalised
HERMEVEN_AGENT_WENDY_WAKE=wendi,windy      # optional; extra spoken forms of the name
HERMEVEN_AGENT_WAKE=peper                  # the same, for the default agent

An agent is called by voice with the first word of its name ("Cody R." answers to "cody"), plus any aliases. The default agent answers to its name only once HERMEVEN_AGENT_NAME is set. Two agents may not answer to the same word. Wake words are never sent to a client. See docs/decisions/0004-always-listening.md.

The list is the owner's allow-list. A client names an agent only by id, only when creating a conversation, and the id is checked against the list; it is never used to build an address. A turn goes to the agent of its conversation. Each agent has its own conversation and its own Hermes session, so nothing said to one is sent to another. /v1/device is unchanged, and its active_conversation_id and agent_reachable describe the default agent.

Creating a turn

Typed text (Content-Type: application/json):

{
  "schema_version": 1,
  "request_id": "0b9f6c1e-3c1d-4b1e-9a51-2f6d0f4c8a11",
  "conversation_id": "5d0c2c35-6a8f-4f0e-8f55-0d1f7c0b2a90",
  "locale": "en-US",
  "input": { "kind": "text", "text": "What is on my calendar tomorrow?" }
}

Audio (Content-Type: application/octet-stream): the body is the raw PCM, and the metadata is in the query string. Audio is never placed in JSON.

POST /v1/turns?schema_version=1&request_id=...&conversation_id=...&locale=en-US
     &input_kind=audio&encoding=pcm_s16le&sample_rate=16000&channels=1
Rule Value
Accepted audio pcm_s16le, 16000 Hz, 1 channel. Anything else: 415 unsupported_media.
Maximum audio capture cap + 1 second, 992,000 bytes at the default 30 s. Larger: 413.
Maximum text 4,000 characters
Unknown fields rejected (400). A client cannot name a Hermes session or profile.
Rate 20 new turns per minute per device by default. Duplicates do not count.

request_id is generated by the client and is the idempotency identity. Submitting the same id with the same content returns the existing turn with "replayed": true. The same id with different content, or from another device, returns 409 request_id_conflict.

Turn result

{
  "schema_version": 1,
  "request_id": "...",
  "conversation_id": "...",
  "state": "done",
  "terminal": true,
  "outcome": "succeeded",
  "cancel_requested": false,
  "input_text": "what is on my calendar tomorrow",
  "answer_text": "...",
  "error": null,
  "replayed": false,
  "created_at": "2026-11-18T18:00:00.000Z",
  "updated_at": "2026-11-18T18:00:04.210Z",
  "timings": { "transcribe_ms": 640, "agent_ms": 3410 }
}
  • state: accepted, transcribing, thinking, approval_required, cancelling, done.
  • outcome (when terminal): succeeded, incomplete, failed, cancelled, unknown.
  • answer_text is the agent's complete answer. The bridge never shortens it.
  • input_text and answer_text become null once the retention window passes.
  • An HTTP 200 only means the bridge answered. Read terminal and outcome.

Error codes

Defined in packages/contracts/src/errors.ts. Codes are stable; a code is never repurposed.

Code Meaning Retryable
invalid_request, unsupported_schema_version, unsupported_media, payload_too_large The request was malformed. no
unauthorized, credential_expired, forbidden Credential missing, revoked or expired. no
pairing_invalid The pairing code was wrong, expired or already used. The answer is identical in all three cases. (pairing_locked is reserved and no longer returned.) no
not_found Unknown, or belongs to another device. no
request_id_conflict Request id reused for different content. no
conversation_busy A turn is still running in this conversation. yes
conversation_closed The conversation was replaced or the device was revoked. no
rate_limited Too many requests. yes
stt_unavailable, stt_failed, stt_timeout, stt_empty Transcription did not produce text. Nothing reached the agent. yes
interrupted_before_agent The bridge restarted before sending. Nothing ran. yes
agent_unreachable Hermes never received the request. Nothing ran. yes
agent_rejected Hermes refused the request. Nothing ran. no
agent_failed, agent_interrupted The agent ran and failed or was interrupted. Actions already taken are not undone. no
agent_timeout, approval_timeout The bridge stopped the run after a deadline. no
agent_incomplete The agent stopped short; the answer is partial. no
outcome_unknown The bridge cannot tell whether the turn ran. Check the agent first. no

Operating budgets

Defaults, all configurable. These are limits, not measured performance.

Budget Default
Capture 30 s
Transcription deadline 30 s
Agent deadline 120 s, paused while an approval is pending
Approval wait 300 s
Grace period to confirm a stop 30 s
Speech provider deadline 20 s
Answer read aloud first 900 characters, 6 answers a minute per device

No latency percentiles are published because none have been measured against a real STT provider, a real model or a real device.