Node.js & TypeScript SDK

@doclinth/sdk is the official client for the doclinth PDF generation API. It is written in TypeScript, ships zero dependencies, is fully typed end-to-end, and builds in automatic retries plus idempotency so a retried request can never double-print or double-bill.

Install

npm install @doclinth/sdk

Requires Node 18+ (uses the global fetch). On older runtimes, pass your own fetch via options.fetch.

Generate a PDF

import { Doclinth } from "@doclinth/sdk";

const doclinth = new Doclinth({
  apiKey: process.env.DOCLINTH_API_KEY!,
  baseUrl: "https://doclinth.com",
});

// Binary (default) — returns the PDF bytes.
const pdf = await doclinth.generate({
  templateId: "b1c2d3e4-…",
  data: { invoice_number: "INV-1042", total: 2592 },
});
await fs.writeFile("invoice.pdf", pdf);

// Signed URL — returns { url, expiresAt }.
const { url, expiresAt } = await doclinth.generate({
  templateId: "b1c2d3e4-…",
  data: { total: 2592 },
  output: "url",
});

Retries & idempotency

By default the client retries 429 and 5xx responses (and network errors) up to twice with exponential backoff, honoring Retry-After. To make those retries safe, it attaches an Idempotency-Key automatically. Provide your own key to dedupe across process restarts:

await doclinth.generate({ templateId: "b1c2d3e4-…", data, idempotencyKey: orderId });

Set maxRetries: 0 to disable retries (and the automatic key).

Errors

Non-2xx responses throw a DoclinthError with a stable code and status:

import { Doclinth, DoclinthError } from "@doclinth/sdk";

try {
  await doclinth.generate({ templateId, data });
} catch (e) {
  if (e instanceof DoclinthError && e.code === "quota_exceeded") {
    // prompt an upgrade
  }
}

See the error reference for all codes.

Not using Node?

The API is plain HTTP with a bearer key and returns either PDF bytes or a signed URL. Generate straight from curl, Python, Go, PHP, or your AI agent over MCP — see the quickstart and the OpenAPI 3.1 spec.