> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chromiumly.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates (hosted API)

> Generate invoice PDFs from structured data with the hosted Templates API.

`Templates` is a hosted Chromiumly feature. It is not available on self-hosted Gotenberg endpoints.

To use templates, configure `apiKey` (or `CHROMIUMLY_API_KEY`). When only `apiKey` is set, Chromiumly uses `https://api.chromiumly.dev`.

## Supported template types

* `invoice_freelancer`
* `invoice_saas`
* `invoice_classic`
* `invoice_minimal`
* `invoice_modern`

## Basic usage

```typescript theme={null}
import { Chromiumly, Templates } from "chromiumly";

Chromiumly.configure({
  apiKey: process.env.CHROMIUMLY_API_KEY!,
});

const templates = new Templates();
const buffer = await templates.generate({
  type: "invoice_saas",
  data: {
    invoiceNumber: "INV-319",
    createdDate: "2026-03-19",
    dueDate: "2026-04-02",
    sender: {
      name: "Acme Cloud LLC",
      addressLine1: "450 Madison Ave",
      addressLine2: "New York, NY 10022",
    },
    receiver: {
      name: "Northwind Health Inc.",
      addressLine1: "221 Harbor Blvd",
      addressLine2: "San Diego, CA 92101",
    },
    items: [
      {
        description: "Platform Subscription",
        qty: 1,
        unitPrice: "1500.00",
        amount: "1500.00",
      },
    ],
    currency: "USD",
    subTotal: "1500.00",
    taxRate: 8.25,
    taxAmount: "123.75",
    total: "1623.75",
    footerNote: "Payment due in 14 days.",
  },
});
```

## Runtime validation

Pass `{ validate: true }` as the second argument to validate the payload shape before the request:

```typescript theme={null}
const buffer = await templates.generate(request, { validate: true });
```

If `apiKey` is missing, `Templates.generate()` throws.

## Payload shape

```typescript theme={null}
interface InvoiceSaasTemplateData {
  invoiceNumber: string;
  createdDate: string;
  dueDate: string;
  companyLogo?: string;
  sender: TemplateParty;
  receiver: TemplateParty;
  items: InvoiceItem[];
  currency: Currency;
  subTotal: string;
  taxRate: number;
  taxAmount: string;
  total: string;
  footerNote: string;
  footerDisclaimer?: string;
}

// invoice_classic uses this variant instead, where companyLogo is required.
interface InvoiceClassicTemplateData
  extends Omit<InvoiceSaasTemplateData, "companyLogo"> {
  companyLogo: string;
}

interface TemplateParty {
  name: string;
  addressLine1: string;
  addressLine2?: string;
  tax?: string;
  iban?: string;
  bic?: string;
}

interface InvoiceItem {
  description: string;
  qty: number;
  unitPrice: string;
  amount: string;
}
```

`invoice_saas`, `invoice_freelancer`, `invoice_minimal`, and `invoice_modern` all use `InvoiceSaasTemplateData`; `invoice_classic` uses `InvoiceClassicTemplateData`, the only variant where `companyLogo` is required.

The `currency` field accepts any [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code exported as the `Currency` type (e.g. `"USD"`, `"EUR"`, `"GBP"`).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.