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 key | Live key | |
|---|---|---|
| Prefix | pal_test_… | pal_live_… |
| Needs | An account | An active API subscription |
| Cost | Free, never billed | €0.005 per successful render, on top of €5 a month |
| Quota | 50 requests per UTC day and 10 per minute, failed renders included | None |
| Count | One per account | As 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:
| Field | Type | Description |
|---|---|---|
html | string | Required. The document. |
css | string | string[] | Extra stylesheets, applied after the document's own. |
format | "pdf" | "png" | "webp" | "svg" | Default pdf. |
width, height | integer (CSS px) | Layout size. Default width 800; the height follows the content unless you paginate. See size and format. |
baseURL | string | Resolves the relative URLs of images, fonts, stylesheets and links. |
options | object | The rendering options. |
{
"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:
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:
| Header | Value |
|---|---|
content-type | application/pdf, image/png, image/webp or image/svg+xml |
x-palatine-render-id | Identifier of this render. Quote it when you contact support. |
x-palatine-mode | live or test, from the key. |
x-palatine-format | The output format. |
x-palatine-pages | Page count of a PDF, 1 for an image. Informational. |
x-palatine-documents | Billed documents: 1 with a live key, 0 with a test key. |
x-palatine-duration-ms | Time to native render metadata in milliseconds, including invocation and resource loading; final document transfer follows as a binary stream. |
x-palatine-engine-duration-ms | Time spent in the native engine process, including fonts and resources. |
x-palatine-lambda-duration-ms | Native invocation time, including document transfer inside AWS. |
server-timing | Authentication, upload, invocation, download, engine and persistence timings. |
x-palatine-warnings | URL-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
| Limit | Value |
|---|---|
| Request body | 6 MiB (413 beyond) |
| Output | 16 MiB (422 with code: "output.limit" beyond) |
| Render time | 5 minutes |
| Engine allocation budget | 512 MiB (422 with code: "memory.limit" when a document cannot fit) |
| Resources | 20 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": "…" } | Status | Meaning | What to do |
|---|---|---|
| 400 | The body is not JSON, html is missing or format is unknown. | Fix the request. |
| 401 | Missing, invalid or revoked API key. | Check the Authorization: Bearer header. |
| 402 | A live key without an active subscription. | Subscribe, settle the invoice, or use a test key. |
| 413 | Body larger than 6 MiB. | Host large images and fonts and reference them by URL. |
| 422 | The 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. |
| 429 | Test key quota reached. | Retry after Retry-After seconds. |
| 502 | The native backend or document transfer failed. | Retry with backoff. |
| 504 | The render exceeded its deadline. | Reduce the document or use a local build. |
| 503 | The 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.
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));
}
}