# Leafwright — full content for LLMs
> Generate PDFs without running headless Chrome. Leafwright (https://leafwright.co) is a document studio and PDF API: render HTML, public URLs, or Handlebars templates to PDF with one API call — no headless Chrome in your bundle. AI drafts templates and repairs them from render logs. Free tier: 100 PDFs/month, no credit card.
## API quickstart
Render HTML to a PDF with one call:
```sh
export LEAFWRIGHT_API_KEY="paste-your-key-here" # Dashboard → API keys → Create test key
curl -X POST https://leafwright.co/api/v1/pdfs \
-H "Authorization: Bearer $LEAFWRIGHT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":{"type":"html","html":"
Hello from Leafwright
"},"delivery":{"mode":"sync","return":"bytes"}}' \
-o hello.pdf
```
The response includes a job id and a signed download_url. Published templates render via POST https://leafwright.co/api/v1/templates/{id}/render with a JSON data payload. Every render is a tracked job with readable logs, retries, and optional webhooks. Full reference: https://leafwright.co/docs/api
## MCP for AI agents
Remote MCP server (OAuth 2.1 + PKCE + Dynamic Client Registration): https://leafwright.co/mcp
Leafwright’s Claude and OpenAI plugin directory submissions are awaiting approval (last checked October 10, 2026). You can connect now using the direct MCP options below, or install the Claude Code plugin from its public GitHub marketplace.
- Claude: add the custom connector manually; a marketplace listing is not required.
1. Open Customize → Connectors → + Add → Add custom connector in Claude.
2. Name it Leafwright and enter https://leafwright.co/mcp as the remote MCP server URL.
3. Choose OAuth authentication. If Claude shows an OAuth client choice, select Register automatically; leave custom client ID and client secret empty.
4. Finish adding the connector, then connect and sign in to Leafwright. Choose your organization and default project, and approve access.
5. Enable Leafwright for your conversation from + → Connectors.
On Team and Enterprise plans, an owner first adds it in Organization settings → Connectors.
- Claude Code: run `claude mcp add --transport http leafwright https://leafwright.co/mcp`, then use /mcp to authenticate.
- ChatGPT: create a custom MCP plugin; account and workspace permissions apply.
1. Open ChatGPT → Plugins, select +, then Add custom MCP server.
2. Name it Leafwright, add a description, and enter https://leafwright.co/mcp as the public server URL.
3. Choose OAuth authentication, review the access notice, and create the custom plugin.
4. Review the discovered tools, install the custom plugin, and sign in to Leafwright when prompted. Choose your organization and default project.
5. Start a new conversation, type @, and select your Leafwright custom plugin.
Official custom MCP guide: https://developers.openai.com/plugins/deploy/connect-chatgpt
Codex — direct hosted MCP (no directory plugin required):
```sh
codex mcp add leafwright --url https://leafwright.co/mcp
codex mcp login leafwright
```
Complete browser sign-in, choose an organization and project, and restart your client or start a new session. Use /mcp to check the connection.
Alternatively add this to ~/.codex/config.toml, then run codex mcp login leafwright:
```toml
[mcp_servers.leafwright]
url = "https://leafwright.co/mcp"
```
Direct MCP provides tools; the submitted OpenAI plugin’s bundled PDF skill awaits directory approval and publication.
Local stdio — Node.js and npm required: `npx -y @leafwright/mcp`.
Configure Claude Code or Cursor with command npx and args ["-y", "@leafwright/mcp"]. Codex uses TOML in ~/.codex/config.toml:
```toml
[mcp_servers.leafwright]
command = "npx"
args = ["-y", "@leafwright/mcp"]
```
Restart the client, call leafwright_login, approve access in the browser, then call leafwright_auth_status to complete login. Choose either hosted MCP or local stdio for a client.
Optional Claude Code plugin: Install from Leafwright’s public GitHub marketplace. You must add that marketplace first; searching Anthropic’s built-in marketplace does not add it. The plugin configures the MCP server, and you still need to sign in.
```text
/plugin marketplace add Tactic-Systems/leafwright-claude-plugin
/plugin install leafwright@leafwright
```
Key tools:
- leafwright_render_html: Render raw HTML to a PDF (signed URL).
- leafwright_render_url: Render a public URL to a PDF (SSRF-protected).
- leafwright_render_template: Render a published template with JSON data.
- leafwright_create_template: Create a draft template.
- leafwright_update_template_draft: Update a draft's HTML, CSS, or sample data.
- leafwright_ai_generate_template: Generate a draft template from a prompt.
- leafwright_ai_revise_template: Revise a draft from an instruction.
- leafwright_ai_fix_from_logs: Repair a template from a failed render's logs.
- leafwright_get_job_logs: Render logs for debugging.
- leafwright_get_usage: Credits used and remaining.
Read-only mode: set LEAFWRIGHT_MCP_READ_ONLY=true. AI drafts templates; publishing always requires a human. Setup guide: https://leafwright.co/docs/mcp
## Frequently asked questions
### Is there a free plan?
Yes. Hobby includes 100 PDFs and 8 AI template drafts per month, with no credit card required. It is hard-capped — past the limit, renders pause until the next period or an upgrade.
### How is Leafwright different from running Puppeteer myself?
Puppeteer needs Chromium, and Chromium doesn't fit serverless: ~170 MB of browser against a 250 MB function limit, slow cold starts, memory spikes, and missing fonts. Leafwright runs the browser engine on its own rendering infrastructure — your function makes one API call and stays small.
### How does rendering work?
POST HTML, a public URL, or a published template plus JSON data to the render API. You get back a signed download URL, metadata, or raw bytes. Every render is a tracked job with readable logs, retries, and optional webhooks.
### Can AI agents and assistants use Leafwright?
Yes. Connect directly over MCP with OAuth in Claude, ChatGPT, Claude Code, or Codex, or use the local @leafwright/mcp package in a supported client. Claude Code also has a plugin available through Leafwright’s public GitHub marketplace. Custom connections depend on your account and workspace permissions. See the MCP setup guide for installation options while directory approvals are pending.
### What HTML is supported?
Full documents with inline CSS and data-URI images, up to 250 KB of HTML, 120 KB of CSS, and 200 pages per PDF. Scripts, iframes, external assets, and inline SVG are rejected by validation before rendering. To capture a public page with its remote assets, use the URL source type, which fetches behind SSRF protections.
### What happens when I hit my monthly limit?
Hobby stops rendering until the next period. Paid plans can enable metered overage, billed per additional PDF through Stripe, so batch jobs never fail at the end of the month.
### Where do my documents live?
Rendered PDFs are delivered through time-limited signed URLs. Projects can also bring their own storage — Amazon S3 via an assumed role (no long-lived keys) or Google Cloud Storage — so documents land directly in your bucket.
### Do templates support dynamic data?
Yes. Templates use Handlebars placeholders rendered with per-request JSON, and brand kit variables (logo, colors, footer) are injected automatically so every export stays on-brand.
## Compared with other PDF APIs
### Leafwright vs PDFMonkey (https://leafwright.co/vs/pdfmonkey)
The PDF API that doesn't make you build a template first.
Switch to Leafwright if you…
- already have the HTML — your app renders invoices or reports and you just need them as PDFs
- want AI to draft and repair templates instead of hand-maintaining Liquid or Vue
- connect AI agents over MCP — remote server or `npx -y @leafwright/mcp`
- want 5× the free monthly volume while you build (100 PDFs vs 20)
Stay on PDFMonkey if you…
- are invested in Liquid or Vue templates that already work
- drive documents from Zapier, Make, or n8n
- need JavaScript to run at render time, or PNG/WebP/JPG output
Pricing (verified September 2026):
- At 3,000 documents a month the two cost within a few dollars of each other (Indie $19 vs Pro €15) — price is not the reason to switch here.
- The gap is at zero: Leafwright's free tier carries 5× the monthly documents (100 vs 20), with AI template drafts included.
### Leafwright vs DocRaptor (https://leafwright.co/vs/docraptor)
A studio, an API, and about a tenth of the price per PDF.
Switch to Leafwright if you…
- render at volume — $79 covers 15,000 documents a month; the same spend covers ~1,250 on DocRaptor
- want templates managed for you: AI draft, brand kit, canvas, publish, then render by ID
- need webhooks on failure, not only on success
- connect AI agents over MCP
Stay on DocRaptor if you…
- depend on Prince paged media: mixed page sizes, footnotes, crop marks, CMYK, tagged PDFs
- export HTML to XLS/XLSX, or run JavaScript at render time
- need SOC 2 or HIPAA attestations today — DocRaptor publishes them, Leafwright doesn't
Pricing (verified September 2026):
- Same budget: at ~$75–79 a month, Leafwright includes 15,000 documents to DocRaptor's 1,250 — about 12× the volume.
- Same volume: 15,000 documents a month is $79 on Leafwright Pro and $399 on DocRaptor Bronze — about a fifth of the price.
## Guides
# Puppeteer doesn't work on Vercel. Here's the fix.
You wrote the PDF feature in ten minutes. `npm i puppeteer`, `page.setContent(html)`, `page.pdf()`. It worked perfectly on your laptop.
Then you ran `vercel deploy`, and it died.
```
Error: Could not find Chromium (rev. 1108766). This can occur if either
1. you did not perform an installation before running the script
2. your cache path is incorrectly configured
```
If you've been here, you know the next three hours: swapping in `@sparticuz/chromium`, bumping the function memory, hitting the 250 MB unzipped bundle limit, fighting cold starts, and discovering your fonts render as tofu boxes in production but not locally.
## Why it breaks
Headless Chrome was never designed to live inside a serverless function. The conflicts are structural, not a config you missed:
- **Bundle size.** Chromium is ~170 MB compressed. A standard Vercel or Lambda function caps out at 250 MB unzipped, so you're over budget before your own code. Vercel's Large Functions beta raises that to 5 GB on Fluid compute, which gets Chromium in the door and leaves every other problem on this list exactly where it was.
- **Cold starts.** Spinning up a fresh Chromium per invocation adds seconds. Under load you're launching dozens of browsers.
- **Memory.** Chromium wants 1 GB+ for anything non-trivial. Complex documents OOM and the function just... dies, with a useless log line.
- **Missing system libraries and fonts.** The base image doesn't ship the libs Chromium links against, or the fonts your CSS references. "Works on my machine" in its purest form.
- **Timeouts.** `waitUntil: "networkidle"` plus a slow asset and you've blown the function's execution limit.
## The hacks, and why they don't last
**`@sparticuz/chromium`** — a stripped Chromium build that fits the bundle. It works, until a Chromium version bump breaks the pairing with your `puppeteer-core`, or a heavier document OOMs anyway. You now own a fragile binary-compatibility problem forever.
**A second always-on server just for Chrome.** Now you're running and paying for a box 24/7, building your own queue, and reinventing retries — to render a PDF.
Both are the same mistake: **running a browser inside infrastructure that doesn't want one.**
## The fix: don't run Chrome at all
Move the render off your function. You send HTML, a hosted service runs Chromium on infrastructure built for it, you get a PDF back. Your serverless function stays tiny and stateless.
Here's the whole thing with [Leafwright](https://leafwright.co):
```ts
// app/api/invoice/route.ts — runs fine on Vercel, no Chromium in your bundle
export async function POST(req: Request) {
const { html } = await req.json();
const res = await fetch("https://leafwright.co/api/v1/pdfs", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LEAFWRIGHT_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
source: { type: "html", html },
delivery: { return: "url" }
})
});
const { download_url } = await res.json();
return Response.json({ download_url });
}
```
No `puppeteer` dependency. No `@sparticuz/chromium`. No memory tuning. The PDF comes back as a signed URL (or raw bytes, if you'd rather stream it), and every render is a tracked job with logs you can actually read when something fails.
## "But I render the same invoice every time"
Then don't ship HTML on every request — publish a template once and render it with JSON:
```ts
await fetch("https://leafwright.co/api/v1/templates/tmpl_invoice/render", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LEAFWRIGHT_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ data: { client: "Northwind", total: "$16,000" } })
});
```
And if you don't want to hand-write print CSS at all, AI can draft the template from a prompt and even repair it from the render logs when a layout breaks — but that's a different post.
## The point
Generating a PDF should be one API call, not an infrastructure project. If you're staring at a Chromium error in your Vercel logs right now, you can have a working PDF in about five minutes:
→ **[Start free — 100 PDFs/month, no credit card](https://leafwright.co)**
*Built on Next.js or Lambda? The example above is the entire integration. Swap in your HTML and ship.*
---
# Give Claude Code (or Cursor) the ability to make PDFs
Your AI coding agent can read your repo, run your tests, and refactor a module. But ask it to "add a PDF invoice to this app" and it does what you'd do: reaches for Puppeteer, writes code that won't deploy, and hands you a layout it can't actually see or test.
The Model Context Protocol fixes that by giving the agent a real tool to call. Install the Leafwright MCP server and your agent can **render PDFs, manage templates, and debug failures from logs** — directly, while it works.
## Install
Connect to the hosted server and sign in with OAuth:
```sh
# Claude Code
claude mcp add --transport http leafwright https://leafwright.co/mcp
# Then run /mcp inside Claude Code to authenticate.
# Codex
codex mcp add leafwright --url https://leafwright.co/mcp
codex mcp login leafwright
```
Claude Code can also install the PDF commands and skill from the public GitHub marketplace:
```text
/plugin marketplace add Tactic-Systems/leafwright-claude-plugin
/plugin install leafwright@leafwright
```
Run `/mcp` to authenticate after installing. The Claude and OpenAI directory
submissions are awaiting approval (last checked October 10, 2026); these direct
installation options are available while review is pending.
For local stdio, Node.js and npm are required. Claude Code’s project `.mcp.json`
and Cursor’s `~/.cursor/mcp.json` use this configuration:
```json
{
"mcpServers": {
"leafwright": {
"command": "npx",
"args": ["-y", "@leafwright/mcp"]
}
}
}
```
Codex uses TOML in `~/.codex/config.toml` instead:
```toml
[mcp_servers.leafwright]
command = "npx"
args = ["-y", "@leafwright/mcp"]
```
Restart the client, call `leafwright_login`, approve browser access, then call
`leafwright_auth_status`. A project API key is an alternative for automation.
See the [MCP setup guide](https://leafwright.co/docs/mcp) for ChatGPT custom MCP,
Claude custom connectors, and one-click Cursor installation.
## What the agent can now do
The server exposes the Leafwright API as tools the agent can call on its own:
- **Generate a PDF** from HTML or a URL
- **Render a template** with JSON data
- **Create and update templates** (drafts only — humans still publish)
- **Read render jobs and logs** to see exactly why a render failed
- **Estimate usage cost** before running a batch
So a prompt like *"generate a PDF invoice for order #1024 and give me the link"* becomes a tool call that returns a real, signed URL — not a code suggestion you have to wire up and deploy yourself.
## The part that actually matters: it can debug its own output
A code-only agent is flying blind on layout. It writes print CSS, can't see the result, and guesses. With Leafwright it doesn't have to:
1. Agent renders the template → the render **fails or looks wrong**.
2. Agent calls **get render logs** → reads the real failure: a font that 404'd, an asset that timed out, a CSS rule that overflowed the page.
3. Agent calls **fix-from-logs** → gets a corrected template, re-renders, confirms it's clean.
That's a closed feedback loop. The agent fixes the document the same way it fixes code — by reading the error and trying again — instead of handing you something broken.
## Safe by design
The MCP server only calls the public Leafwright API. It runs no shell commands from agent input, supports a read-only mode, and uses scoped authentication. AI drafts and revises templates; **publishing always requires a human**. You get the speed of an agent without handing it a footgun.
## Try it
If your agent already lives in your editor, this is the fastest way to give it a capability it's missing:
```bash
npx -y @leafwright/mcp
```
→ **[Get an API key — free, 100 PDFs/month](https://leafwright.co)** · [MCP setup docs](https://leafwright.co/docs/mcp)
---
# Add PDF export to your v0 or Lovable app in 5 minutes
You shipped a real app this weekend. v0 scaffolded the UI, you wired up the data, it looks great. Then your first user asks for the one thing the AI didn't build: **"Can I download this as a PDF?"**
So you reach for the obvious options, and they all disappoint:
- **`window.print()`** — gives you the browser's print dialog, page margins you don't control, and a result that looks like a 2009 web page, not a document.
- **A client-side library** (`jspdf`, `html2canvas`) — rasterizes your DOM into a blurry image, breaks on page boundaries, ignores half your CSS, and balloons your bundle.
- **Puppeteer** — the right rendering engine, but [it doesn't deploy on serverless](https://leafwright.co/blog/puppeteer-doesnt-work-on-vercel), and now you've lost the afternoon.
The clean answer is to render the PDF **on the server, with a real browser engine**, via one API call. Here's the whole thing.
## 1. Get a key
Sign up at [leafwright.co](https://leafwright.co), create a project, copy your `lw_live_…` key into `.env`:
```bash
LEAFWRIGHT_API_KEY=lw_live_xxxxxxxx
```
## 2. Add one route
Your app already renders the thing on screen as HTML. Send that HTML to the API and hand back a download link:
```ts
// app/api/export/route.ts
export async function POST(req: Request) {
const { html } = await req.json();
const res = await fetch("https://leafwright.co/api/v1/pdfs", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LEAFWRIGHT_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
source: { type: "html", html },
delivery: { return: "url" }
})
});
const { download_url } = await res.json();
return Response.json({ download_url });
}
```
## 3. Wire up the button
```tsx
async function downloadPdf(html: string) {
const res = await fetch("/api/export", {
method: "POST",
body: JSON.stringify({ html })
});
const { download_url } = await res.json();
window.open(download_url, "_blank");
}
```
That's it. Server-side Chromium renders your HTML exactly as a browser would — real fonts, real CSS, proper page breaks — and returns a signed URL.
## Don't want to write print CSS?
Screen CSS and print CSS aren't the same, and getting page breaks, headers, and margins right is fiddly. So skip it: describe the document and let AI draft a clean, branded template for you, then render it with your data:
```ts
// Render a published template with JSON instead of raw HTML
await fetch("https://leafwright.co/api/v1/templates/tmpl_receipt/render", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LEAFWRIGHT_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ data: { order_id: "1024", total: "$59.00" } })
});
```
Lock your fonts, colors, and footer into a brand kit once, and every export — whether a user clicks the button or your backend generates 10,000 receipts overnight — comes out on-brand.
## Ship it
PDF export is the feature that makes a weekend project feel like a product. It shouldn't take more than the five minutes above.
→ **[Start free — 100 PDFs/month, no credit card](https://leafwright.co)**