Document Generation API

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.

POST https://pylon-doc-gen-api.fly.dev/generate

Endpoints

MethodPathDescription
POST/generateGenerate a PDF document (payment required)
GET/templatesList available templates and fields (free)
GET/healthHealth check (free)

Templates

Invoice

FieldTypeRequiredDescription
companystringYesYour company name
tostringYesBill to (recipient)
itemsarrayYesLine items: [{name, qty, price}]
totalnumberYesTotal amount
due_datestringYesDue date
invoice_numberstringYesInvoice number
notesstringNoOptional notes

Receipt

Fields: merchant, items[] (name, price, qty?), total, date, transaction_id

Report

Fields: title, author (optional), date (optional), sections[] (heading, content)

Letter

Fields: from, to, date, subject (optional), body, signature

Custom HTML

Instead of a named template, provide custom_html with Handlebars syntax ({{variable}}) and the data object.

Response

Returns a PDF binary with Content-Type: application/pdf.

Pricing

$0.02 USDC per document — paid via x402 on Base (Coinbase L2).

Code Examples

# 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": { ... }
    }
  }'

x402 Setup

To use Pylon APIs, you need an x402-compatible client with a funded wallet on Base. See x402.org for client libraries.