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

FieldWhat it is
templateIdA template saved in your account. Or send templateHtml instead.
templateHtmlThe template as HTML (up to 500 KB), with {{Column}} placeholders.
rowsThe rows: [{"Name": "Ada"}, …]. Or send csv instead.
csvThe rows as CSV text, column names first (comma, semicolon or tab).
groupByOptional. A column: rows with the same value make one PDF (an invoice with its lines). Without it, one PDF per row.
fieldsOptional. 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.
outputzip (default): separate PDFs in a ZIP. pdf: one PDF. sheet: small designs, several per Letter page.
filenamePatternOptional. Names inside the ZIP, like {{Invoice Number}} {{Client}}.
nameOptional. The download's name.

Other requests

GET /batches/:idStatus, progress, errors and the download link.
POST /batches/:id/cancelStops a batch. Nothing of it is counted.
POST /renderOne PDF right away: send html, get the PDF file back.
GET /meYour 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.pdf

Template syntax

What a template can use:

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_keyThe key is wrong or was revoked.
402 no_api_planThe account isn't on the API plan (for example, a payment failed and it ended).
402 quotaNot enough PDFs left this month. The count resets on the 1st (UTC).
402 batch_sizeMore than 5,000 PDFs in one request. Split it.
404 template_not_foundNo template with that id in this account.
400 csvThe CSV couldn't be read; the message says why.
429Too 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.