# API reference: devices

Device consent layer: robot-side runners, approval requests and approvals, and the driver's telemetry summaries. An agent may make an approval request. Only a human session may sign an approval. No API key can put a policy on a robot.

## GET /v1/devices/signing-key

`getDeviceSigningKey` · scope `none` · The hub's approval verification key

The public half of the key the hub signs device approvals with, as PEM. A robot-side driver (`lucen-device`) pins this key at registration. It verifies every approval token **offline** against it: signature, expiry, audience and the device binding. So a compromised network path between hub and robot cannot forge an approval. This endpoint is public, because nobody can verify against a key they cannot fetch. `ephemeral` is true when the deployment runs without `DEVICE_APPROVAL_SIGNING_KEY` (dev / CI). The key was then generated at process start, and every approval it signs dies with the process.

Responses:

- `200`: The verification key.
- `401`: Missing or invalid credentials.

## GET /v1/devices

`listDevices` · scope `key:read` · List devices

Devices the caller may see: their own and those owned by an org they belong to. No device is public. Newest first; an unknown `owner` is an empty page, not a 404.

Parameters:

- `owner` (query): Only devices owned by this user or org handle.
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of devices.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `422`: Request failed validation.

## POST /v1/devices

`registerDevice` · scope `key:write` · Register a robot-side runner

A robot box declares itself with:

- a name, unique among the owner's connected devices (a disconnected device gives its name back);
- the robot repo it embodies, which must be visible to the caller and of kind `robot`;
- the adapter it drives;
- the **io_contract fingerprints it accepts** (sha256 of the canonical `contract` block of a stamped ONNX manifest);
- the public half of the Ed25519 keypair the driver generated locally. The hub verifies the driver's telemetry signatures against it.

Owner is a user or an org, like a repo. Nothing here grants the device anything. A policy reaches it only through an approval a human signs in the web app. Audited as `device.register`.

Request body: `application/json`, required.

Responses:

- `201`: Device registered.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## POST /v1/device-pairings

`createDevicePairing` · scope `key:write` · Start pairing a robot from the platform

