# API reference: campaigns

Campaigns: a training loop as hub objects. A campaign is a task on a robot with a budget. Each round locks a spec: one declared change, a hypothesis, and gates with predictions. The round trains through `createRun` and is gated and band-scanned in simulation. It gets a verdict from its locked gates and a decision. Three rules are enforced in code. Only a signed-in person may override one, with a reason.

## GET /v1/campaigns

`listCampaigns` · scope `key:read` · List campaigns

Campaigns visible to the caller (owner, org member or creator), newest first. No campaign is public: a campaign holds its owner's budget and runs.

Parameters:

- `status` (query)
- `robot` (query): Only campaigns on this robot repo (`owner/slug`).
- `slug` (query): Only campaigns with this slug (one per owner).
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: A page of campaigns.
- `401`: Missing or invalid credentials.
- `422`: Request failed validation.

## POST /v1/campaigns

`createCampaign` · scope `key:write` · Start a campaign: a task on a robot, with a budget and the three rules

A campaign is the unit of a training loop. It has a task on a robot repo the caller can see and a budget. It also has rounds and, optionally, a declared root checkpoint. Its `task` picks the default gate battery for every round:

- `stand` → the posture battery `stand`
- `walk` / `omni` → `watch` while training and `c_matrix` for the band scan
- `recovery` → `recovery`
- `reach` → the target grid of a fixed-base robot (an arm), built from the brief's reach range: `grid` while training and for the scan
- `custom` → `smoke`

`reach` needs a robot whose card says `base: fixed`, and always has a brief: one without a range takes the hub's default reach range.

The three rules are enforced on every round and cannot be switched off:

- one variable per round
- resume only from a PASS checkpoint
- a FAIL ends the lineage

A signed-in person may override one rule on one round, with a reason (`createRoundWithOverride`). Creating spends nothing: `key:write`.

**From a brief.** With `brief`, the hub derives the command grid from the brief's ranges. Rounds are gated and scanned on `grid` instead of `c_matrix`. Each round's chosen checkpoint then gets the four gates (`Round.four_gates`). With `dry_run=true` nothing is recorded, and the answer is the price (`CampaignQuote`): one run per seed per round, at its maximum.

**Stop rules.** Every campaign has `limits`. When a round passes all four gates, when it reaches `max_rounds`, when progress stalls, or when GPU hours or the budget run out, the hub stops the agent's rounds. It also tells the owner. A person continues it.

Parameters:

- `dry_run` (query): Price the brief and record nothing (`CampaignQuote`).

Request body: `application/json`, required.

Responses:

- `200`: `dry_run`: the price. Nothing was recorded.
- `201`: Campaign created.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## POST /v1/campaigns/plan

`planCampaign` · scope `key:write` · Plan a campaign from one sentence

Turns a sentence such as "walk forward at up to 1 m/s and turn, within $10" into a campaign a person confirms. The answer is the exact `createCampaign` body, its price, and one reason per choice. Nothing is recorded. Confirming is `createCampaign` with `campaign`, unchanged or edited.

**The robot's base decides the task.** On a floating base the task is `walk`, `omni`, `stand` or `recovery`. On a fixed base (an arm) it is `reach`: move the end effector, or the joints, to targets and hold them. Its range is end-effector targets in metres when the card names an end effector in the model and the robot has one arm, else joint targets in radians. A sentence about an object (pick, place, push, open, pour, stack) on a fixed base is `422` before any model call: the hub has no sim test for it.

**Who plans.** When the hub has a model for the caller, an agent plans (`planned_by: agent`). Its answer is checked in code before it is returned:

- the task is one a campaign trains on this robot's base
- every command range stays inside the robot card's declared range (on a fixed base, the hub's most for a reach range)
- a range beyond the robot's tested range is allowed only with a flag naming the axis
- a budget given in the request is kept as given
- every choice carries a reason

An answer that breaks a rule is rejected as a whole. The agent gets one retry with the complaints quoted. After that, the hub's rules plan the campaign instead and `fallback` says why.

Without a model, the rules plan it (`planned_by: rules`). They read speeds, turning, a reach distance (cm, m, rad or degrees), budget, seeds and rounds out of the sentence. The rules also plan when the credential may not spend, or when `planner` is `rules`.

