thirdsai

payload plugin thirds render

by thirdsai
Other
v3
^3.37.0
MIT

Overview

Summary generated from the README

Adds a render endpoint to configured collections that sends a document to the API and stores the resulting PDF, PNG, JPEG or WebP file in an upload collection. A read-only sidebar group links to the latest file. It requires a account and API key, and Payload 3.37 or newer.

Features

  • Adds a POST thirds-render endpoint to each configured collection
  • Outputs PDF, PNG, JPEG or WebP with configurable page and image options
  • Default HTML layout, custom HTML function or saved template
  • Stores files in an added thirds-renders collection or an existing upload collection
  • Idempotency key from document content reuses earlier renders without new API calls
  • Read-only sidebar group shows latest file, job id, format and render time

Use cases

  • Generate PDF invoices from documents in a collection
  • Create share images such as social preview cards from content
  • Produce downloadable PDF versions of pages or posts on demand

From the author

Payload CMS plugin that renders a document to PDF or image with the thirds.ai API and stores the file in an upload collection.

Installation

npm i payload-plugin-thirds-render

0

Stars

0

Forks

0

Open Issues

1 months ago

Last Updated

0

Weekly Downloads

v

npm Version

Dependencies

GitHub stars

00 since Oct 25

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

30/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1439784509-root.svg)](https://payloaddirectory.dev/plugins/1439784509-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1439784509-root"><img src="https://payloaddirectory.dev/badge/1439784509-root.svg" alt="Payload Directory"></a>
Updated Oct 30, 2026Created Oct 30, 2026

README

(Disclosure: I'm connected to thirds.ai.) Drafted with AI help.

payload-plugin-thirds-render

A Payload CMS plugin that renders a document to a PDF or an image with the thirds.ai API and stores the file in an upload collection.

The plugin requires a thirds.ai account and API key.

What it does

  • Adds POST /api/<collection>/:id/thirds-render to each configured collection.
  • Renders the document as PDF or PNG (live-tested), or as JPEG or WebP (not yet live-tested). The HTML comes from a plain default layout (live-tested), from a function in the config (not yet live-tested), or from a saved thirds.ai template (not yet live-tested).
  • Stores the file in an upload collection: the thirds-renders collection that the plugin adds (live-tested), or an existing upload collection (tested against a local stand-in, not the live API).
  • Adds a read only thirdsRender group to the document sidebar. It links to the latest file and shows the thirds.ai job id, the format and the render time. Checked through the REST API; the admin panel view is not yet live-tested.
  • Sends an Idempotency-Key built from the document content, so rendering an unchanged document again reuses the earlier job.

Version 1 has no publish hook and no background jobs. A render runs only when the endpoint is called.

Requirements

  • Payload ^3.37.0. Tested against the live API on 3.92.1. Tested on 3.37.0 against a local stand-in, not the live API.
  • The Node version that the installed Payload release requires.
  • A thirds.ai API key in THIRDS_API_KEY, or passed as apiKey.

Install

The package is not on npm yet. Install it from GitHub:

npm install github:thirdsai/payload-plugin-thirds-render#v0.1.0

The built files in dist/ are part of the repository, so no build step runs on install.

Setup

// payload.config.ts
import { buildConfig } from 'payload'
import { thirdsRenderPlugin } from 'payload-plugin-thirds-render'

export default buildConfig({
  // ...
  plugins: [
    thirdsRenderPlugin({
      collections: {
        invoices: {
          filename: ({ doc }) => `invoice-${doc.number}`,
          pdf: { format: 'A4', margins: { bottom: '16mm', left: '16mm', right: '16mm', top: '16mm' } },
          image: { width: 1200, height: 630 },
        },
        posts: true,
      },
    }),
  ],
})
THIRDS_API_KEY=...   # read when a render runs, never logged

The plugin adds a thirdsRender field group to each listed collection and, unless uploadsCollection is set, a thirds-renders upload collection. Run your usual migration step after adding it.

Render a document

curl -X POST "http://localhost:3000/api/invoices/42/thirds-render?format=pdf" \
  -H "Authorization: JWT <token>"

Query parameters:

ParameterValuesDefault
formatpdf, png (live-tested), jpeg, webp (not yet live-tested)defaultFormat, else pdf
forcetrue skips the stored file check and calls thirds.aioff
drafttrue renders the latest draft (not yet live-tested)off
localeany configured locale (localized collections not yet live-tested)the request locale

Response:

{
  "id": 7,
  "url": "/api/thirds-renders/file/invoice-42.pdf",
  "filename": "invoice-42.pdf",
  "mimeType": "application/pdf",
  "filesize": 16811,
  "format": "pdf",
  "jobId": "pdf_0123456789abcdef0123456789abcdef",
  "credit": "settled",
  "idempotencyKey": "payload-...",
  "sha256": "...",
  "replayed": false,
  "reused": false
}

id and url belong to the upload document. The same file is linked from the sidebar of the source document.

Reuse and idempotency

The Idempotency-Key is a hash of the collection, the document id, the locale, the draft flag, the format and the exact request body. The default HTML leaves out id, createdAt, updatedAt, _status and thirdsRender, so saving the document without changing its content keeps the same key.

  • Unchanged document, file still stored: the endpoint returns the stored file with reused: true and makes no API call.
  • force=true, unchanged document: the endpoint calls thirds.ai with the same key. thirds.ai returns the earlier job (replayed: true) without rendering again, within its 24 hour replay window. A new upload document is stored with the same bytes.
  • Changed document: the key changes and thirds.ai renders a new job.

A custom html or template.data function that adds timestamps or other values that change on every save gives a new key every time.

Options

OptionTypeNotes
collectionsRecord<slug, true | CollectionRenderConfig>Required. Collections that get the endpoint and the sidebar field.
uploadsCollectionstringSlug of an existing upload collection (tested against a local stand-in, not the live API). When omitted the plugin adds thirds-renders.
uploadData({ doc, req, format, collection }) => objectExtra data for the upload document, such as a required alt field (tested against a local stand-in, not the live API).
rendersCollection(collection) => collectionChanges the added thirds-renders collection, for example its upload.staticDir or access.
access({ doc, id, req }) => booleanWho may render. See Access. Not yet live-tested.
apiKeystringDefault process.env.THIRDS_API_KEY.
baseUrlstringDefault process.env.THIRDS_API_BASE, else https://thirds.ai.
timeoutMsnumberWhole request including polling. Default 60000. The timeout path is not yet live-tested.
disabledbooleanRemoves the endpoint. The fields and the collection stay so the schema does not change.

CollectionRenderConfig:

OptionNotes
defaultFormatpdf, png, jpeg or webp.
formatsFormats this collection accepts. Default all four.
html({ doc, req, format, collection }) => string. Replaces the default layout. Not yet live-tested.
template{ id, version?, data? }. Renders a saved thirds.ai template with data({ doc, ... }). Not yet live-tested (the request shape is checked against the public API schema only).
pdfthirds.ai PDF options: format, width, height, margins, landscape, print_background, scale, display_header_footer, header_template, footer_template, title, author, subject. Live-tested: format, margins, print_background, title; the others are not yet live-tested.
imagethirds.ai image options: width (320 to 7680), height (200 to 4320), quality, transparent. The format comes from the request. Live-tested at 1200x630; other sizes, quality and transparent are not yet live-tested.
filename({ doc, ... }) => string. Default <collection>-<id>.

The default layout prints the useAsTitle field as a heading, then each visible field with its label. Values are HTML escaped. Fields with hidden or admin.hidden are left out. Lexical rich text is converted with @payloadcms/richtext-lexical/html when that package is installed, and printed as plain paragraphs otherwise (the plain paragraph fallback is not yet live-tested).

Access

By default a user may render a document when logged in and allowed to update it under the collection's own update access, including access functions that return a query. The document is read with overrideAccess: false, so read access and field access apply to what is rendered. Set access to replace the update check (not yet live-tested).

The thirdsRender group cannot be written through the API. Only the plugin sets it.

Errors

StatusMeaning
400Unknown format, or thirds.ai refused the request body.
401Not logged in.
403Not allowed to read or render the document.
404Document not found.
409The same idempotency key was sent with a different request. Tested against a local stand-in, not the live API.
422The render failed at thirds.ai. The body has the error code. Not yet live-tested.
429Rate limited by thirds.ai. Not yet live-tested.
500THIRDS_API_KEY is not set. Tested against a local stand-in, not the live API.
502thirds.ai rejected the key or was unavailable, or the file could not be stored. Not yet live-tested.
504The render did not finish within timeoutMs. Not yet live-tested.

Notes

  • The API key is sent only to the thirds.ai API. The signed download link from thirds.ai is fetched without it and is not stored.
  • For a collection with drafts, a render of a draft saves the sidebar link on the draft. Not yet live-tested.
  • force=true stores a new upload document each time. Older upload documents are left in place.
  • Payload 4 is not in the peer range yet. The test suite passed against 4.0.0-beta.5 with the peer check skipped, tested against a local stand-in, not the live API.

What was tested

Tested against the live thirds.ai API on Payload 3.92.1 with sqlite, over the REST API:

  • PDF and PNG renders with the default layout, stored in the added thirds-renders collection, with the sidebar link and the upload metadata.
  • Reuse of an unchanged document with no API call, and force=true replaying the same job.
  • The 400, 401, 403 and 404 responses before any API call.

Tested against a local stand-in, not the live API: storage in an existing upload collection with uploadData, a changed document giving a new job, the thirdsRender group not being writable over REST, the 500 for a missing key, and the 409 for a reused key. The same suite passed on Payload 3.37.0 and 4.0.0-beta.5.

Not yet live-tested: JPEG and WebP, saved templates (the request shape is only checked against the public API schema), a custom html function, the access option, drafts, localized collections, a render that fails at thirds.ai (422), the 429, 502 and 504 responses, and the plain paragraph fallback for rich text without @payloadcms/richtext-lexical. The sidebar group was checked through the REST API, not by eye in the admin panel.

Tests

npm test runs the unit tests in test/ against a local stand-in of the thirds.ai API (test/mock-thirds.mjs). No API key is needed and nothing is rendered.

License

MIT

Similar plugins