> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# API reference

> Endpoint contract for the agent ingest pipeline — auth, projects, ingest, organize, share.

All endpoints accept `Authorization: Bearer <ufl_mcp_token>` and
`Content-Type: application/json`. Base host: `https://www.userflowlibrary.com`.
Projects and AI usage belong to the authenticated account/workspace.
Accountless trial issuance and AI reservations are disabled.

## Auth

### Account usage and upgrades

`GET /api/account/usage` accepts the authenticated account token. Optional
`projectId` selects an authorized project for the checkout return link.
Optional `requiredScreens` (1–40, default 1) checks whether the pending batch fits
without reserving any screens.
The response includes `allowed`, `usedCount`, `maxCount`, `remainingCount`,
`plan`, `scope`, `upgradeUrl`, `upgradeAvailable`, `billingProvider`, and `status`.
With hosted billing enabled, `upgradeUrl` opens Stripe Checkout. An existing
unpaid purchase may instead return its Stripe billing portal or invoice link;
the server does not create a second subscription to bypass pending payment.

`get_account_usage` is the MCP equivalent. It accepts `project_id`,
`required_screens` (1–40), and `wait_seconds` (0–20), and returns
`readyToResume` for the requested batch size.

At the free allowance limit, render requests return HTTP 402 with
`AI_QUOTA_EXCEEDED`, the upgrade URL, and `safeToRetry: true`. Preserve the
project and rejected batch, show the URL, and poll usage until billing confirms
the paid plan. Then retry the rejected batch. No reauthorization is required
when the same account/workspace is upgraded.

Checkout creation rechecks workspace membership and billing management
permission. A read-only MCP token cannot create a purchase or open the billing
portal. A completed redirect is never accepted as proof of payment.

`BILLING_SETUP_REQUIRED` indicates that the scope has no supported paid plan;
do not treat its URL as an available paid checkout. HTTP 503 means billing or
usage could not be verified; no AI work is authorized.

Free attempts are reserved atomically before provider work. Concurrent imports
share the same account allowance; creating another repository/project does not
reset it. Failed or uncertain attempts retain their reservation.

### `POST https://mcp.userflowlibrary.com/device_authorization`

Starts the OAuth device flow. No body required.

```json theme={null}
{
  "device_code": "...",
  "user_code": "ABCD-1234",
  "verification_uri": "https://userflowlibrary.com/mcp/authorize",
  "verification_uri_complete": "https://userflowlibrary.com/mcp/authorize?code=ABCD-1234",
  "expires_in": 900,
  "interval": 5
}
```

### `POST https://mcp.userflowlibrary.com/token`

`grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=...`

Returns `{"error":"authorization_pending"}` until the user approves, then `{ "access_token": "ufl_mcp_...", "token_type": "Bearer" }`. Tokens last 30 days.

## Projects

### `POST /api/projects`

```json theme={null}
{ "name": "my-app", "platform_type": "web" }
```

`platform_type` defaults to `"web"`. Returns the created project including `id`.

### `POST /api/projects/{id}/ingest-screens`

Renders agent-supplied routes into screens. Synchronous — expect up to a few minutes for a full batch.

```json theme={null}
{
  "routes": [
    {
      "path": "/billing",
      "title": "Billing",
      "source": "<route component source, verbatim>",
      "sourceFile": "app/billing/page.tsx",
      "framework": "nextjs",
      "components": { "components/Table.tsx": "<source>" },
      "styles": { "app/globals.css": "<source>" },
      "content": { "lib/fixtures.ts": "<source>" },
      "assets": { "public/logo.svg": "<source>" },
      "navigation": [{ "to": "/billing/confirmation", "label": "Confirm" }]
    }
  ],
  "flowId": "optional-existing-flow-uuid",
  "flowName": "Imported screens"
}
```

| Constraint | Value |
| - | - |
| `routes` per call | 1–40 |
| `source` per route | ≤150 KB |
| Required route source and fixtures | Must fit the shared 90,000-character render source budget |
| Quota | Free tier: 25 AI renders total → `402` with `code: "AI_QUOTA_EXCEEDED"` |

Response: `{ success, flowId, screens: [{id,title,path,stateKey,rendered,error?}], renderedCount, failedCount, projectUrl, navigationWarning?, contextWarnings }`.
`success` is true only when every requested screen completes. Success requires
usable generated content, validation of a requested dialog, and a saved compiled
stylesheet and screen. Partial failures return the project and per-screen results;
preserve successful screens and retry only failed states.
If styling or validation fails after markup is returned, that markup may be
retained for inspection, but the screen is reported as failed.

Route source and supplied fixtures are included whole. Components share the
remaining source budget, with route/state implementations preferred over generic
supporting files. Oversized required input returns `400` before allowance is
reserved; send a smaller coherent source sample rather than truncating a form.
`contextWarnings` lists `{ path, stateKey, omittedFiles }` for supporting files
that did not fit. Report these coverage limits instead of claiming unseen code
was reconstructed.

Requested dialogs must have a static open dialog container, a visible heading
and content, and a matching state marker in the generated markup. Missing,
closed, hidden or empty dialog output fails validation. These are structural
checks, not a guarantee of computed browser visibility or exact source fidelity.
Compare the result with the source and running app when available before
claiming visual accuracy.

`navigation` is optional source-evidenced metadata: up to 200 internal destinations
per route, each with `to` (up to 500 characters) and a nullable `label` (up to 80).
Include form submissions and verified literal fallbacks that static markup cannot
express. Do not guess runtime destinations. These links remain inferred rather
than observed, and resolve when their destination screens arrive in later batches.
If `navigationWarning` is returned, source links are saved but graph derivation
needs to be retried; screen rendering counts do not imply a complete graph.

For a source-supported interaction state, send another entry at the same real
`path` with `variant: { stateKey, kind, renderInstruction }`. Use a stable state
key within the route and a kind such as `dialog`, `tab`, or `step`. For example,
a task drawer can use `stateKey: "task-create"` and `kind: "dialog"`, with an
instruction to show the component opened by the source's Create button.
Include that component and its dependencies in `components`; do not invent a
URL or claim a backend operation succeeded. State metadata is retained for
organization, while ordinary route links resolve to the default screen.
Each state consumes one requested screen from the same allowance. Preserve
the full payload and its `(path, stateKey)` identity when pausing for payment.

When known, include optional `variant.evidence` with `file` (repo-relative),
`line` (one-based), `expression`, and `candidate_key` (a stable source-candidate
identifier). These source references are retained for rendering and curation;
they describe source conditions, not observed runtime interactions. Omit the
field or use `null` when no precise reference is available.

### `POST /api/projects/{id}/organize`

Groups rendered screens into named user journeys with a mermaid graph per journey. No body required.
Journeys follow individual user goals, including single-screen goals when that
is all the captured evidence. Incomplete model plans fail before replacing
the saved organization.

### `GET /api/projects/{id}/share`

Mints (or reuses) a public share token. Returns `{ shareUrl }` — publicly accessible without auth.

## Errors

Standard JSON error body: `{ "error": "..." }`. `401` invalid/missing token, `402` AI quota exceeded, `404` project not found or not yours.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.