**The trainer.** The hub picks where the rounds train for the campaign's owner. `round` names a template, an executor or a GPU instead. The `trainer` reason and `engines` then describe that template. A stand or recovery plan has no planned round, so `round` is not applied there and a flag says so. When the rounds train with `ppo_isaac`, `isaac_task` names the Isaac Lab task they train, and the plan says which one. Naming one for another template is `422`.

**Scope.** Planning records nothing, so it is `key:write`. Only a credential holding `train` makes the model call, because that is the scope that may spend. A `write` key always gets the rules plan.

A model call is billed like coach advice: to the workspace's own model key, else the hub's for the accounts it serves. Each call counts once against the daily coach quota. Its tokens and cost are in `usage`.

Request body: `application/json`, required.

Responses:

- `200`: The plan and its price. Nothing was recorded.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `422`: Request failed validation.

## GET /v1/campaigns/{campaign_id}

`getCampaign` · scope `key:read` · Get a campaign (its rounds, spend, and what waits on a person)

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.

Responses:

- `200`: The campaign with every round, newest first.
- `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/campaigns/{campaign_id}

`updateCampaign` · scope `key:write` · Rename, re-describe, change the budget of, or stop a campaign

`key:write`, with two exceptions enforced in the handler. **Raising** `budget_usd` or **raising** `per_run_limit_usd` is a person's decision (a signed-in session). A key of any scope gets `403` for either. Together, these two exceptions are what let an agent run rounds without asking. An agent that could raise either would have no limit at all. A key may lower them, rename the campaign, or stop it.

`unattended` follows the same rule. Switching it on, or raising `max_rounds` or `max_hours`, is a signed-in person's decision (`403` for a key). Any key with write access may lower either number or switch it off. Switching it on starts a stretch: its counters start at zero and any pause is cleared.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.

Request body: `application/json`, required.

Responses:

- `200`: The updated campaign.
- `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/campaigns/{campaign_id}/continue

`continueCampaign` · scope `session` · Continue a campaign after the hub stopped it

**Session only.** A campaign the hub stopped waits for a person. This clears the pause. An unattended campaign starts a new stretch: its round and hour counters start again at zero. The stop rules' round count also starts again. The budget does not reset, and what was spent stays spent. An agent session attached to the campaign that waits on the pause is woken with a notice. `instruction` is one sentence the next round must address. A campaign with nothing to continue answers `409`.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.

Request body: `application/json`.

Responses:

