# API reference: plans

The planner: a frontier model orchestrates the three layers for one task on one device. It works through a closed step vocabulary. It can only *request* approvals, and a human signs them. It never opens a session and never names a joint. Each plan is recorded as an `orchestration` run.

## GET /v1/plans

`listPlans` · scope `key:read` · List plans

Plans visible to the caller (owner, creator, or org member), newest first. No plan is public.

Parameters:

- `status` (query)
- `device_id` (query)
- `run_id` (query): The plan recorded as this `orchestration` run (at most one).
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of plans.
- `401`: Missing or invalid credentials.
- `422`: Request failed validation.

## POST /v1/plans

`createPlan` · scope `key:train` · Plan a task for a robot (the planner makes its first decision)

`{task, device, budget_usd, max_minutes}` → a plan. The hub records an `orchestration` run (with `parent_run_id` lineage when given). It asks the planner model for its first decision **synchronously** and executes what it can. A `request_approval` step files an approval request on the device at once. The hub returns the plan with its steps and timeline.

The planner's vocabulary is closed: `request_approval`, `await_started`, `open_session`, `wait`, `evaluate`, `hand_back`. Six guarantees are enforced **in code** on every decision:

- only those kinds
- no step text names a joint, a torque, a velocity, a gain or a raw action
- a `request_approval` may only name an endpoint or model the device's registered contracts allow (checked before any request is filed)
- nothing runs on the device's behalf before the device's own signed `started`
- every step expires inside the plan's window
- every step's cumulative cost cap lies within the budget

A violating decision is retried once with the errors quoted back. If the retry also violates a guarantee, the plan is `failed` and the response is `502` carrying the errors.

The plan cannot approve anything, because `createApproval` is session-only. It does not open a session. The device opens it. It only reads endpoints. It acts as the credential that created it, narrowed to `write`, for the one write it makes: filing requests. Spends model dollars: `key:train`. Every decision is billed to the Anthropic key of the workspace that owns the device. A workspace with no key answers `402` and no plan is recorded. When the hub's own key pays, every decision counts against the coach's daily quota, this one and each later one. This call answers `429` with `X-Coach-Quota-*` headers when the first decision cannot be made.

Request body: `application/json`, required.

Responses:

- `201`: Plan created; its first decision was made and executed as far as it could go.
- `401`: Missing or invalid credentials.
- `402`: This workspace has no key the hub may use for the model's vendor, or a limit is reached: its own key's monthly cap, or the workspace's limit. `type` and `errors[].type` say which: `model_key_required`, `model_cap_reached` or `billing.cap_reached`. `settings_url` is where a person adds a key, raises the cap or opens Billing. Nothing was spent.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.
- `502`: The planner's first decision failed validation twice. The plan exists, is `failed`, and its timeline carries the errors; `errors[]` here carries them too.
- `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/plans/{plan_id}

`getPlan` · scope `key:read` · Get a plan (steps, timeline, what it is waiting on)

Parameters:

- `plan_id` (path, required): Plan id (`plan_...`).

Responses:

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

## POST /v1/plans/{plan_id}/advance

`advancePlan` · scope `key:train` · Run one orchestrator tick on a plan (idempotent)

The orchestrator's beat, callable by hand. Re-reads the device's events, the endpoint session metering and the approval state. Expires a step whose window passed and executes the current step when it can. Asks the model for the next decision only when no step is pending or the last one failed or expired. Takes a compare-and-set lock on the plan, so two ticks at once cannot both decide. A tick with nothing due changes nothing. The same function runs on a schedule (the arq cron, or the API's in-process ticker when `PLAN_TICK_INTERVAL_S` is set). You never need to call this. A decision made here counts against the coach's daily quota when the hub's key pays. When the account's quota is exhausted, the plan hands back. This call does not answer `429` in that case. When the workspace has lost its key or reached its cap, the plan is `failed` with that reason and this call answers `402`.

Parameters:

- `plan_id` (path, required): Plan id (`plan_...`).

Responses:

- `200`: The plan after the tick (unchanged when nothing was due).
- `401`: Missing or invalid credentials.
- `402`: This workspace has no key the hub may use for the model's vendor, or a limit is reached: its own key's monthly cap, or the workspace's limit. `type` and `errors[].type` say which: `model_key_required`, `model_cap_reached` or `billing.cap_reached`. `settings_url` is where a person adds a key, raises the cap or opens Billing. Nothing was spent.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `502`: A decision made during this tick failed validation twice; the plan is `failed`.
- `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.

## POST /v1/plans/{plan_id}/cancel

`cancelPlan` · scope `key:train` · Cancel a plan

Ends an active plan (`canceled`) and its run. A pending approval request the plan filed stays for a person to deny in the web app. An issued approval ends on its own window. The plan can request consent. It cannot revoke it, and its final event says so. `409` when the plan already ended.

Parameters:

- `plan_id` (path, required): Plan id (`plan_...`).

Responses:

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