API Reference

Generate beautiful PDFs and HTML documents from your templates with a simple HTTP API.

Authentication

All API requests require a bearer token in the Authorization header. Create and manage your API keys from Settings → API Keys.

Authorization: Bearer pf_live_…

Keep your keys secret. Do not commit them to version control or expose them in client-side code.

Base URL

https://your-project.lovable.app

All endpoints are prefixed with /api/public/v1.

Render a document

POST/api/public/v1/render?format=html|pdf

POST a template ID and JSON data. Returns interpolated HTML by default, or a PDF binary when format=pdf is set.

Request body

ParameterTypeRequiredDescription
template_idstringYesID of the template to render. Found in the template editor URL.
dataobjectNoJSON payload to interpolate into the template. Falls back to the template's sample JSON.
formatstringNoOverride output format: 'html' or 'pdf'. Defaults to 'html'.

Query parameters

ParameterTypeRequiredDescription
formatstringNoSame as body.format. Query string takes precedence.

Request headers

ParameterTypeRequiredDescription
AuthorizationstringYesBearer token with your API key.
Content-TypestringYesMust be application/json.
AcceptstringNoSet to application/pdf to default to PDF output.

Response — HTML (default)

Status: 200 OK

Content-Type: text/html; charset=utf-8

Response — PDF

Status: 200 OK

Content-Type: application/pdf

Content-Disposition: inline; filename="document_name.pdf"

Example — HTML

curl -X POST https://your-project.lovable.app/api/public/v1/render \
  -H "Authorization: Bearer pf_live_…" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "550e8400-e29b-41d4-a716-446655440000",
    "data": {
      "customer": "Acme Corp",
      "invoice_id": "INV-001",
      "total": 1240.00
    }
  }'

Example — PDF

curl -X POST "https://your-project.lovable.app/api/public/v1/render?format=pdf" \
  -H "Authorization: Bearer pf_live_…" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "550e8400-e29b-41d4-a716-446655440000",
    "data": { "customer": "Acme Corp", "total": 1240.00 }
  }' \
  --output invoice.pdf

Check usage

GET/api/public/v1/usage

Returns your current month's API request count and PDF generation count.

Request headers

ParameterTypeRequiredDescription
AuthorizationstringYesBearer token with your API key.

Response

Status: 200 OK

Content-Type: application/json

{
  "month": "2026-06",
  "api_requests": 42,
  "pdfs_generated": 17,
  "storage_bytes": 0
}

Example

curl https://your-project.lovable.app/api/public/v1/usage \
  -H "Authorization: Bearer pf_live_…"

Errors

Errors are returned as JSON with an error field.

ParameterTypeRequiredDescription
400NoBad Request — Invalid JSON, missing template_id, or invalid format.
401NoUnauthorized — Missing, invalid, or revoked API key.
404NoNot Found — Template does not exist or does not belong to you.
500NoInternal Server Error — Database or auth lookup failure.
502NoBad Gateway — PDF rendering service returned an error.
503NoService Unavailable — PDF rendering is not configured.
{
  "error": "template_id is required"
}

More examples

Node.js / fetch

const res = await fetch("https://your-project.lovable.app/api/public/v1/render?format=pdf", {
  method: "POST",
  headers: {
    "Authorization": "Bearer pf_live_…",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    template_id: "YOUR_TEMPLATE_ID",
    data: { customer: "Acme", total: 1240 },
  }),
});

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

Python / requests

import requests

res = requests.post(
    "https://your-project.lovable.app/api/public/v1/render?format=pdf",
    headers={"Authorization": "Bearer pf_live_…"},
    json={
        "template_id": "YOUR_TEMPLATE_ID",
        "data": {"customer": "Acme", "total": 1240},
    },
)

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