API Reference
Render templates, manage assets, and integrate PDF generation into any stack.
api.pdfs.build Overview
The pdfs.build API lets you render templates to PDFs, manage your template library, and retrieve generation logs — all over HTTPS with JSON request bodies and standard HTTP status codes.
https://api.pdfs.build application/pdf Authentication
All API requests require a bearer token. Create and manage API keys from Settings → API Keys in your dashboard. Keys are shown once on creation — store them securely.
The primary public REST API is versioned under /v2/organizations/:organizationId/* and accepts API keys only. API keys are organization-scoped, and the organization in the URL must match the key. The legacy /v1/* API remains supported.
Key format
Keys are prefixed with prs_ and scoped to your organization.
curl https://api.pdfs.build/v2/organizations/org_abc/templates \
-H "Authorization: Bearer prs_your_api_key" /v2/organizations/:organizationId/templates Create template
Creates a draft template owned by the user that minted the API key. Drafts are not visible to the render endpoint until they are published. Template source is normalized through the same publishing pipeline used by the app and should define a top-level #let render(...) = { ... } function whose named parameters match the schema fields.
Request body
| Field | Type | Description |
|---|---|---|
| externalId | string | Your organization-scoped template ID. Required and unique. |
| name | string | Display name. Required. |
| description | string | Optional one-line summary. |
| typstCode | string | Template source. Must define #let render(...). Required. |
| schema | object | JSON Schema describing the data payload accepted by the render endpoint. |
| sampleData | object | Example data that satisfies the schema. |
| pageSettings | object | Page size, margins, and other layout settings. |
Returns 201 with both the immutable generated internalId and your externalId. V2 URLs use the external ID; v1 continues to use the internal ID.
External IDs are case-sensitive, 1–128 characters, and may contain ASCII letters, digits, ., _, ~, and -. The values . and .. are reserved. IDs remain reserved after a template is deleted.
/v2/organizations/:organizationId/templates/:externalId/publish Publish template
Promotes a draft template to published so it becomes visible to your organization and callable via the render endpoint. The caller must own the template or be an organization admin/owner. Enforces your plan's published-template limit.
Request body (optional)
| Field | Type | Description |
|---|---|---|
| name | string | Rename the template on publish. |
| description | string | Update the description on publish. |
Returns the updated template detail. Returns 402 template_limit_reached if the org's plan does not allow another published template.
/v2/organizations/:organizationId/templates/:externalId/unpublish Unpublish template
Moves a published template back to draft. Once unpublished, the template can no longer be rendered by the public API and is removed from organization template listings. Existing generation log entries are preserved.
Returns the updated template detail.
/v2/organizations/:organizationId/templates/:externalId/render Render PDF
Compiles the specified template with the provided data payload and returns a binary PDF. Data is validated against the template's schema before rendering.
Request body
| Field | Type | Description |
|---|---|---|
| data | object | Key-value pairs matching the template's schema. |
Response
Returns Content-Type: application/pdf on success. On error, returns JSON with an error object.
const response = await fetch(
'https://api.pdfs.build/v2/organizations/org_abc/templates/invoice-primary/render',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: {
company: 'Acme Corp',
items: [
{ name: 'Consulting', qty: 3, price: 150 },
],
due_date: '2025-06-01',
}
}),
}
);
const pdf = await response.arrayBuffer(); /v2/organizations/:organizationId/templates List templates
Returns published templates in the API key's organization. Drafts created by the key owner remain available through the single-template endpoint.
[
{
"internalId": "550e8400-e29b-41d4-a716-446655440000",
"externalId": "invoice-primary",
"name": "Invoice v3",
"description": "Standard invoice with line items",
"status": "published",
"createdAt": "2025-03-12T10:24:00Z",
"updatedAt": "2025-04-01T08:15:00Z"
}
] /v2/organizations/:organizationId/templates/:externalId Get template
Returns a single template's metadata, schema definition, and sample data. Use the schema field to know which keys your data payload must include when rendering.
{
"internalId": "550e8400-e29b-41d4-a716-446655440000",
"externalId": "invoice-primary",
"name": "Invoice v3",
"status": "published",
"schema": {
"type": "object",
"properties": {
"company": { "type": "string" },
"due_date": { "type": "string", "format": "date" },
"items": { "type": "array" }
}
},
"sampleData": { /* ... */ }
} /v2/organizations/:organizationId/templates/:externalId Rename external ID
Send {"externalId":"invoice-primary"}. The old v2 URL stops resolving immediately; the internal ID, v1 URL, and historical generation-log foreign keys do not change. Requires template ownership or organization admin access.
/v2/organizations/:organizationId/logs Generation logs
Returns a paginated list of PDF generation events for your organization. Each log exposes templateInternalId and the templateExternalId captured when that generation occurred, so later renames do not rewrite audit history. Use GET /v2/organizations/:organizationId/logs/:logId for detail or GET /v2/organizations/:organizationId/templates/:externalId/logs for one template.
Query parameters
| Parameter | Type | Description |
|---|---|---|
| limit | integer | Max results to return (default: 50) |
| offset | integer | Pagination offset |
| status | string | Filter by status: success or error |
| source | string | Filter by source: api, ui, or mcp |
| externalId | string | Filter by the external ID captured at generation time. Historical IDs continue to work after a rename. |
| search | string | Full-text search on template name |
| from | string (ISO 8601) | Start of time range |
| to | string (ISO 8601) | End of time range |
Migrate from v1
V1 remains supported and continues to identify templates by the generated internal ID. V2 adds an organization-scoped external ID that you control. Existing templates initially use their internal ID as the external ID; rename it in the dashboard or with PATCH /v2/organizations/:organizationId/templates/:externalId.
| V1 | V2 |
|---|---|
| POST /v1/render | POST /v2/organizations/:organizationId/templates/:externalId/render |
Send templateId and data | Move the template identifier into the URL and send only data |
| Generated internal ID | Client-managed external ID, unique within the organization |
MCP server (for AI agents)
The same authentication layer also serves a Model Context Protocol endpoint. Agents that connect to it can design, publish, and render PDFs inside a single conversation — without API keys or dashboard handoffs.
https://backend.pdfs.build/mcp Tool surface
The MCP server exposes the entire template lifecycle plus authenticated rendering. MCP renders count toward the same monthly PDF render quota as UI, authenticated form, automation, and REST API renders.
| Tool | Purpose |
|---|---|
| list_templates / get_template / browse_templates | Discover templates and load their code, schema, and sample data. |
| create_template / duplicate_template | Start a fresh draft or clone an existing template. |
| write_document / edit_document / write_schema / write_sample_data | Author the template code, schema, and data. |
| compile_document | Compile the active template against default edge fixtures and optional custom fixtures, returning per-fixture diagnostics. |
| render_template | Render a saved template without an API key. Pass public_share=true to create share/download URLs, and expires_in_days to customize the expiry. |
| save_template | Persist the active session's changes after the compile gate passes; draft WIP saves can explicitly skip the gate. |
| publish_template / unpublish_template | Move templates between draft and published. Publishing requires the compile gate to pass. |
| create_api_key / list_api_keys / delete_api_key | Mint, audit, and revoke REST API keys for external integrations. |
| document_reference | Look up template code reference inline. |
| list_fonts / upload_font / confirm_font_upload | Browse org fonts and upload custom TTF/OTF files. |
| search_google_fonts / install_google_font | Browse Google Fonts and install a family into the org. |
Connect from Claude Desktop, Cursor, or any MCP-compatible client. See the MCP integration guide for an end-to-end example.
Errors
All errors return a JSON body with a top-level error object.
{
"error": {
"code": "schema_validation_failed",
"message": "Missing required field: company"
}
} | Status | Code | Description |
|---|---|---|
| 400 | invalid_request | Missing or malformed request parameters |
| 400 | invalid_external_id | External ID is not URL-safe or exceeds 128 characters |
| 400 | already_published | Trying to publish a template that is already published |
| 400 | already_draft | Trying to unpublish a template that is already a draft |
| 401 | unauthorized | Missing or invalid API key |
| 403 | forbidden | Caller does not have permission to publish/unpublish this template |
| 403 | organization_scope_mismatch | Organization URL does not match the API key organization |
| 409 | external_id_conflict | External ID is already reserved in the organization |
| 404 | not_found | Template not found or not accessible |
| 402 | template_limit_reached | Org plan's published-template limit is reached. Unpublish a template or upgrade the plan. |
| 402 | api_renders_not_allowed_on_free | The REST render API is not available on the Free plan. Use the app, authenticated forms, MCP rendering, or upgrade to Starter or higher. |
| 422 | schema_validation_failed | Data payload doesn't match the template schema |
| 429 | rate_limited | Request rate exceeded — see Rate Limits |
| 500 | render_failed | Internal rendering error |
Rate limits
Rate limits apply per API key, per minute. When a limit is exceeded, the API returns a 429 status. Check the response headers to determine when you can retry.
| Plan | Requests / min |
|---|---|
| Free | 10 |
| Pro | 300 |
| Enterprise | Custom |
Rate limit headers
| Header | Description |
|---|---|
| X-RateLimit-Limit | Maximum requests allowed per minute |
| X-RateLimit-Remaining | Requests remaining in the current window |
| X-RateLimit-Reset | Unix timestamp when the window resets |
API keys
API keys are scoped to your organization and grant access to all templates your organization can see. Keys are prefixed with prs_ and displayed only once on creation — copy them immediately and store them in a secret manager or environment variable.
Manage your API keys from Settings → API Keys in the dashboard. You can create multiple keys for different environments and revoke them individually.