Generate professional PDF documents from templates and data. Choose from built-in templates (invoice, receipt, report, letter) or provide your own HTML with Handlebars placeholders. Returns a rendered PDF.
| Method | Path | Description |
|---|---|---|
POST | /generate | Generate a PDF document (payment required) |
GET | /templates | List available templates and fields (free) |
GET | /health | Health check (free) |
| Field | Type | Required | Description |
|---|---|---|---|
company | string | Yes | Your company name |
to | string | Yes | Bill to (recipient) |
items | array | Yes | Line items: [{name, qty, price}] |
total | number | Yes | Total amount |
due_date | string | Yes | Due date |
invoice_number | string | Yes | Invoice number |
notes | string | No | Optional notes |
Fields: merchant, items[] (name, price, qty?), total, date, transaction_id
Fields: title, author (optional), date (optional), sections[] (heading, content)
Fields: from, to, date, subject (optional), body, signature
Instead of a named template, provide custom_html with Handlebars syntax ({{variable}}) and the data object.
Returns a PDF binary with Content-Type: application/pdf.
$0.02 USDC per document — paid via x402 on Base (Coinbase L2).
# Generate an invoice
curl -X POST "https://pylon-doc-gen-api.fly.dev/generate" \
-H "Content-Type: application/json" \
-d '{
"template": "invoice",
"data": {
"company": "Acme Winery",
"to": "Bay Area Wine Shop",
"items": [
{"name": "2023 Cabernet Sauvignon", "qty": 12, "price": 24.00},
{"name": "2024 Rosé", "qty": 6, "price": 18.00}
],
"total": 396.00,
"due_date": "2026-03-15",
"invoice_number": "INV-001"
}
}' \
--output invoice.pdf
import { wrapFetch } from "@x402/fetch";
import fs from "fs";
const fetchWithPayment = wrapFetch(fetch, wallet);
const res = await fetchWithPayment(
"https://pylon-doc-gen-api.fly.dev/generate",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
template: "invoice",
data: {
company: "Acme Winery",
to: "Bay Area Wine Shop",
items: [{ name: "Cabernet", qty: 12, price: 24 }],
total: 288,
due_date: "2026-03-15",
invoice_number: "INV-001"
}
})
}
);
const buf = Buffer.from(await res.arrayBuffer());
fs.writeFileSync("invoice.pdf", buf);
import requests, json
response = requests.post(
"https://pylon-doc-gen-api.fly.dev/generate",
json={
"template": "invoice",
"data": {
"company": "Acme Winery",
"to": "Bay Area Wine Shop",
"items": [{"name": "Cabernet", "qty": 12, "price": 24}],
"total": 288,
"due_date": "2026-03-15",
"invoice_number": "INV-001"
}
}
)
with open("invoice.pdf", "wb") as f:
f.write(response.content)
# Via the Pylon Gateway
curl -X POST "https://pylon-gateway-api.fly.dev/route" \
-H "Content-Type: application/json" \
-d '{
"query": "generate an invoice for Acme Winery",
"params": {
"template": "invoice",
"data": { ... }
}
}'
To use Pylon APIs, you need an x402-compatible client with a funded wallet on Base. See x402.org for client libraries.