# Connector

The Récit connector is the small public part of Récit: it validates a story written as JSON (its
[twin](/documentation/reference/glossary)) against the published schema, and sends it to the Récit
service, which renders it as a deck, a webtoon, a book in PDF or a film. The engine stays on the
service; the connector carries only the schema and a client of the service's API.

:::caution{title="An alpha, not on npm"}

The connector is in alpha, and it is not on npm. Its first archive is being prepared and will be
handed out by the Récit team (see [Getting the alpha](#getting-the-alpha)). Once you have it,
`validate` works offline; `send` and `render` wait for the render routes of the service, which are
not online yet.

:::

## Getting the alpha

The alpha will ship as one archive, such as `recit-connector-0.1.0-alpha.0.tgz` (the number is not
final), the way the other private packages of Récit ship. Nobody will download it from a registry:
the Récit team will hand it to the people it is meant for. Once you have it, install it from the
file, in a project or globally:

```bash
npm install ./recit-connector-0.1.0-alpha.0.tgz      # in a project: npx recit-connector …
npm install --global ./recit-connector-0.1.0-alpha.0.tgz
```

The archive holds the connector alone. Its only dependencies are `zod` and the MCP SDK; no package
of the engine comes with it.

What the alpha does not do yet:

- **Render on the service.** `send`, `render` and the MCP tool `render_story` speak the
  [contract](#the-services-contract) of the service's render routes, which are not online yet; until
  they are, the alpha validates stories and renders none.
- **Update itself.** A new alpha is a new archive, installed the same way over the old one.
- **Keep its interface.** Until its first release, a command, an option or an export may change from
  one alpha to the next; the [stability](/documentation/reference/stability) promise of 1.0 does not
  cover it.

## What you need

- A story twin, a `.json` file with `kind: "story"` (or a sidecar with `kind: "sidecar"`). The
  schema is published at `https://recit.dev/schema/v1/story.json`; an editor that reads `$schema`
  completes and checks it as you type.
- To render: the address of the service (`RECIT_API_URL`) and a personal token of your account with
  the `render:write` scope (`RECIT_API_TOKEN`), created on your
  [account page](/documentation/reference/account). Validation needs neither.

## From a terminal

```bash
recit-connector validate lorem.story.json
recit-connector validate lorem.sidecar.json --sidecar
```

`validate` reads the file, checks it against the schema the connector carries, and prints each
problem with its path in the document. It never reaches the network.

```bash
export RECIT_API_URL=https://api.lorem.example
export RECIT_API_TOKEN=rct_…

recit-connector send lorem.story.json --to pptx     # prints the render's id and status
recit-connector render lorem.story.json --to pdf    # waits, then prints the file's link
```

`send` and `render` validate the story first and send nothing when it is invalid. `--to` is the file
to render, one of `pdf`, `pptx` or `mp4`; the format comes from the story itself, and each format
renders to its own files only:

| Story format      | `--to`        |
| ----------------- | ------------- |
| `deck`            | `pdf`, `pptx` |
| `book`, `webtoon` | `pdf`         |
| `motion` (a film) | `mp4`         |

| Exit status | Meaning                                                            |
| ----------- | ------------------------------------------------------------------ |
| `0`         | valid, or the render was accepted (`send`) or succeeded (`render`) |
| `1`         | invalid story, refusal of the service, or a failed render          |
| `2`         | usage error: unknown command, missing `--to`, no service set       |

## From an agent

`recit-connector-mcp` is an MCP server over stdio. Add it to your MCP host (Claude Code, Claude
Desktop or any other) with the two variables above; without them, only validation works.

```json
{
  "mcpServers": {
    "recit": {
      "command": "recit-connector-mcp",
      "env": {
        "RECIT_API_URL": "https://api.lorem.example",
        "RECIT_API_TOKEN": "rct_…"
      }
    }
  }
}
```

| Tool             | What it does                                                          |
| ---------------- | --------------------------------------------------------------------- |
| `validate_story` | checks a twin or a sidecar against the schema, offline                |
| `render_story`   | validates a twin, then asks the service to render it to one `output`  |
| `get_render`     | reads the status of a render, and the link to its file once succeeded |

An agent writes the story as JSON, calls `validate_story` until it is valid, then `render_story`,
and follows the render with `get_render` until it has succeeded.

## From TypeScript

```ts
import { createRecitClient, formatIssues, validateStory } from "@recit/connector";

const result = validateStory(story);
if (!result.ok) {
  throw new Error(formatIssues(result.issues));
}
const client = createRecitClient({ baseUrl, token });
const { id } = await client.render({ story, output: "pdf" });
const render = await client.waitForRender(id);
console.log(render.url);
```

`validateStory(document, "sidecar")` checks a sidecar instead. A refusal of the service throws
`RecitApiError`, with its HTTP `status` and the service's error `code`.

## The service's contract

The connector speaks two routes of the service, with the token in `Authorization: Bearer …`:

| Route                        | Body or answer                                                                   |
| ---------------------------- | -------------------------------------------------------------------------------- |
| `POST /v1/render/jobs`       | sends `{ output, story }`; answers `202 { job }`                                 |
| `GET /v1/render/jobs/:jobId` | answers `{ job }`                                                                |
| a job                        | `{ id, format, output, status, error, bytes, downloadUrl }`                      |
| a refusal                    | `{ error, issues? }`: a code, and for a refused story the problems of its schema |

`status` is one of `queued`, `running`, `succeeded` or `failed`. Once a job has `succeeded`,
`downloadUrl` is a link to its file valid one hour (read the job again for a fresh one); the
connector shows it as `url`. A failed job names its `error` (`invalid_story`, `render_failed`,
`timeout`, `output_too_large` or `storage_failed`). Renders count against the quota of your account:
past it, the service answers `429 render_quota_exceeded`.

## Related

- [Glossary](/documentation/reference/glossary): story, twin, sidecar.
- [Stability](/documentation/reference/stability): the connector is outside the 1.0 contract until
  its release.
- [Account](/documentation/reference/account): personal tokens.