- `200`: The campaign, with a new stretch.
- `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/campaigns/{campaign_id}/rounds

`createRound` · scope `key:train` · Lock a round's spec and start its training run

The spec is **locked** here and never edited. It holds:

- one declared change (a summary and the resolved-config keys it covers);
- a hypothesis;
- what is not being done;
- tripwires;
- gates with their predictions;
- an iteration cap.

A gate added later is shown and not counted. Then the three rules are checked, in code, before anything is spent:

- **One variable.** The change the recipe makes is predicted against the parent checkpoint's run (its resolved config, and its recipe). That change must lie inside the declared keys. A declared key covers itself and every path under it. `run.*` and a template's own bookkeeping never count. A round that stacks a sibling's change (same parent checkpoint) on its own is more than one variable. When the run's resolved config arrives, the same diff is recomputed on what it actually trained on. An undeclared key found then makes the round `confounded`.

- **Resume only from PASS.** `parent` must be the campaign's declared root, or a checkpoint of one of its rounds. That checkpoint's verdict **at that step** must be `pass`.

- **A FAIL ends the lineage.** No checkpoint of a round whose verdict is `fail` or `confounded` may be a parent. The same holds for a round whose lineage was stopped.

A violation is `422`, and nothing is recorded. The body has one `errors[]` entry per rule. Each entry's `type` is `rule.one_variable`, `rule.resume_from_pass` or `rule.fail_ends_lineage`, and its `msg` names the keys or the verdict. Only a signed-in person may override a rule, with a reason, through `createRoundWithOverride`. No key of any scope can.

**Budget:** the round's run is priced with `estimateRun`. The campaign's spend is what the ledger holds, plus what in-flight rounds may still spend. When the run's maximum would take the campaign past `budget_usd`, the answer is `409` naming the numbers. The request is well-formed; the campaign has no money left for it. A priced run's own `budget_usd` is capped at what remains, so the hub stops it there. Then the run is created through `createRun`'s own path. So `executor: modal`, `parent_checkpoint_step` and `gate` behave exactly as there. When the recipe names no gate, the run gets the campaign's task-aware gate. Spends compute: `key:train`.

**Dry run.** `?dry_run=true` runs every check above on the same body and records nothing. It answers `200` with a `RoundPreview`, which holds:

- the three rules as verdicts (the `422`'s own entries, from the same implementation);
- the variables against the parent;
- the run's price, with the campaign's remaining budget as its cap;
- every published checkpoint of the parent run, with whether it may be a parent and the rule's sentence when not;
- whether the template reads each hyperparameter;
- why the parent run cannot be fine-tuned, when it published no checkpoint at all (every imported run today).

A malformed body, an unknown parent and a campaign that cannot afford the round answer as `createRound` would. A web fine-tune is a round, so this is its preview before the spend.

**Experiment card.** `card` holds a hypothesis and a numeric prediction: a metric (`gates_passed` or one of the round's locked gate names), a direction and an optional value. It is stored with the locked spec, so it is never edited. The hub scores it when the round's chosen checkpoint is measured, against the checkpoint the round started from.

**Unattended campaigns.** When `Campaign.unattended.enabled` is true, three more checks apply to a key (a signed-in person is not blocked):

- A paused stretch answers `409`, `errors[0].type` `campaign.paused`, naming the reason and `POST /v1/campaigns/{campaign_id}/continue`. The hub checks its pause conditions here too, and pauses before it answers.
- A round without `card` is `422` with `rule.prediction_required`, and the hub pauses the stretch.
- The declared change must fall in the autoloop whitelist: reward, domain randomization or commands. Anything else is `422` with `rule.autoloop_whitelist`. A person may still create such a round, and it is marked as theirs.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.
- `dry_run` (query): Check everything and record nothing; `200` with a `RoundPreview`.

Request body: `application/json`, required.

Responses:

- `200`: `dry_run=true`: what this round would be. Nothing was recorded.
- `201`: Round created; its spec is locked and its run queued.
- `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.
- `429`: The account's or the key's daily GPU-hour quota (as on `createRun`).
- `503`: A service this endpoint needs is not configured in this deployment. The API boots with zero secrets. An endpoint that needs one says so instead of returning a stack trace.

## GET /v1/campaigns/{campaign_id}/rounds/draft

`draftRound` · scope `key:read` · A draft of the campaign's next round, ready for one change

Returns a `createRound` body for the next round. Nothing is recorded. An agent fills in its one change and its prediction, then sends the body to `createRound`.

The parent is the newest round's chosen checkpoint when its verdict is `pass` and its lineage is open. Otherwise it is the campaign's `root`. Without either, the round trains from scratch. The recipe repeats the parent round's recipe, or the campaign's planned round. The gates are a starting point on the campaign's test grid: edit their thresholds to what you predict.

Round one's change is the confirmed plan itself, so its draft can be sent as it is. A later draft leaves `spec.change` empty and lists it in `needs`. `blocked` says why no round can start now, for example a campaign the hub stopped for a person.

**The Isaac Lab task.** A `ppo_isaac` round trains its parent's task, read from the parent checkpoint's run. Without a parent it trains the planned task. `isaac_task` names another one. That is a change, and the draft declares it in `spec.change` (key `task`). A round that names a task and nothing else can be sent once its hypothesis is filled in. Naming the parent's own task changes nothing. Naming a task for a round that does not train with `ppo_isaac` is `422`.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.
- `isaac_task` (query): The Isaac Lab task this round trains, when it is not the parent's.

Responses:

- `200`: The draft. Nothing was recorded.
- `401`: Missing or invalid credentials.
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## POST /v1/campaigns/{campaign_id}/rounds/override

`createRoundWithOverride` · scope `session` · Start a round that breaks a rule: a person's decision, with a reason

`createRound`, plus `override: {rules, reason}`. **Session only**: no API key of any scope may override a rule. So an agent can propose a round, and it cannot waive the rules that round would break. `rules` must name exactly the rules this round violates. Naming a rule the round does not break is `422`. An override record says what was waived and nothing more. `reason` is recorded on the round with who and when, as an `override` chip. A round created with a `one_variable` override reads `confounded` whatever its gates say. Nothing resumes from it without another override. Budget, scope and every other check are `createRound`'s.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.

