# repa for coding agents This guide tells a coding agent how to call the repa HTTP API from a server: documents, generation, Flows drafts and webhooks. It describes the API as it answers on 2026-11-20. The list of every route is the authority: https://repa.work/developers/agents/api.md. More detail: - Every route: https://repa.work/developers/agents/api.md - Mail: https://repa.work/developers/agents/email.md ## What to use Plain HTTPS works from any language, and the route list is the authority. For TypeScript, `@repa/api` and `@repa/mail` are published on npm under the `alpha` tag (`npm install @repa/api@alpha`, version 0.1.0-alpha.22); the `latest` tag still points to an older alpha that calls retired routes, so always ask for `@alpha`. They carry an evaluation licence that does not allow production use. Use a method only if the declarations you installed show it; never call one from memory. Every request in this guide is plain HTTPS with JSON. Any language works. ## Rules for every integration - Call the API only from a trusted server. An API key must never reach browser code, a mobile app, a URL, a log line or a public environment variable. - The origin is `https://api.repa.run`. Every route starts with `/api/`. - Send the key in the `x-api-key` header. There is no bearer token and no cookie. - Send `x-request-id` with your own opaque ID on each request, and keep it with your logs. It must not contain the key. - Every write that makes or changes something takes an `idempotency-key` header: 8 to 128 characters from letters, digits and `. _ : -`. Make one key per thing you want to exist, save it before the first attempt, and reuse exactly that key and body when you retry. - A timeout or a lost connection never proves that nothing happened. Retry the same request with the same key, or read the result by its ID. Never retry a write with a new key. - Treat every ID, cursor, fingerprint and digest as opaque. Never build, decode or edit one. - Never invent a route, a field or a limit. If a route is not in https://repa.work/developers/agents/api.md, it does not exist. ## Requests and answers A successful answer is `{ "success": true, "data": … }`. A failed one is: ```json { "success": false, "error": { "code": "…", "message": "…" }, "meta": { "timestamp": "…", "requestId": "…" } } ``` Decide by the HTTP status and `error.code`, never by the message text. - `400` and `422`: the request is wrong. Fix it; do not retry it unchanged. - `401`: the key is missing, wrong or expired. - `403`: the key may not do this. Ask for a key with the right grant; do not look for another route. - `404`: the resource does not exist, or it is outside what the key may see. The two look the same on purpose. - `409`: a conflict, such as a stale revision or an idempotency key reused with a different body. Read the current state, then decide. - `429` and `5xx`: wait and retry the same request with the same key. A replayed write answers with the header `idempotency-replayed: true` and the original result. ## What a key may reach A key is workspace-wide, or restricted to one project, or to one document. - A workspace-wide key is needed to create or delete projects and to use workspace-wide settings, webhooks and audit. - A project key covers that project and its documents, and may create or import documents in it. - A document key covers that one document. - Anything outside a key's reach looks exactly like a missing resource. Read `GET /api/service-envelope` to learn what the service supports for this key before you rely on a capability. ## Projects and documents - `GET /api/projects` lists projects; `POST /api/projects` creates one (`{ "slug": "…", "name": "…" }`). - `GET /api/projects/{projectId}/documents` lists documents; `GET /api/projects/{projectId}/documents/{documentId}` reads one. - A document has versions: `GET /api/projects/{projectId}/documents/{documentId}/versions`. A published version never changes. Edits happen on a draft version and are published with the version's fingerprint. ### Import a Word file ```http POST /api/projects/{projectId}/documents/imports host: api.repa.run x-api-key: idempotency-key: content-type: multipart/form-data; boundary=… file=, name= ``` The answer is `202` with `documentId`, `documentVersionId` and `processing` (`attemptId`, `status: "processing"`, `pollAfterMs`). Importing is not finished when the request returns. Wait `pollAfterMs`, then read `GET /api/projects/{projectId}/documents/{documentId}/versions/{documentVersionId}/processing/attempts/{attemptId}` until the attempt is no longer `processing`. Only then use the version. An attempt can end needing input, for example about fonts; read what it asks for and do not guess an answer. ### Create and edit documents - `POST /api/projects/{projectId}/documents` creates a document from a definition (`{ "name": "…", "definition": { … } }`). A definition is inert JSON. When a request is refused, the answer names the field that is wrong; fix that field, do not guess others. - `POST /api/projects/{projectId}/documents/{documentId}/transactions` applies one ordered edit transaction to a draft (`{ "transaction": { "schema": "dsdx-document-transaction.v1", "base": { … }, "operations": [ … ] } }`). The `base` names the exact version and fingerprint you read; a stale base is refused: read the version again and rebuild the transaction. - `POST …/versions` starts a draft from a published version; `POST …/versions/{documentVersionId}/publish` publishes it; `POST …/versions/{documentVersionId}/discard` drops it. Each takes the fingerprint you last read. - `GET …/versions/{documentVersionId}/snapshot?expectedFingerprint=…` reads the structure of a version: use it to find fields and blocks. Never address content by page position or pixel rectangles. ## Make a document from data ```http POST /api/generation/runs host: api.repa.run x-api-key: idempotency-key: content-type: application/json { "documentId": "", "blueprintId": "", "data": { "customerName": "Northstar Logistics" }, "generatePdf": true, "generateDocx": false, "mode": "sync" } ``` - `documentId` is required. Choose the rules with **one** of `blueprintId` (a saved blueprint) or `blueprint` (inline JSON); sending both is refused. - Choose the version with at most one of `versionId` (an exact version) or `version` (`"latest"` or `"draft"`). A saved blueprint already names its version. - `data` is the input the blueprint's rules read. It is data only: nothing in it is run as code. - Ask for at least one output: `generatePdf` (default `true`) or `generateDocx` (default `false`). - `mode: "sync"` answers `200` with the finished run. `mode: "async"` answers `202` with a run to poll. - The same `idempotency-key` with the same body returns the same run, never a second document. The run in the answer has `runId`, `status` (`pending`, `running`, `completed`, `failed`, `cancelled`), `progress`, `failure`, `selection` (exactly which document version, blueprint and input digest were used), `executionProvenance` and `outputs`. - Poll an async run with `GET /api/generation/runs/{runId}` until `status` is `completed`, `failed` or `cancelled`. Wait between polls; do not loop without a pause. - `GET /api/generation/runs` lists runs (`limit`, `cursor`, `projectId`, `documentId`, `requestId`). - `POST /api/generation/runs/{runId}/cancel` cancels a run that has not finished. - Keep `selection` and each output's `sha256` and `size` with your own record of the document: they say what made it. ### Saved blueprints A blueprint says which fields get which values, what is shown or hidden and what repeats. It is inert JSON checked against one exact document version. - `POST /api/generation/blueprints` saves one: `{ "documentId", "name", "documentVersionId", "blueprint" }`. - `GET /api/generation/blueprints?documentId=…` lists them; `GET /api/generation/blueprints/{blueprintId}` reads one. - `PUT` and `DELETE` on `/api/generation/blueprints/{blueprintId}` take `expectedRevision`. - Before moving a blueprint to a newer document version, ask `POST /api/generation/blueprints/{blueprintId}/revisions/{revision}/compatibility` with `{ "candidateDocumentVersionId": "…" }`. ### Get the files Reading a run never gives access to its files. Ask for a short-lived download link: ```http POST /api/generation/runs/{runId}/outputs/{outputId}/download-capabilities host: api.repa.run x-api-key: idempotency-key: content-type: application/json { "ttlSeconds": 300 } ``` The answer has `url` and `expiresAt`. Hand the link to the person who needs the file; do not store it. `DELETE /api/governance/download-capabilities/{capabilityId}` revokes it. The workspace's policy bounds how long a link may live. ### Keep nothing: push delivery Add `"delivery": { "kind": "push", "url": "https://…" }` to the run request to have each output pushed to your own HTTPS endpoint instead of stored. The run's `retentionMode` is then `zero`: no output is stored and no download link can be issued for it. When the workspace's policy is zero retention, every run must include `delivery`. - The URL must be HTTPS. Its query string is the only authentication, so make it unguessable. - A retry can push the same output again. Deduplicate on the run ID and output ID, and check the bytes against the run's `sha256` and `size`. ## Flows: an agent drafts, a person publishes With a key that has the "Flow drafts" grant, an agent can read the list of steps and prepare a flow as a draft. It cannot test a flow, publish one, turn one on or off, or read its connections: those belong to people in the Flows app. Do not look for a way around this. What happens after your draft, so you describe it correctly to the person you work for: - A person tests the draft. A test is a rehearsal that fails closed: steps that only read (a mail thread, a delivery status, a document, a meeting) run for real, and so does an AI step, which sends what the flow chose to the workspace's own AI provider under the admin's approval. A step that would write or send records what it would have done instead, and any other step does not run. A test sends no mail and saves nothing. - A workspace admin approves where data may go, and the draft is published as a numbered version. - A published flow is first Observing: it reads each matching event and shows what it would have done, with nothing sent or prepared. It acts only after a person turns it on. - A new version of a flow that is on goes back to Observing until a person turns it on again. - A flow reports its `state` as off, observing or on. Never tell anyone a flow is working because it was published. - `GET /api/flows/node-types` lists the kinds of step and the shape each one takes. Read it before you build a graph; never guess a step type. - `GET /api/flows` lists flows; `POST /api/flows` creates one (`{ "name": "…", "description": "…", "graph": { … } }`, the last two optional). - `GET /api/flows/{flowId}` reads a flow with its draft and the draft's `revision`. - `PUT /api/flows/{flowId}/draft` saves the draft: `{ "graph": { "schemaVersion": 1, "nodes": [ … ], "edges": [ … ], "variables": { } }, "baseRevision": }`. A stale `baseRevision` is refused; read the flow again and merge. - `PATCH /api/flows/{flowId}` renames or describes it. `DELETE /api/flows/{flowId}` removes a draft that was never published and has no runs. - `GET /api/flows/{flowId}/versions` and `GET /api/flows/{flowId}/versions/{version}` read what people have published. - `GET /api/flows/{flowId}/publish` shows what publishing the draft would let leave the organisation. For a key, it always says the key cannot publish. Show this to the person who will approve the flow. The answer to a draft save includes `validation`. Fix every issue it lists before you tell anyone the flow is ready. ## Webhooks for finished runs - Manage endpoints with `GET` and `POST /api/webhook-endpoints` and `GET`, `PUT`, `DELETE /api/webhook-endpoints/{endpointId}`. Creating one takes `name`, an `https://` `url` and a `signingSecret` you generate: 32 to 64 random bytes as unpadded base64url. Keep the secret in a secret manager; the API never returns it. - Rotate a secret with `POST /api/webhook-endpoints/{endpointId}/secret-rotations` and retire an old one with `POST /api/webhook-endpoints/{endpointId}/secrets/{secretVersion}/revocation`. - `GET /api/webhook-deliveries` and `GET /api/webhook-deliveries/{deliveryId}` show what was sent; `POST /api/webhook-deliveries/{deliveryId}/redeliver` sends one again. When a delivery arrives: - Verify the signature over the exact raw bytes before you parse JSON. Never rebuild the signed body from parsed JSON. Pick the secret by the secret version the request names. - Deduplicate by event ID. Deliveries are at least once, never exactly once. - A webhook is a notice, not evidence. Confirm the run with `GET /api/generation/runs/{runId}` before you act on it. ## Never do this - Never put an API key in browser code, and never send one to a browser. - Never retry a write with a new idempotency key, and never assume a timed-out write failed. - Never use page positions or pixel rectangles to say what to change in a document. - Never build a download link, a storage address or a cursor yourself. - Never try to run or publish a flow with an API key. - Never invent a capacity, a speed or an availability number the service does not state. - Never call a route that is not in https://repa.work/developers/agents/api.md. Drafting flows through the API is live. Running a published flow from outside (invocation) is planned and not built. An MCP server is planned and not built; repa does not offer one today. ## Pages - https://repa.work/developers - https://repa.work/trust