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.appAll endpoints are prefixed with /api/public/v1.
Render a document
/api/public/v1/render?format=html|pdfPOST a template ID and JSON data. Returns interpolated HTML by default, or a PDF binary when format=pdf is set.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| template_id | string | Yes | ID of the template to render. Found in the template editor URL. |
| data | object | No | JSON payload to interpolate into the template. Falls back to the template's sample JSON. |
| format | string | No | Override output format: 'html' or 'pdf'. Defaults to 'html'. |
Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| format | string | No | Same as body.format. Query string takes precedence. |
Request headers
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer token with your API key. |
| Content-Type | string | Yes | Must be application/json. |
| Accept | string | No | Set 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.pdfCheck usage
/api/public/v1/usageReturns your current month's API request count and PDF generation count.
Request headers
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| 400 | No | Bad Request — Invalid JSON, missing template_id, or invalid format. | |
| 401 | No | Unauthorized — Missing, invalid, or revoked API key. | |
| 404 | No | Not Found — Template does not exist or does not belong to you. | |
| 500 | No | Internal Server Error — Database or auth lookup failure. | |
| 502 | No | Bad Gateway — PDF rendering service returned an error. | |
| 503 | No | Service 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)