A person (or the owner's `write` key) starts connecting a robot to a robot repo. The answer is a **short code** (`XXXX-XXXX`, Crockford base32, about 40 bits). The code expires after ten minutes and works once. On the robot, `lucen-device pair CODE --hub URL` generates the device's Ed25519 key locally and claims the code (`claimDevicePairing`). No person's API key is ever typed on the robot. What the robot declared then waits for a signed-in person to **confirm** it (`confirmDevicePairing`). Owner is a user or an org, like a repo. `name`, when given, names the device. A device credential cannot start a pairing.

Request body: `application/json`, required.

Responses:

- `201`: Pairing started; `code` is what to type on the robot.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## POST /v1/device-pairings/claim

`claimDevicePairing` · scope `none` · Declare this robot to a pairing: with a code, or to get one

The robot's driver declares itself. It sends the public half of the key it generated, the adapter and its provenance, and the fail-safe probe. It also sends the capability and any contracts it registers. That is what `registerDevice` takes, minus the robot repo, owner and trust mode a person decides. **With `code`** it joins a pairing a person started on the hub. The code is the only credential for this call. A used, expired or unknown code gets the same `404`. **Without `code`** (a robot that ships with the driver) the hub starts the pairing. It answers with a code for the robot to show. A signed-in person opens it on the hub. Either way the pairing is then `claimed` and waits for a person's confirmation. The driver polls `collectDevicePairing`. The call is unauthenticated. So it is counted per caller address (`429` past ten attempts a minute), on top of the anonymous rate limit. Nothing is created until a person confirms.

Request body: `application/json`, required.

Responses:

- `201`: Claimed; waiting for a person. `code` is set when the robot asked for one.
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.
- `429`: Too many claim attempts from this address; retry after `Retry-After`.

## GET /v1/device-pairings/{pairing}

`getDevicePairing` · scope `key:read` · Get a pairing: has the robot joined, and what did it declare?

By id: the person who started it, the owner user or an owner-org member. By code: any signed-in caller holding the code, while the pairing is not yet confirmed. That is how a robot-issued pairing is opened on the hub. The answer carries what the robot declared (adapter and provenance, probe, capability, key fingerprint). It also carries the interface fingerprint the device will pin. So a person can compare the robot's screen with the page before confirming. Anything else is `404`.

Parameters:

- `pairing` (path, required): A pairing id (`dpair_...`) or, while it is not yet confirmed, its code (`XXXX-XXXX`).

Responses:

- `200`: The pairing.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## DELETE /v1/device-pairings/{pairing}

`rejectDevicePairing` · scope `key:write` · Drop a pairing: "Not my robot"

Ends a pairing that is not yet confirmed: an unused code, or a claim nobody recognises. The robot's next poll is `404`. Addressed like `getDevicePairing`; `409` once confirmed (disconnect the device instead). Not audited: nothing was created.

Parameters:

- `pairing` (path, required): A pairing id (`dpair_...`) or, while it is not yet confirmed, its code (`XXXX-XXXX`).

Responses:

- `200`: Rejected.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## POST /v1/device-pairings/{pairing}/confirm

`confirmDevicePairing` · scope `session` · Confirm the robot that claimed a pairing (web session only)

**`session` scope**: a person looks at what the robot declared and says "this is my robot". They look at its key fingerprint on the robot's own screen, its adapter and its probe. No key can look at these. Confirming creates the device (audited `device.register`, by this person) and pins the robot card's interface fingerprint on it. It also sets the device's **trust mode**. The mode is chosen here and delivered to the robot when it collects. Afterwards only the robot itself can change it (`setDeviceTrustMode`). A robot-issued pairing also takes its `robot_repo` (and `owner`) here. `409` unless the pairing is `claimed`, or when the name is taken. `422` for trust mode `registered` with no registered contract.

Parameters:

- `pairing` (path, required): A pairing id (`dpair_...`) or, while it is not yet confirmed, its code (`XXXX-XXXX`).

Request body: `application/json`, required.

Responses:

- `200`: Confirmed; `device_id` is the new device.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## POST /v1/device-pairings/{pairing_id}/collect

`collectDevicePairing` · scope `none` · The robot picks up what a person confirmed

The driver polls with a signature by the key it declared. The signature covers the canonical JSON of `{pairing_id, ts}` (`ts` within five minutes). While a person has not confirmed, the answer is `202` with the pairing. Once confirmed, the answer is `200` **once**. It carries the device (its trust mode included), the hub's approval signing key and the robot interface to pin. It also carries the **device credential**: an API key bound to this device, shown this once. The credential can act only as the device:

- read itself and its approvals;
- post its signed events;
- pull the model repos its live approvals name;
- read its robot card;
- open its endpoint sessions;
- upload its trial logs;
- change its own trust mode.

Anything else is `403`. `disconnectDevice` revokes the credential. Rejected or expired: `404`. Collected already: `409`.

Parameters:

- `pairing_id` (path, required): Pairing id (`dpair_...`), from the claim's answer.

Request body: `application/json`, required.

Responses:

- `200`: Connected; `api_key` is shown this once.
- `202`: Waiting for a person to confirm.
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/devices/{device_id}

`getDevice` · scope `key:read` · Get a device

One device. A device the caller may not see is `404`. The API does not answer `403` for it (see *Visibility*). The answer carries what a live page needs without another call:

- `online` (a signed event within `DEVICE_ONLINE_SECONDS`);
- `running_approval_id`;
- the trust mode;
- the pinned interface fingerprint;
- the device credential's prefix and last use;
- `disconnected_at`.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.

Responses:

- `200`: The device.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## POST /v1/devices/{device_id}/disconnect

`disconnectDevice` · scope `key:write` · Disconnect a device: revoke its credential

The owner cuts the device off, with a session or a `write` key. Neither an agent session's key nor the device's own key can do this. The device credential is revoked at once, and every later call with it is `401`. The device is marked `disconnected_at`. A running approval is asked to stop. No request, approval or event is accepted for the device again (`409`). A driver that meets the `401` mid-run stops its adapter. The trail stays, and the name is free again. The same robot can be connected under it as a new device. Idempotent. Audited as `device.disconnect`.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.

Responses:

- `200`: Disconnected.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## POST /v1/devices/{device_id}/trust-mode

`setDeviceTrustMode` · scope `key:write` · The robot changes its own trust mode

**Only the device**: its own credential, plus a signature by its own key. The signature covers the canonical JSON of `{device_id, trust_mode, ts}` (`ts` within five minutes). On the robot, that is `lucen-device trust MODE`. A person chose the mode when confirming the pairing. After that the hub never flips it, and a session or any other key is `403`. Switching to `registered` with no registered contract is `422`. Audited as `device.trust_mode`.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.

Request body: `application/json`, required.

Responses:

- `200`: Changed (or already so).
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/devices/{device_id}/approval-requests

`listApprovalRequests` · scope `key:read` · List a device's approval requests

Newest first; `status` narrows to one state.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `status` (query)
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of requests.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## POST /v1/devices/{device_id}/approval-requests

`createApprovalRequest` · scope `key:write` · Ask for a policy to be put on a device

An agent or a human **asks**: "model repo X onto device Y for T minutes". The hub pins the request to a specific ONNX and its **current sha256**, out of the repo's own file rows. The ONNX is `onnx_path` (or the repo's single `*.onnx` when omitted). So what the human approves is bytes. Re-pushing a file under the same name does not change what they approved.

