# LLM course/deck authoring workflow

This API accepts content for registered card types, not new executable providers.
A deck is submitted inside a complete course object; there is no separate deck
upload endpoint. New card implementations follow the [repository contribution
path](implementing-card-types.md), not these proposal endpoints.

Base URL: https://deckrehearsal.com

1. Start with the [card type guide and its small examples](card-types.md), then
   consult the [generated field reference](content-reference.html) for your chosen types.
   Read [content-writing guidance](instructions.md) and [notation](notation.md) as needed.
   The [complete schema](../course.schema.json) is a validation reference, not required
   initial reading. Start with 2–3 sourced cards.
2. POST the **course object itself** to `/api/authoring/validate`, with
   `Content-Type: application/json`. No token, sign-in, cookies or browser needed.
   The endpoint does not save your course. It returns `ok`, `stage`, `issues`, and
   per-card checks. HTTP 200 means valid; 422 means fix `issues` and retry.
3. Ask the owner for a token scoped to your chosen **new course ID**. The owner
   creates it in [the proposal inbox](review.html). Never invent or scrape a token.
4. POST `{ "requestId": "<UUID v4>", "course": <course object> }` to
   `/api/authoring/proposals`, using `Authorization: Bearer <token>` and JSON.
   A 201 response contains `id`, `status`, `statusUrl`, `published:false` and validation.
5. If a response is lost, retry the exact same payload and requestId. A duplicate
   returns its receipt without another quota charge. Reusing the ID with different
   content gives 409. Every revised draft must use a **new** requestId. Submissions
   are immutable full drafts, not patches; stable card IDs preserve future progress.
   Include `"supersedes": "<previous proposal ID>"` when sending a revised draft.
   This optional field must reference a proposal submitted with the same token for
   the same course. It is part of the immutable submission: retries must keep it
   unchanged. Omit it for the first draft. The predecessor retains its review
   status and note; its status response lists subsequent proposal IDs in `revisions`.
   Follow the new receipt's `statusUrl` for review of the revised draft. Keep both
   receipts. The owner's inbox identifies the predecessor and marks entries with
   newer revisions; this relationship does not approve or publish either draft.
6. GET `statusUrl` with the same token for review status and `review_note`.
   States: `pending`, `needs-revision`, `approved`, `rejected`.
   Lost a receipt? GET `/api/authoring/proposals` with the same Bearer token.
   It lists only submissions made with that token, newest first, including proposal
   ID, `requestId`, course ID, title, status, creation time, `supersedes` and
   `statusUrl`. Open a status URL for the review note. A token permits at most 40
   submissions, so this list needs no pagination. Expired or revoked tokens cannot
   list proposals; contact the owner if you no longer have a valid token.
   Check when the owner tells you a review happened; don't continuously poll.

## Limits and error handling

- Validation/proposals: at most 1,000,000 UTF-8 bytes, 50 cards, 20 decks,
  20,000 JSON values. Local file import supports larger courses.
- Public validation: 30 requests/hour per network address. On 429 wait an hour;
  don't keep retrying. Tokens last 21 days and permit 40 saved drafts for one ID.
- Tokens cannot publish, modify existing proposals, access another token's drafts,
  or replace built-in courses. Owner can revoke them.
- 400 malformed request; 401 missing/expired/revoked token; 403 wrong course scope;
  409 reused requestId with different content; 413 too large; 415 wrong media type;
  422 invalid course; 429 quota/rate limit; 503 temporary service failure.
- On 503 or a timeout, retry with exponential backoff and the same requestId.
  Never claim receipt or publication unless the server confirms it.
- `issues` give `severity`, `code`, `path`, `message`, and `cardId` when available.
  Independent structural issues are reported together. After structure is valid,
  independent course/card checks are collected; a failed dependent check may prevent
  further checks within that card.
  Mechanical checks are not a proof of mathematical correctness or source fidelity.
  Review source coverage yourself. The owner's browser preview checks actual layout.

## Mixed course format

Use `schemaVersion:1`, `engine:"mixed-cards-v1"` to mix existing equation card
objects with verbatim, self-review, diagram-labeling, and cloze cards. See the
[card type guide](card-types.md) for examples and progress mappings, and the
[generated content reference](content-reference.html) for field meanings and bounds.
Existing `equation-editor-v1` files remain supported.
Verbatim cards require `id`, `type:"verbatim"`, `title`, `prompt`, `learningVersion`,
`answer`, and `formulas`. Do not add equation `editor`, `answers` or `grading` fields
on verbatim cards. Decks may use `kind:"recall"`.

`answer` is an ordered array of literal text strings and `{ "id": "formula-id" }`
tokens. Preserve spaces and blank lines deliberately. Prose matching is case-insensitive and supports the built-in spelling
aliases; it is not semantic grading. Formula identity remains significant. Each referenced formula must be declared in `formulas`, with
`id`, `latex`, accessible `label`, keyboard `code`, and optional `aliases`.
Codes/aliases contain no whitespace, backslash or punctuation and must be unique
and prefix-free within each card’s palette (e.g. `sigma` and `sigmaStar` conflict).
The learner types a backslash followed by a name. Formula tokens render LaTeX but
remain opaque to the grader: this is how to use quantifiers, sets and relations
that the equation editor does not support. Plain-prose cards use `formulas:[]`.

Declare `localization.original:"de"` and list Deutsch in `available` for German
original content. Optional per-card `translations` may include translated `answer`
and `formulaLabels`; keep formula IDs/LaTeX stable. Missing translated answers stay
in the original language. An automatic length-based multiplier applies to recall
unless `multiplier` is explicitly supplied.

## Publication boundary

A proposal is private to its submitting token and the site owner. Owner review can
approve it **for publication**, request revision or reject it. Approval itself does
not publish: the maintainer must explicitly integrate and deploy the approved
course. The receipt always says `published:false`. Local import also never uploads
or publishes. Do not tell the user that submitting or importing publishes a course.

Machine-readable contract: [OpenAPI](openapi.json). Discovery: [LLM manifest](llm.json).

## HTTP examples

```sh
curl --fail-with-body \
  -H 'Content-Type: application/json' \
  --data-binary @course.json \
  https://deckrehearsal.com/api/authoring/validate

# proposal.json contains requestId and course, as documented above.
curl --fail-with-body \
  -H "Authorization: Bearer $COURSE_TOKEN" \
  -H 'Content-Type: application/json' \
  --data-binary @proposal.json \
  https://deckrehearsal.com/api/authoring/proposals
```

Keep the token out of course files, prompts shared publicly, and source control.
If your tools can only fetch GET URLs, return the JSON file for the user to import;
do not claim to have validated or submitted it over HTTP.

## Publication handoff

The owner issues the course-scoped token and reviews your proposal. Approval means
editorial acceptance. The maintainer downloads the approved JSON, validates it,
checks it in the Import course preview, integrates it into the catalog and deploys
it. The maintainer then verifies the live course URL and release version and saves
both in the proposal's review note. Read `review_note` through your status URL while
your token remains valid; ask the owner for the result if it has expired.

`published:false` describes the proposal API: approval never publishes directly.
It is not a live catalog lookup. The review note supplies the actual publication
handoff. No automatic email is sent. Keep your source JSON throughout this process.

The Import course dialog is the primary author preview. The repository's offline
preview is an additional developer tool, not a prerequisite for authoring.

For a local authoring exercise, use the coordinator-supplied origin with the same API paths instead of the production base URL.
