# API reference: trials

Real-robot trials: a session of trials on one device. Each trial is a checkpoint run under its own device approval, with a run sheet locked at approval. The driver uploads the log and summary, signed with the device key. The operator adds notes from a phone. A person gives a verdict (promote / iterate / stop) that the campaign's rules read.

## GET /v1/trial-sessions

`listTrialSessions` · scope `key:read` · List real-robot sessions

Newest first. No session is public. A session is visible to its owner (the campaign's, else the device's) and the owner org's members. Filters narrow within that.

Parameters:

- `campaign` (query): A campaign id or slug.
- `device_id` (query)
- `status` (query)
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

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

## POST /v1/trial-sessions

`createTrialSession` · scope `key:write` · Plan a real-robot session: one trial per checkpoint, in bracket order

A session is a sequence of **trials** on one device. Each trial is a checkpoint run under its own device approval. The hub writes down their order before anything runs. The control runs first. The candidates follow by ascending sim risk (fewer locked gates passed, then fewer seeds upright, runs later). The control runs again last. This is an A/B/A bracket (`700 → A800 → 700`). Its rule is checked once both control runs have a log (`TrialSession.bracket`).

Each trial gets a **run sheet** drafted from the review. It lists the stages (hang → floor → teleop), gain profile, kd and power scale, and the environment. It also lists the abort rules and the criteria the log will be judged against. Its predictions are copied from the round's locked gates, with the sim conditions they were measured under. The sheet is editable until its approval is issued, and locked then (`RunSheet.locked_at`). The token carries the sheet's digest.

With a `device_id`, the hub files one consent request per trial at once. It does the same when exactly one of the owner's devices embodies the robot and accepts every trial's contract. The hub files requests only and issues no approval. `decideRound {shortlist}` calls this for the round it shortlists. An agent's shortlist files its requests through the same trials. `key:write`: a plan and requests a person must still approve, one by one.

Request body: `application/json`, required.

Responses:

- `201`: The session, its trials and their run sheets.
- `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/trial-sessions/{session_id}

`getTrialSession` · scope `key:read` · Get a real-robot session: its order, bracket check and trials

Parameters:

- `session_id` (path, required): A real-robot session id (`tses_...`).

Responses:

- `200`: The session.
- `401`: Missing or invalid credentials.
- `404`: Resource not found (or hidden from the caller).

## POST /v1/trial-sessions/{session_id}/requests

`fileTrialRequests` · scope `key:write` · File the consent requests of a session's unfiled trials

For a session created without a device: names the device and files one device consent request per trial that has none. A session has no device when none of the owner's devices accepted every contract, or several did. Each request is pinned to the checkpoint's ONNX and its digest, and carries the session's reason. A contract the device does not accept is `409` naming the trial, and nothing is filed. Idempotent: a trial that already has a request is left alone. Never approves anything.

Parameters:

- `session_id` (path, required): A real-robot session id (`tses_...`).

Request body: `application/json`, required.

Responses:

- `200`: The session, with the trials' requests.
- `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/trials

`listTrials` · scope `key:read` · List trials

Newest first, under the session's visibility rule. `status=needs_verdict` is what the Inbox's "needs your verdict" card reads. `approval_id` is how a driver finds the trial an approval belongs to.

Parameters:

- `session_id` (query)
- `campaign` (query): A campaign id or slug.
- `device_id` (query)
- `approval_id` (query)
- `status` (query)
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

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

## GET /v1/trials/{trial_id}

`getTrial` · scope `key:read` · Get a trial: run sheet, approval, log, summary, criteria, notes, verdict

One real-robot trial as a record. `criteria` are judged on every read, from the uploaded summary, against what was written down before the run. Those are the run sheet's criteria (locked with its approval) and the round's locked gates the log can measure. Each comes with the sim measurement beside it. A comparison with the session's control trials is `pending` until one of them has a log. `log.files[].url` are presigned GETs (1 h). Invisible is `404`.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).

Responses:

- `200`: The trial.
- `401`: Missing or invalid credentials.
- `404`: Resource not found (or hidden from the caller).

## PATCH /v1/trials/{trial_id}/run-sheet

`updateTrialRunSheet` · scope `key:write` · Edit a trial's run sheet before its approval locks it

Partial: a key that is absent is unchanged, and `null` clears an optional one. Stages, gain profile, kd and power scale, environment, abort rules and criteria may change until the trial's approval is issued. From then on the sheet is what a person approved, and this is `409` ("no tuning on site"). The approval token carries the locked sheet's digest (`run_sheet_sha256`). The driver refuses a sheet that does not hash to it.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).

Request body: `application/json`, required.

Responses:

- `200`: The trial, with the edited run sheet.
- `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/trials/{trial_id}/log/presign

`presignTrialLog` · scope `key:write` · Presigned PUTs for the log files a driver will upload

The driver's first step after a trial's run stops: one presigned PUT (1 h) per log file, under `trials/{trial_id}/log/`. Bytes never pass through the API. Allowed only while the trial's approval is running or stopped and no log has been recorded. The upload becomes a record only when `uploadTrialLog` names each file's sha256 under the device's signature.

**Storage.** The declared sizes count toward the trial session owner's storage quota (`STORAGE_QUOTA_BYTES`, the same 50 GiB as repo files). Over it is `413`, and no URL is issued.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).

Request body: `application/json`, required.

Responses:

- `200`: One PUT per file.
- `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`: A file is over `TRIAL_LOG_MAX_BYTES`, or the session owner's storage quota would be exceeded.
- `422`: Request failed validation.

## POST /v1/trials/{trial_id}/log

`uploadTrialLog` · scope `key:write` · Record the log and summary the driver computed on the robot, signed

The driver's word on what the robot-side command wrote. It reports one of these:

- `state: uploaded` carries each file's sha256, bytes and rows, and the summary the driver computed on the box. The summary gives tilt mean and max over the log's steady second half, and the worst left–right joint asymmetry. It adds per-joint tracking error and the motor temperatures the command printed at stop. It also gives battery, falls, what stopped the command and the stages it ran.
- `missing` / `malformed` carries the reason, so a failure is always stated.

**Signed with the device's own Ed25519 key** over the canonical payload (`trial_log_payload`: approval, device, trial, state, files, summary, stages, detail, ts). The hub verifies it against the key registered for the trial's device, exactly like `postDeviceEvent`. The hub then hashes every uploaded object and refuses (`422`) a file whose bytes do not match the signed digest. It re-derives the log's own numbers (tilt, asymmetry, tracking) from the CSV and stores whether they agree (`summary.hub_check`). Once only (`409` after), while the approval is running or stopped. Audited `trial.log`.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).

Request body: `application/json`, required.

Responses:

- `201`: The trial, with its log and summary.
- `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 the device event cap (64 KiB) or a file its cap.
- `422`: Request failed validation.

## GET /v1/trials/{trial_id}/series

`getTrialSeries` · scope `key:read` · The log as plottable series: tilt at 50 Hz, joints on request

The series come from the uploaded log files: every stage, on the trial's own clock, with the stage boundaries. They are decimated like `getEpisodeSeries`: min/max per bucket, so a one-frame tilt spike survives. `channels` picks what to return: `tilt` (degrees, from the logged gravity vector, `acos(−g_z)`), `q:<joint>`, `tgt:<joint>`, `act:<joint>`. The default is `tilt`. `409` while no log is recorded.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).
- `channels` (query): Comma-separated channel names (default `tilt`).
- `max_points` (query)

Responses:

- `200`: The series.
- `401`: Missing or invalid credentials.
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## PATCH /v1/trials/{trial_id}/notes

`putTrialNotes` · scope `key:write` · Save the operator's notes: a partial autosave

The phone form's autosave. A key that is absent is unchanged, and `null` clears it. The response carries `filed_at` (the time of this save), so the form can say "notes saved 14:33". Fields are taps: stability 1–5, drift, four toggles, and which motors were hot. Free text sits beside them, kept in the language it was written in (`lang`, detected when absent). A machine translation (`translation`), when the hub has one, is labelled as one. It never replaces the text. This hub fills it from recorded fixtures only (no live model call). The first save is audited `trial.notes`, and later saves update the same record. Notes may be filed from the moment the trial is approved, and until its verdict.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).

Request body: `application/json`, required.

Responses:

- `200`: The notes as saved.
- `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/trials/{trial_id}/notes/videos

`presignTrialVideo` · scope `key:write` · Start a phone video's presigned multipart upload

One multipart upload under `trials/{trial_id}/videos/`, straight from the phone to object storage (presigned multipart, 8 MiB parts, 1 h URLs). `completeTrialVideo` takes the part list from storage and attaches the video to the notes. Up to 2 GiB and eight videos a trial.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).

Request body: `application/json`, required.

Responses:

- `201`: The upload, with a presigned PUT per part.
- `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`: Larger than 2 GiB, or the session owner's storage quota would be exceeded (trial videos count toward it).
- `422`: Request failed validation.

## POST /v1/trials/{trial_id}/notes/videos/{video_id}/complete

`completeTrialVideo` · scope `key:write` · Finish a phone video's upload and attach it to the notes

Completes the multipart upload from the parts object storage holds, so the phone need not keep ETags. Checks the stored size against the declared one, and adds the video to `TrialNotes.videos`. Audited `trial.video`.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).
- `video_id` (path, required)

Request body: `application/json`.

Responses:

- `200`: The notes, with the video.
- `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/trials/{trial_id}/verdict

`setTrialVerdict` · scope `session` · Record a person's verdict on a candidate trial (web session only)

**Session only**: a person decides what a real robot showed. No API key of any scope can, and so no agent can (`403`).

There are three options, none the default, and each takes a reason:

- `promote`: this checkpoint becomes the campaign's policy on the robot (`Campaign.policy_on_robot`). It is also the baseline the next session's criteria are drafted from.
- `iterate`: back to simulation. The checkpoint stays a valid parent. An agent session attached to the campaign is woken with the verdict, the notes and the summary. It drafts the next round from them, and a person still approves that round.
- `stop`: this checkpoint's lineage ends the way a FAIL does. No round may resume from it (`rule.fail_ends_lineage`), and iterating from it is refused.

Only a candidate trial takes a verdict. A control trial is measured and not judged. A candidate takes a verdict only once, and only after its run started. Audited `trial.verdict`, with a sentence in `listActivity`.

Parameters:

- `trial_id` (path, required): A trial id (`trial_...`).

Request body: `application/json`, required.

Responses:

- `200`: The trial, with its verdict.
- `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.