When the model repo carries an `io_contract.json` sidecar, the hub fingerprints its `contract` block. It refuses (`409`) a request the device has already said it will not accept. A human should not be asked to approve what the robot will refuse. Without a sidecar the fingerprint is null, and the driver's own check on the ONNX manifest decides.

A request is a trial (`mode: run`) or an install (`mode: install`). It records the skill `slot` the file goes into. On a Laika, and on any robot with pre-deploy checks, a request without a slot gets one from the file. The hub uses the slot the file's signed manifest names. It reads a manifest only from bytes it has verified. There, a dry run of a file still being verified is `409`. A request of such a file that names no slot is `409` too. On those robots every request needs a slot, here or in the manifest (`422` without one). A dry run is still answered, and its sim check says why. Elsewhere only an install needs a slot (`422`). Only a Laika or a robot with pre-deploy checks gets it from the manifest. A request for an endpoint is a trial only (`422`). On a Laika, a trial is at most 60 minutes (`422`).

A device in **trust mode `approved`** also runs a contract it never registered. This needs a signed approval naming it, and a policy built for the robot interface the device pinned. The hub then answers `201` when the model's recorded `embodiment_fingerprint` equals the device's `interface_fingerprint`. It also answers `201` for an **unstamped** policy. That policy's approval then requires the approver's explicit `unstamped_acknowledged`. The device additionally compares the policy's joint order with its pinned interface. A policy built for another embodiment, or a device that pinned no interface, is still `409`. `checks[]` says which way the contract was established. A disconnected device is `409`.

The request appears in the web app as a pending card. **Nothing moves until a person approves it there.** `key:write`: it is a data mutation, and it grants nothing. A session files and then approves in two calls (one-step deploy by a person). Audited as `device.request`.

With `dry_run: true` nothing is filed or audited. The answer is `200` with the request as it would be, and `checks[]`, `device` and `model` filled. That is what a deploy page shows before anything exists. There, a contract the device would refuse is a `fail` check instead of the `409`.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.

Request body: `application/json`, required.

Responses:

- `200`: `dry_run`: the request as it would be filed, with its checks; nothing stored.
- `201`: Request recorded, status `pending`.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/devices/{device_id}/approval-requests/{request_id}

`getApprovalRequest` · scope `key:read` · Get an approval request

The consent page in one call. Besides the request itself, the answer carries:

