API
Make PDFs from your own code
Everything the app does, from your server: send a template and spreadsheet rows, get a PDF for every row (or every group of rows) back. The API needs the API plan: $19 a month for 5,000 PDFs, up to 5,000 in one request. The app itself stays free.
1. Get a key
In the app, open Account, then API, and make a key. It's shown once; keep it on your server (an environment variable), never in a web page. Send it with every request:
Authorization: Bearer tpdf_…
You can have up to 10 keys and revoke any of them from the same page.
2. Design the template in the app
Easiest: make the design in the app with an example and your own spreadsheet, check the preview, and save it (Save as my template). In Templates, “Copy id” gives you its templateId. The values you typed in “Same on every PDF” are saved with it. You can also send the HTML yourself as templateHtml.
3. Make PDFs
curl https://pdf-api.thrifa.io/batches \
-H "Authorization: Bearer $THRIFA_PDF_KEY" \
-H "Content-Type: application/json" \
-d '{
"templateId": "YOUR-TEMPLATE-ID",
"csv": "Invoice Number,Client,Item,Amount\nINV-1,Harbor & Co,Logo,$1200.00\nINV-1,Harbor & Co,Guide,$850.50",
"groupBy": "Invoice Number",
"output": "zip"
}'The answer has the batch's id. Batches run in the background, usually a few seconds for a few dozen PDFs. Ask for its status until it's done:
curl https://pdf-api.thrifa.io/batches/BATCH-ID \ -H "Authorization: Bearer $THRIFA_PDF_KEY"
{
"batch": {
"id": "6f1c…",
"status": "done", // queued, running, done, failed or canceled
"total": 2, // PDFs in this batch
"done": 2,
"failed": 0,
"errors": [], // [{ "row": 3, "message": "…" }] for PDFs that failed
"downloadUrl": "https://pdf-api.thrifa.io/batches/6f1c…/download?token=…",
"expiresAt": "2026-11-12T10:00:00Z"
}
}Download from downloadUrl; it needs no key and works for 7 days.
POST /batches
| Field | What it is |
|---|---|
templateId | A template saved in your account. Or send templateHtml instead. |
templateHtml | The template as HTML (up to 500 KB), with {{Column}} placeholders. |
rows | The rows: [{"Name": "Ada"}, …]. Or send csv instead. |
csv | The rows as CSV text, column names first (comma, semicolon or tab). |
groupBy | Optional. A column: rows with the same value make one PDF (an invoice with its lines). Without it, one PDF per row. |
fields | Optional. Values that are the same on every PDF: {"Your Business": "Northstar Studio"}. They add to the template's saved values. A real column of the same name wins. |
output | zip (default): separate PDFs in a ZIP. pdf: one PDF. sheet: small designs, several per Letter page. |
filenamePattern | Optional. Names inside the ZIP, like {{Invoice Number}} {{Client}}. |
name | Optional. The download's name. |
Other requests
GET /batches/:id | Status, progress, errors and the download link. |
POST /batches/:id/cancel | Stops a batch. Nothing of it is counted. |
POST /render | One PDF right away: send html, get the PDF file back. |
GET /me | Your plan and how many PDFs you have left this month. |
curl https://pdf-api.thrifa.io/render \
-H "Authorization: Bearer $THRIFA_PDF_KEY" \
-H "Content-Type: application/json" \
-d '{"html": "<h1>Hello</h1>", "filename": "hello.pdf"}' \
-o hello.pdfTemplate syntax
{{Client}}is replaced by the value of the Client column. Case, spaces,_and-don't matter.{{#each}}…{{/each}}repeats for every row in the PDF, like the lines of an invoice. Inside it,{{row}}counts 1, 2, 3. It can't be nested, and nothing goes after the word each.{{sum Amount}}adds up the Amount column over the PDF's rows, keeping a $ sign and the decimals.{{row}}: the PDF's number in the batch.- Page size and margins come from CSS:
@page { size: Letter; margin: 0.5in }. A4, Letter, landscape or a size like4in 6inall work. Without it, pages are A4.
What a template can use:
- One HTML file, with the CSS in a
<style>tag. - No JavaScript: scripts and
onclick-style attributes never run. - Images, fonts and stylesheets load only from public
https://addresses ordata:URIs.http://and relative paths don't load. - For a picture per row, put a column of image links in the src:
<img src="{{Photo URL}}">. A logo can be an https link or a small embeddeddata:image. - Up to 500 KB in all, embedded images included.
Examples
JavaScript (Node 18 or later):
const KEY = process.env.THRIFA_PDF_KEY;
const api = (path, init = {}) => fetch("https://pdf-api.thrifa.io" + path, {
...init,
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
});
// 1. Start: your rows, with a template you saved in the app.
const start = await api("/batches", {
method: "POST",
body: JSON.stringify({
templateId: "YOUR-TEMPLATE-ID",
rows: [
{ "Invoice Number": "INV-1", Client: "Harbor & Co", Item: "Logo", Amount: "$1,200.00" },
{ "Invoice Number": "INV-1", Client: "Harbor & Co", Item: "Guide", Amount: "$850.50" },
],
groupBy: "Invoice Number",
}),
});
const { batch } = await start.json();
// 2. Wait until it's done.
let status;
do {
await new Promise((r) => setTimeout(r, 2000));
({ batch: status } = await (await api(`/batches/${batch.id}`)).json());
} while (status.status === "queued" || status.status === "running");
// 3. Download (a ZIP of PDFs here). The link works for 7 days.
if (status.status === "done") {
const file = await fetch(status.downloadUrl);
// save await file.arrayBuffer() wherever you need it
}Python:
import os, time, requests
KEY = os.environ["THRIFA_PDF_KEY"]
H = {"Authorization": f"Bearer {KEY}"}
batch = requests.post("https://pdf-api.thrifa.io/batches", headers=H, json={
"templateId": "YOUR-TEMPLATE-ID",
"csv": open("invoices.csv").read(),
"groupBy": "Invoice Number",
"output": "pdf", # everything in one PDF
}).json()["batch"]
while True:
status = requests.get(f"https://pdf-api.thrifa.io/batches/{batch['id']}", headers=H).json()["batch"]
if status["status"] not in ("queued", "running"):
break
time.sleep(2)
if status["status"] == "done":
with open("invoices.pdf", "wb") as f:
f.write(requests.get(status["downloadUrl"]).content)Limits and errors
Errors come back as JSON with a sentence you can show, and a code:
401 invalid_key | The key is wrong or was revoked. |
402 no_api_plan | The account isn't on the API plan (for example, a payment failed and it ended). |
402 quota | Not enough PDFs left this month. The count resets on the 1st (UTC). |
402 batch_size | More than 5,000 PDFs in one request. Split it. |
404 template_not_found | No template with that id in this account. |
400 csv | The CSV couldn't be read; the message says why. |
| 429 | Too much at once (20 batches waiting, or 20 single PDFs in flight). Wait for the Retry-After seconds. |
PDFs that fail aren't counted. Rows you send are deleted when the batch finishes; downloads after 7 days.
Help
Email support@thrifa.io.