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

# Render PDF

> Render PDFs over HTTP with the self-hosted server — inline templates, pre-compiled templates by slug, and form flattening.

These endpoints are served by the **self-hosted server** — the same engine behind `npm install`, packaged as a Docker image:

```bash theme={null}
docker run -p 3000:3000 formepdf/forme
```

Base URL below is `http://localhost:3000` (substitute your deployment). Authentication is optional: set the `FORME_API_KEY` environment variable on the container and pass it as a Bearer token; with no key set, endpoints are open. See [Self-Hosting](https://docs.formepdf.com/self-hosting.md) for full setup.

> [!NOTE]
>
> Forme also runs a [hosted API](https://docs.formepdf.com/hosted-api.md) at `https://api.formepdf.com`, in the same `/v1` route family. It adds saved JSX and HTML + Liquid templates, `POST /v1/render/html`, async jobs with webhooks, S3 upload, document storage, and `POST /v1/extract`. Its request bodies differ in places: see [Hosted API — Render](https://docs.formepdf.com/hosted-api/render.md). If you'd rather not run a server at all, every operation here is also a function call in [@formepdf/core](https://docs.formepdf.com/typescript-sdk.md).

***

## Render PDF (inline)

`POST /v1/render`

Renders a compiled template sent in the request. Fully stateless.

**Body:**

| Field | Type | Required | Description |
| - | - | - | - |
| `template` | `object` | Yes | The compiled document JSON tree — the output of `forme build --template` or `serialize()` from `@formepdf/react` |
| `data` | `object` | No | Template data. When present, template expressions (`$ref`, `$each`, `$if`) are evaluated against it. |

```bash theme={null}
curl -X POST http://localhost:3000/v1/render \
  -H "Content-Type: application/json" \
  -d '{"template": {"children": [{"kind": {"type": "Page"}, "children": [{"kind": {"type": "Text", "content": "Hello"}}]}]}, "data": {"customer": "Acme"}}' \
  --output hello.pdf
```

**Response:** `200 OK` with `Content-Type: application/pdf` body.

***

## Render PDF (template by slug)

`POST /v1/render/:slug`

Renders a pre-compiled JSON template from the directory set by `FORME_TEMPLATES_DIR` (`{slug}.json`). See [Self-Hosting — Template render](https://docs.formepdf.com/self-hosting.md#template-render).

**Path params:** `slug` — the template file name without `.json`.

**Body:**

| Field | Type | Required | Description |
| - | - | - | - |
| `data` | `object` | No | Template data, evaluated against the template's expressions |

```bash curl theme={null}
curl http://localhost:3000/v1/render/invoice \
  -H "Authorization: Bearer your-secret-key" \
  -H "Content-Type: application/json" \
  -d '{"data": {"clientName": "Jane Smith", "date": "2026-01-15", "dueDate": "2026-02-15", "items": [{"description": "Consulting", "quantity": 10, "unitPrice": 150}]}}' \
  --output invoice.pdf
```

```javascript Node.js theme={null}
const res = await fetch("http://localhost:3000/v1/render/invoice", {
  method: "POST",
  headers: {
    Authorization: "Bearer your-secret-key",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    data: {
      clientName: "Jane Smith",
      date: "2026-01-15",
      dueDate: "2026-02-15",
      items: [{ description: "Consulting", quantity: 10, unitPrice: 150 }],
    },
  }),
});

const pdf = Buffer.from(await res.arrayBuffer());
fs.writeFileSync("invoice.pdf", pdf);
```

```python Python theme={null}
import requests

res = requests.post(
    "http://localhost:3000/v1/render/invoice",
    headers={"Authorization": "Bearer your-secret-key"},
    json={
        "data": {
            "clientName": "Jane Smith",
            "date": "2026-01-15",
            "dueDate": "2026-02-15",
            "items": [{"description": "Consulting", "quantity": 10, "unitPrice": 150}],
        }
    },
)

with open("invoice.pdf", "wb") as f:
    f.write(res.content)
```

```go Go theme={null}
package main

import (
	"bytes"
	"encoding/json"
	"io"
	"net/http"
	"os"
)

func main() {
	body, _ := json.Marshal(map[string]any{
		"data": map[string]any{
			"clientName": "Jane Smith",
			"date":       "2026-01-15",
			"dueDate":    "2026-02-15",
			"items": []map[string]any{
				{"description": "Consulting", "quantity": 10, "unitPrice": 150},
			},
		},
	})

	req, _ := http.NewRequest("POST", "http://localhost:3000/v1/render/invoice", bytes.NewReader(body))
	req.Header.Set("Authorization", "Bearer your-secret-key")
	req.Header.Set("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)
	defer res.Body.Close()

	out, _ := os.Create("invoice.pdf")
	io.Copy(out, res.Body)
}
```

**Response:** `200 OK` with `Content-Type: application/pdf` body. An unknown slug returns `404`.

***

## Flatten Forms

`POST /v1/render?flattenForms=true` or `POST /v1/render/:slug?flattenForms=true`

Render a PDF with all form fields flattened — interactive fields are converted to static content. Useful for filling a form template with data and sending a non-editable PDF.

***

## Embedded Data

The self-hosted server has no `/v1/extract` endpoint. To read data embedded with `embedData`, call `extractData()` from `@formepdf/core`, or use [`POST /v1/extract`](https://docs.formepdf.com/hosted-api/extract) on the hosted API. See [Embedded Data](https://docs.formepdf.com/embedded-data.md).

***

## Error Format

All errors return JSON:

```json theme={null}
{ "error": "Human-readable error message", "code": "BAD_REQUEST" }
```

Common HTTP status codes:

* `400` — Invalid request, or the render failed (`code`: `BAD_REQUEST`, `RENDER_FAILED`). Hosted-only fields such as `certificateId` and a redaction `template` also return `400`.
* `401` — Missing or wrong API key, when `FORME_API_KEY` is set
* `404` — Template not found
* `501` — Resource listing (`GET /v1/templates`, `/v1/documents`, …), which is hosted-only
* `500` — Internal server error


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