- who asked and with which credential (`requester`, and `plan` when a plan's planner filed it);
- the device it is for (`device`);
- what would run (`model`, and `endpoint` when the request is endpoint-bound and the endpoint is visible to the caller);
- `checks[]`: what the hub verified against the current state of the hub, computed now.

The checks cover:

- the device's accepted contracts;
- the control class and where it would run;
- the device's declared fail-safe probe;
- the latest sim-gate scorecard for this model on this robot;
- the policy's embodiment fingerprint against the robot's interface;
- whether the pinned bytes are still what the repo (or endpoint) serves.

Absent evidence is reported as `absent`. It is never reported as a pass. Checks inform the person deciding. None of them approves or blocks anything.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `request_id` (path, required): Approval request id (`dreq_...`).

Responses:

- `200`: The request.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## POST /v1/devices/{device_id}/approval-requests/{request_id}/deny

`denyApprovalRequest` · scope `session` · Deny an approval request (web session only)

A human says no. **`session` scope**: denying is a decision on the same footing as approving. No API key of any scope may take it. Otherwise an agent could clear its own trail of refused requests. `409` when the request is no longer pending. Audited as `device.deny`.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `request_id` (path, required): Approval request id (`dreq_...`).

Request body: `application/json`.

Responses:

- `200`: Denied.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/devices/{device_id}/approvals

`listApprovals` · scope `key:read` · List a device's approvals

Newest first. `status=issued` is what a driver polls: approvals a human has signed that have neither been picked up nor expired. The token is returned on every read. It is a signed statement about one device and does not work as a hub credential. Only that device's driver can use it. `device_id` may be `-` for every device the caller can see. `model_repo` narrows the list to one model: where a model has run.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `status` (query)
- `model_repo` (query): `owner/slug` of a model repo; one you cannot read is an empty page.
- `mode` (query): `run`, the default, lists trials only. That is what an older driver polls, so it never sees an `install` approval. `install` lists approvals to keep a policy. `shadow` lists shadow runs. `any` lists every mode.
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of approvals.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## POST /v1/devices/{device_id}/approvals

`createApproval` · scope `session` · Approve a pending request and mint the signed token (web session only)

**`session` scope: a human, signed in to the web app. No API key of any scope can call this.** That is the whole invariant of the consent layer. The hub's programmatic credential can browse, push and *ask*. It cannot put a policy on a robot. Approving a `pending` request mints a short-lived **EdDSA (Ed25519) JWT**. The token is bound to the device id (`sub`), the model repo, and the ONNX path and its sha256. It is also bound to the contract fingerprint, the approver and `exp = now + minutes`. The driver verifies it offline against `GET /v1/devices/signing-key`. The approval's window **is** the run window. A policy picked up late runs for what is left of it. The driver stops it at `expires_at` on its own clock. `409` when the request is not pending or the device is disconnected. On a trust-mode-`approved` device whose request rests on an unstamped policy, `unstamped_acknowledged: true` is required (`422` without it). It is signed into the token. The approver may shorten the window with `minutes` (`422` above what was asked). On a device whose organization requires a second person (`Org.require_second_approver`), the person who asked cannot approve: `403`. Audited as `device.approve`.

On a Laika, and on any robot with pre-deploy checks, the repo must still hold the pinned file (`422` once it changed, `409` while the hub checks its bytes). A request for an endpoint skips this check. On those robots, a request that names no slot has no sim test, so it is `422`. On a robot the hub runs pre-deploy checks on, a file Lucen has not certified needs its sim test, with a score. The approval names the request's `report_rollout_id` and sets `report_acknowledged` (`422` without them). A file Lucen certified needs neither, in the slot Lucen certified it for. In another slot it is `422`. Lucen's word counts on any Laika. On any other robot, a `report_rollout_id` the approver gives must still be the request's (`422`). A second person is required as before, for a certified file too. On a Laika, a trial is at most 60 minutes (`422`). The token signs `mode`. It also signs `slot`, `report_rollout_id` and `certified` when they are set.

**The gate, one rule for the web, the CLI and MCP.** The hub computes the request's checks (`ApprovalRequest.checks`) as the approver reads them. It refuses while any one is `fail`. That covers an incompatible policy (`device.contract`, `embodiment.fingerprint`, `artifact.digest`). It covers firmware below the robot's minimum or on its blocked list (`firmware.version`). It covers a file with no pre-deploy report that Lucen has not certified (`sim_gate.scorecard`, on a robot the hub runs pre-deploy checks on). Each refusal is RFC 9457 problem+json. Its `errors[]` carry one entry per failed check, with the check code as `type` and its sentence as `msg`. A report with failed tests needs `report_acknowledged` (`422` without it, `type: sim_gate.scorecard`). A report every test of which passed does not. A runtime-release mismatch (`runtime.release`) warns and does not refuse. A robot whose card declares no firmware has no firmware check. Every other rule is the same on every robot.

**A shadow request** (`mode: shadow`) meets the compatibility checks and no others. Shadow moves nothing, so the sim report is not required and no tick is asked for. The contract, the embodiment fingerprint, the firmware and the pinned bytes still refuse: a candidate the robot cannot load, or that reads the wrong layout, teaches nothing. A `run` approval gets a `bringup` ladder. Its first rung is ticked by a finished shadow run of the same file on the same device within the last 24 hours.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.

Request body: `application/json`, required.

Responses:

- `201`: Approved; `token` is what the driver verifies.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/devices/{device_id}/approvals/{approval_id}

`getApproval` · scope `key:read` · Get an approval

The approval, token included, plus what a live page polls: `seconds_left` in the window, `stop_requested_at`, and the latest heartbeat while it runs.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `approval_id` (path, required): Approval id (`appr_...`).

Responses:

- `200`: The approval, token included.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## POST /v1/devices/{device_id}/approvals/{approval_id}/stop

`stopApproval` · scope `session` · Stop a deployment now (web session only)

The STOP button. A signed-in person who can see the device ends an approval before its window does. No API key of any scope may call it. Approving, confirming and stopping a deployment are a person's decisions. So no agent and no device credential can stop a robot either. There is no MCP tool for it. An `issued` approval ends at once (`stopped`; it can never start). A `running` one gets `stop_requested_at`, and it can never start again. The driver reads the field off its next heartbeat's answer, every two seconds by default. It calls the adapter's `hold()` when the adapter has one, then `stop()`, and posts a signed `stopped` with reason `stop_requested`. So a stop lands within one heartbeat interval plus two network round trips, while the robot can reach the hub. A robot that cannot reach the hub stops the policy itself about ten seconds after it loses the hub. It hears the stop when the link returns. **This is not a safety system.** The safety system is a person at a hardware emergency stop. Idempotent while running; `409` on an approval that already ended, unless the robot has reported running since the hub ended it (then the flag is set again). Audited as `device.stop`, with the person who pressed it.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `approval_id` (path, required): Approval id (`appr_...`).

Request body: `application/json`.

Responses:

- `200`: Stopped (`issued`) or stop requested (`running`).
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## POST /v1/devices/{device_id}/approvals/{approval_id}/rungs/{n}

`tickRung` · scope `session` · Tick a rung of the bring-up ladder (web session only)

**`session` scope**, like approving: no API key of any scope can call it. The person at the robot, from their phone, attests that the rung went right. The approver, or any member of the organization that owns the device, may tick. Rungs 1 to 3 are ticked in order while the approval is `running`. Rung 0 (shadow) is satisfied by a finished shadow run, and can only be skipped here, with a reason. The robot is asked to do nothing: it behaves the same at every rung, and the hub records what the person attested. A tick after the rung's own window is still taken; the window is informational and extends nothing. The driver reads the tick off its next heartbeat's answer (`rungs_ticked`) and acknowledges it with a signed `rung` event. Audited as `device.rung`. `409` on a rung already ticked or out of order, and on an approval that is not running. `422` on a skip without a reason, or a skip of rung 1 to 3.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `approval_id` (path, required): Approval id (`appr_...`).
- `n` (path, required): The rung, 0 to 3.

Request body: `application/json`.

Responses:

- `200`: The approval with its ladder.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/devices/{device_id}/approvals/{approval_id}/shadow

`getApprovalShadow` · scope `key:read` · The shadow run's trace and stats

What the robot reported during a shadow approval: the predicted and the applied joint targets over time, thinned to at most `points` samples, the latest stats and how it ended. The hub stores every trace sample the robot sent and thins on read. Under the device's rule: an approval you may not see is `404`. `409` on an approval that is not a shadow run.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `approval_id` (path, required): Approval id (`appr_...`).
- `points` (query): The most samples to return; the hub thins evenly to it.

Responses:

- `200`: The trace, thinned, with the stats.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## POST /v1/devices/{device_id}/slots/{slot}/restore

`restoreSlot` · scope `session` · Put a slot's previous policy back (web session only)

**`session` scope**, like approving: no API key of any scope can call it. One press on the live view or the fleet page. The hub finds the slot's newest `installed` approval and the one before it. It files an `install` request for that previous file, its path and the digest it installed, through the same path as `createApprovalRequest` (`device.request` audited). It then approves that request at once as the person pressing, through the same gate `createApproval` runs. The previous approval's report and acknowledgment carry over when that report is still the file's bound one. A report the person has not acknowledged is refused the way `createApproval` refuses it. The robot verifies the signed token and installs as it does any install. Audited as `device.approve` with `restore_of` naming the approval it replaces. `409` when the hub installed nothing before the current file in this slot; the robot's own `laika policy rollback` is the way back to a factory file. Also `409` when the device is disconnected, or when the previous file's bytes are no longer in its repo. `422` from the gate, with the failed check codes. `403` under a second-person rule when the person pressing filed the current install.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `slot` (path, required)

Request body: `application/json`.

Responses:

- `201`: The install approval for the previous file; the robot picks it up.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/devices/{device_id}/events

`listDeviceEvents` · scope `key:read` · List a device's events

Newest first; `approval_id` narrows to one approval's trail.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.
- `approval_id` (query)
- `kind` (query)
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of events.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## POST /v1/devices/{device_id}/events

`postDeviceEvent` · scope `key:write` · Record a telemetry summary from the driver

The driver's four words back to the hub about one approval: `started`, `heartbeat` (a few scalars), `stopped` or `refused`. A `refused` event carries the reason (bad signature, expired, wrong device, digest mismatch, contract mismatch). Events are summaries. They carry no control. The body is capped at 64 KiB, and nothing here reaches the robot. Every event is **signed with the device's own Ed25519 key** (`signature` over the canonical payload). The hub verifies it against the key registered for the device. So a `started` row is evidence from the box that holds the private key. Holding the hub API key alone cannot produce one. Transitions are checked: `started` needs an `issued`, unexpired approval; `heartbeat` and `stopped` need `running`; `refused` needs `issued`. `installed` needs an install approval (`409` on a trial). It is taken while `issued`, and also once the pickup window has passed. Its summary must name the approval's `sha256` and `slot`. `activated` must be a boolean, and `via` is `cli` or `serve`. Any other summary is `422`. The answer carries the approval's `stop_requested_at`. A driver reads a person's Stop off its next heartbeat. `key:write`: a row is a data mutation, and the driver's key still cannot approve anything. `started`/`stopped`/`refused`/`installed` are audited (`device.started` / `device.stopped` / `device.refused` / `device.installed`). Heartbeats are not audited.

Two kinds since the bring-up ladder. `rung` is the robot's signed acknowledgment of a rung a person ticked; it needs `running`. Its summary names `n` and `name`. `status` is the robot's report of itself with no approval running: `approval_id` is null, and the summary carries the adapter's status. The hub keeps the firmware, runtime, hardware id and slots it reports. The driver posts one on start, when those change, and otherwise at most every 15 minutes. Neither is audited. The answer also carries `rungs_ticked`: the rungs a person ticked that the robot has not acknowledged yet.

`recording` is the bridge's progress while a person records demonstrations on the robot. `approval_id` is null. The hub checks the summary's keys and their types, and the signed `ts` must be within five minutes of the hub's clock (`422` otherwise). It is not audited. `listDeviceEvents` with `kind=recording` and `limit=1` is the latest progress.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.

Request body: `application/json`, required.

Responses:

- `201`: Event recorded.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `413`: The summary exceeds 64 KiB.
- `422`: Request failed validation.

## GET /v1/approval-requests/{request_id}

`getApprovalRequestById` · scope `key:read` · Get an approval request by its id alone

`getApprovalRequest` without the device in the path. The consent page has a URL of its own (`/inbox/requests/{id}`), and a link to it carries only the request id. Same body (device, model, endpoint and `checks[]` computed now) and the same rule. A request on a device the caller cannot see is 404. The API does not answer 403 here, because that would confirm the request exists.

Parameters:

- `request_id` (path, required): Approval request id (`dreq_...`).

Responses:

- `200`: The request, with everything a person needs before deciding.
- `401`: Missing or invalid credentials.
- `404`: Resource not found (or hidden from the caller).

## POST /v1/devices/{device_id}/bridge-tickets

`createBridgeTicket` · scope `session` · Get a ticket that pairs a web page with the robot's bridge

The hub's web page asks for a ticket, then posts it to the bridge on the person's computer (`POST /v1/web/pair` there). The ticket is an EdDSA token signed with the hub's device-signing key. It names the device, the person and the page's origin, and it expires after 120 seconds. The bridge verifies it offline with the key it pinned at registration, and takes each ticket once. The origin is the request's `Origin` header, or `origin` in the body. It must be one of this hub's own web origins (`422` otherwise). Only a signed-in person gets one: a paired page can record on the robot, so no key of any scope pairs a page. The caller must see the device (`404` otherwise). Audited as `device.bridge_ticket`.

Parameters:

- `device_id` (path, required): Device id (`dev_...`). `listApprovals` and `listLiveControl` also take `-`, every device you can see.

Request body: `application/json`.

Responses:

- `201`: The ticket.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.