Request body: `application/json`, required.

Responses:

- `201`: Round created with its override record.
- `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.
- `503`: A service this endpoint needs is not configured in this deployment. The API boots with zero secrets. An endpoint that needs one says so instead of returning a stack trace.

## GET /v1/campaigns/{campaign_id}/rounds/{round_n}

`getRound` · scope `key:read` · Get a round: its locked spec, the verdict at a step, the variables, the decisions

The verdict is the round's **locked gates** evaluated on the measured results at `step`. The default is the chosen step: the one a decision named, else the measured checkpoint with the most counted gates passing. On a tie, the earliest such checkpoint is chosen. Measurements come from the round's band scan at that step, else from the gate its run got while training. The hub's own 0.85–1.15 band verdict for the same rollout is returned beside it (`evaluation.band`). It is a measurement only and does not set the verdict.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.
- `round_n` (path, required): The round's number within its campaign (1, 2, …).
- `step` (query): Evaluate the locked gates at this checkpoint step instead of the chosen one.

Responses:

- `200`: The round.
- `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, ...).

## POST /v1/campaigns/{campaign_id}/rounds/{round_n}/decision

`decideRound` · scope `key:write` · Decide a round: shortlist, iterate, stop the lineage, or done

The operation's floor is `key:write`. **Each action has its own scope, enforced in the handler** (`x-action-scopes`):

- `stop` is `key:write`. Ending a lineage spends nothing.
- `iterate` is `key:train`. It says "train the next round from `step`", which an agent may propose inside the campaign's budget.
- `shortlist` and `done` are **session only**. They are the two human gates. No key of any scope can pass them, and therefore no agent can.

`shortlist` records the chosen checkpoints (`candidates`, steps of this round's run) and the A/B `controls` (any visible checkpoint, usually the parent). Each comes with its verdict at that step. It starts nothing. It plans the real-robot session (`createTrialSession`): one trial per run, the control first and last, a run sheet each. It also files one consent request per trial when the device is known and no agent's shortlist follow-up will file them. The device is known from `device_id`, or as the only one of the owner's devices that accepts every contract. A person approves each request on the consent page.

`iterate` refuses a step whose verdict is not `pass` (the resume rule, stated before the next round is written). `done` closes the campaign.

In an unattended campaign, `iterate` from a key is `409` with `campaign.paused` while the stretch is paused. The hub checks its pause conditions first and pauses when one holds. A person's `iterate` is not blocked.

`shortlist` is refused (`422`, `rule.separates_from_control`) when the round's control also passes every locked gate. The control is the checkpoint the round started from, measured in its own band scan. The person may still shortlist by sending `override` that names that rule, with a reason.

Every decision is recorded with who, when, how and the verdict it was taken on.

When an agent session's `shortlist` decision waits on this round, a `shortlist` here answers it (the note is `reason`). The hub then runs the 20-seed band scan on the picks. If the round's own scan already covers them, it waits for that scan instead. It then files **one device consent request per pick that still passes the locked gates**. The note is each request's reason. Nothing is approved here.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.
- `round_n` (path, required): The round's number within its campaign (1, 2, …).

Request body: `application/json`, required.

Responses:

- `200`: The round, with the decision 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, ...).
- `422`: Request failed validation.

## POST /v1/campaigns/{campaign_id}/rounds/{round_n}/gates

`addRoundGate` · scope `key:write` · Add an uncounted gate after the lock

A round's spec is locked when it starts. What someone learns afterwards may still be worth measuring (a stand tilt gate added to a round that had started). The gate is evaluated and shown beside the locked ones, with `added_after_lock_at` set and `counted: false`. It never changes the verdict.

Parameters:

- `campaign_id` (path, required): Campaign id (`camp_...`), or its slug when exactly one campaign the caller can see has it. Two owners may share a slug: that is a `409` naming both ids.
- `round_n` (path, required): The round's number within its campaign (1, 2, …).

Request body: `application/json`, required.

Responses:

- `201`: The round, with the gate added (not counted).
- `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.
