Cloud API

One endpoint: send HTML, CSS and options as JSON, receive the PDF or the image. No SDK to install, nothing to host.

API keys

Create and revoke keys in your dashboard. A key is shown once, when you create it. There are two kinds:

Test keyLive key
Prefixpal_test_…pal_live_…
NeedsAn accountAn active API subscription
CostFree, never billed€0.005 per successful render, on top of €5 a month
Quota50 requests per UTC day and 10 per minute, failed renders includedNone
CountOne per accountAs many as you need, for instance one per service

Both kinds render with the same engine and return the same output. A document is one successful render: a PDF of any length, a PNG, a WebP or an SVG each count once. Failed renders are free.

Keep keys on your servers. A key embedded in a web page or a mobile app can be copied and used at your expense; to render on your users' devices, use the WebAssembly build. Revoke a key that leaked: it stops working at once. Every request made with your keys appears in the dashboard with its status, format, page count and generation time.

Request

POST https://api.palatine.page/v1/render
Authorization: Bearer pal_live_…
Content-Type: application/json

The body is a JSON object:

FieldTypeDescription
htmlstringRequired. The document.
cssstring | string[]Extra stylesheets, applied after the document's own.
format"pdf" | "png" | "webp" | "svg"Default pdf.
width, heightinteger (CSS px)Layout size. Default width 800; the height follows the content unless you paginate. See size and format.
baseURLstringResolves the relative URLs of images, fonts, stylesheets and links.
optionsobjectThe rendering options.
request body
{
  "html": "<h1>Quarterly report</h1><p>Revenue grew by 12%.</p>",
  "css": "h1 { color: #2447b3 }",
  "format": "pdf",
  "width": 794,
  "height": 1123,
  "options": { "pagination": true, "pdfTitle": "Quarterly report" }
}

The same call from TypeScript, Python and cURL:

render.ts
const key = process.env.PALATINE_API_KEY;
const url = "https://api.palatine.page/v1/render";
const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: "Bearer " + key,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    html: "<h1>Hi!</h1>", format: "pdf",
  }),
});
if (!response.ok) throw Error(response.statusText);
const pdf = await response.arrayBuffer();

Response

A successful render answers 200. The body is the file, with its content type. The headers describe the render:

HeaderValue
content-typeapplication/pdf, image/png, image/webp or image/svg+xml
x-palatine-render-idIdentifier of this render. Quote it when you contact support.
x-palatine-modelive or test, from the key.
x-palatine-formatThe output format.
x-palatine-pagesPage count of a PDF, 1 for an image. Informational.
x-palatine-documentsBilled documents: 1 with a live key, 0 with a test key.
x-palatine-duration-msTime to native render metadata in milliseconds, including invocation and resource loading; final document transfer follows as a binary stream.
x-palatine-engine-duration-msTime spent in the native engine process, including fonts and resources.
x-palatine-lambda-duration-msNative invocation time, including document transfer inside AWS.
server-timingAuthentication, upload, invocation, download, engine and persistence timings.
x-palatine-warningsURL-encoded JSON list of warnings, at most 20. %5B%5D (an empty list) when there are none.
const header = response.headers.get("x-palatine-warnings");
const warnings = header ? JSON.parse(decodeURIComponent(header)) : [];
// [{ code: "pagination.monolithic-overflow", message: "…", source: "img#chart" }]

Fonts and resources

Noto Sans and Noto Naskh Arabic are built in and serve as fallback fonts: text in a family the API does not know is set in Noto Sans. To use your own fonts, declare them with @font-face and an http(s) URL:

@font-face {
  font-family: Body;
  src: url("https://example.com/fonts/Body.woff2");
}
@font-face {
  font-family: Body;
  font-weight: bold;
  src: url("https://example.com/fonts/Body-Bold.woff2");
}
body { font-family: Body, sans-serif; }

Images (<img>, CSS backgrounds) and stylesheets (<link>, @import) are loaded the same way, from http(s) URLs or data: URLs. Relative URLs need baseURL. A resource that cannot be loaded fails the render with 422, unless options.missingResources is "ignore".

  • Resources must be reachable from the internet; private network addresses are refused.
  • Each fetch has a 15-second timeout.
  • Resources are limited to 20 MiB each and combined, with at most 128 loads per document.
  • To send an image without hosting it, embed it as a data: URL. It counts toward the request size.

Arabic PDF text extraction varies between readers. The documented fixtures pass MuPDF; differences remain with PDF.js, Poppler and PDFium. Test your target reader before relying on search or copy, and consult the reader compatibility results.

Limits and timeouts

LimitValue
Request body6 MiB (413 beyond)
Output16 MiB (422 with code: "output.limit" beyond)
Render time5 minutes
Engine allocation budget512 MiB (422 with code: "memory.limit" when a document cannot fit)
Resources20 MiB each and combined, 128 loads, 15 seconds per fetch

The API uses the native engine in Stockholm, with a new rendering process for each request. Long paginated documents can be rendered in slices; a document that cannot fit returns 422. The allocation budget is separate from the execution environment’s total memory of 1 GiB, which also holds parsing, transport and runtime buffers.

Keep the client connected and set its timeout slightly above 5 minutes, as the Python example does. For larger inputs or outputs, or for no time limit at all, run the WebAssembly or native build under a license.

Errors

Errors are JSON, with a message for humans. Rendering limits, accessibility errors and PDF/X refusals also carry a stable code for programs.

{ "error": "Missing resource: https://example.com/logo.png", "code": "…" }
StatusMeaningWhat to do
400The body is not JSON, html is missing or format is unknown.Fix the request.
401Missing, invalid or revoked API key.Check the Authorization: Bearer header.
402A live key without an active subscription.Subscribe, settle the invoice, or use a test key.
413Body larger than 6 MiB.Host large images and fonts and reference them by URL.
422The document could not be rendered: invalid option, missing resource, memory.limit, output.limit, accessibility.* or pdfx.*.Read the message; the request will fail again unchanged.
429Test key quota reached.Retry after Retry-After seconds.
502The native backend or document transfer failed.Retry with backoff.
504The render exceeded its deadline.Reduce the document or use a local build.
503The rendering service is temporarily unavailable, or the result could not be recorded.Retry after Retry-After seconds.

Only successful renders are billed: no error above creates a charge.

Retries

429 and 503 are temporary and name the delay in Retry-After. A 503 can happen when the rendering service cannot admit a request: retry it after the delay. Other errors are permanent for the same request.

render.ts
async function render(body: object): Promise<Uint8Array> {
  for (let attempt = 1; ; attempt++) {
    const response = await fetch("https://api.palatine.page/v1/render", {
      method: "POST",
      headers: {
        Authorization: "Bearer " + process.env.PALATINE_API_KEY,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(body),
    });
    if (response.ok) return new Uint8Array(await response.arrayBuffer());

    const seconds = Number(response.headers.get("retry-after") ?? 1);
    const retryable = response.status === 429 || response.status === 503;
    // A test key over its daily quota asks to wait until midnight UTC: give up.
    if (!retryable || attempt === 5 || seconds > 60) {
      const { error, code } = await response.json();
      throw new Error([response.status, code, error].filter(Boolean).join(" "));
    }
    await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
  }
}