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

# Generate your first document

> Run the renderer, place the documents library and render a note to PDF.

> [!NOTE]
>
> These examples describe the current Bijection CLI and SDK source. Use builds
> from the same source commit for these APIs. The public CLI and npm SDK
> are published independently and may lag this reference.

A report is one task to a renderer you run. The renderer renders the frozen
input in a worker without credentials, validates the exact bytes in another,
and posts each file to your app's upload route. Nothing renders on
Bijection's side.

## 1. Place the library with a renderer

```ts app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, role, secret } from "@bijectionhq/bijection";
import { documents } from "@bijectionhq/library-documents";

export const workspace = label();
export const editor = role({ clear: [workspace] });
export const rendererKey = secret();
export const uploadKey = secret();

export default app({
  workspace, editor, rendererKey, uploadKey,
  docs: documents({
    label: workspace,
    editors: [editor],
    roles: [editor],
    renderer: {
      endpoint: "https://renderer.example.com",
      bearer: rendererKey,          // what the app presents to the renderer
      upload: uploadKey,            // what the renderer presents to the upload route
      // route: "/documents/renders", lifetime: { days: 30 }
    },
  }),
});
```

The renderer's clearance is the library's label: a document's text leaves
that label only as a render request to it. The upload route defaults to
`POST /documents/renders` and is bearer-verified with `upload`.

## 2. Run the renderer

The renderer server ships in the package (`pnpm renderer`, which runs
`src/renderer/serve.ts`). Run it behind HTTPS on infrastructure you control:

| Variable | Meaning |
| - | - |
| `PORT` | Where it listens (8080 by default). |
| `DOCUMENTS_RENDERER_TOKEN` | The bearer the app presents (the value of `rendererKey`). |
| `DOCUMENTS_UPLOAD_URL` | The app's upload route, `https://<site>/documents/renders`. |
| `DOCUMENTS_UPLOAD_TOKEN` | The bearer it presents to that route (the value of `uploadKey`). |
| `DOCUMENTS_RENDER_MEMORY_MB`, `DOCUMENTS_VALIDATION_MEMORY_MB` | The render and validation workers' heaps. |

## 3. Deploy and set the secrets

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection deploy
bijection secret set rendererKey
bijection secret set uploadKey
```

Grant `editor` to a person under `workspace` from one of your mutations, with
`ctx.grant(editor, { to, under })` ([Grants](https://docs.bijection.com/access/grants.md)).

## 4. Generate a PDF

Write a note, then generate a report from its current text:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection mutate docs.reports.generate space=project-42 doc=<doc> formats='["pdf"]' \
  expected=null kind=null locale=null timeZone=null --as person:ada
bijection query docs.reports.get space=project-42 report=<report> --as person:ada
```

`reports.generate` answers the report's key and marks it `rendering`. When
the render task settles, the library attaches the uploaded files whose
SHA-256 matches the task's result and marks the report `ready`, or `failed`
with the code and message. A report stays at the library's label until
someone [releases it](https://docs.bijection.com/files/documents/reports.md#release-a-report).

## What stays yours

* Hosting the renderer: HTTPS, capacity and restarts.
* A mail provider or other receiver, only if you deliver released files
  outside the app.


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