# 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 `. Every error has the shape: ```json { "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 | | `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 `/p/` 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 ``` 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`): ```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 ```json { "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 | No latency percentiles are published because none have been measured against a real STT provider, a real model or a real device.