# API reference: coach

Training Coach: the experience corpus, run diagnosis with in-whitelist proposals, and programme planning. Every claim cites a card.

## GET /v1/coach/doctrine

`getCoachDoctrine` · scope `none` · The coach's doctrine (numbered methodology rules)

The distilled methodology the Training Coach reasons with, as numbered rules with the cases that taught them. Public, because this corpus is what makes the coach's advice citable. Anyone can check a citation against it. Cite a rule as `doctrine-{number}`.

Responses:

- `200`: The doctrine.
- `401`: Missing or invalid credentials.
- `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/coach/cards

`searchExperienceCards` · scope `none` · Search the experience corpus

Keyword + tag search over the experience cards (no vector index in v0). `q` is scored against card id, title, rule, trigger conditions, tags and symptom. Scoring uses inverse-document-frequency weighting, so a term common to the whole corpus contributes nothing. `tags` is a **conjunction**: `tags=reward-shaping,curriculum` returns cards carrying both. With no `q` the result is every matching card ordered by id. That is what the corpus browser lists.

Parameters:

- `q` (query): Free-text query.
- `tags` (query): Comma-separated tags; a card must carry all of them.
- `task` (query): Task line filter: walk | omni | run | recovery | arm | infra.
- `phase` (query): Pipeline phase filter (plant-calibration, reward-shaping, …).
- `confidence` (query)
- `limit` (query): Page size (tree listings allow larger pages).
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of cards, most relevant first.
- `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/coach/cards/{card_id}

`getExperienceCard` · scope `none` · Get one experience card

The full card, including its provenance quote. A citation in an advice report expands to this card.

Parameters:

- `card_id` (path, required): Experience card slug, e.g. `resume-state-dr-audit`.

Responses:

- `200`: The card.
- `404`: Resource not found (or hidden from the caller).
- `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/coach/advice

`createAdvice` · scope `key:train` · Diagnose a training run

Reads a training run, by `run_id` or inlined. Returns a structured `AdviceReport`: diagnosis, in-whitelist proposals, an experiment plan, and flags for anything that would need a contract change. When `parent_run_id` is set (or the run has one), the resolved-config diff against the parent goes into the prompt as attribution evidence.

The hub enforces four things **in code** on the model's output. It does not rely on the prompt for them:

- every proposal's `category` is in the whitelist
- every proposal cites at least one card or doctrine rule that exists in the corpus
- every PASS gate found in the scorecard is echoed under `experiment_plan.constraints`
- no proposal touches the policy contract, observation space, action space or robot description. Those may appear only in `flags`.

An invalid report is retried once and then fails with `502` carrying the validation errors.

This endpoint spends model dollars, so it needs `key:train` like the other compute endpoints. The call is billed to the Anthropic key of the workspace that owns the run (`listModelKeys`). A workspace with no key answers `402`, unless the hub serves it with its own key.

Calls the hub's own key pays for are also capped by a per-account daily quota. Every key, session, plan and agent session of the user shares that one quota. When it is exhausted, the call answers `429` with `X-Coach-Quota-*` headers.

Request body: `application/json`, required.

Responses:

- `201`: Report produced and persisted.
- `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 model's report failed validation twice. `errors[]` carries the broken guarantees; nothing was persisted.
- `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/coach/plan

`createCoachPlan` · scope `key:train` · Plan a training programme from a task brief

The zero-runs path. Takes a task brief (and a robot repo's card, when given) and returns:

- the contract to freeze
- the plant measurements to take before any training
- a minimal reward table
- a DR baseline
- a ladder outline of one-variable rungs
- a first acceptance battery

Every item is cited to the corpus. Spends model dollars: `key:train`. It is billed to your own workspace's Anthropic key, with the same daily quota as `advice` when the hub's key pays.

Request body: `application/json`, required.

Responses:

- `201`: Plan produced and persisted.
- `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 model's plan failed validation twice.
- `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/coach/sessions

`listAdviceSessions` · scope `key:read` · List coach sessions

Sessions visible to the caller, newest first.

Parameters:

- `run_id` (query): Only sessions about this run.
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of sessions.
- `401`: Missing or invalid credentials.

## GET /v1/coach/sessions/{session_id}

`getAdviceSession` · scope `key:read` · Get a coach session

Parameters:

- `session_id` (path, required): Coach session id (`advice_...`).

Responses:

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

## POST /v1/coach/sessions/{session_id}/feedback

`setAdviceFeedback` · scope `key:write` · Rate a coach report

Thumbs up or down, with an optional note. Feedback is a corpus candidate. A report, its verdict and the run that actually followed are the raw material of the next experience card. Idempotent: the last verdict wins.

Parameters:

- `session_id` (path, required): Coach session id (`advice_...`).

Request body: `application/json`, required.

Responses:

- `200`: Feedback recorded; the session is returned.
- `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.
