{"openapi":"3.1.0","info":{"title":"PDF4.dev API","version":"1.0.0","description":"Generate PDFs from HTML templates with Handlebars variables. Create templates in the dashboard, then render them via API with dynamic data.\n\n## Authentication\n\nAll API requests require a Bearer token. Create an API key in **Settings** and include it in the `Authorization` header:\n\n```\nAuthorization: Bearer p4_live_xxx...\n```\n\n## Quick Start\n\n1. Create a template in the dashboard or via API\n2. Generate an API key in Settings\n3. Call `POST /api/v1/render` with your template ID and data\n\n```bash\ncurl -X POST https://www.pdf4.dev/api/v1/render \\\n  -H \"Authorization: Bearer p4_live_xxx\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"template_id\": \"invoice\", \"data\": {\"company\": \"Acme\"}}' \\\n  --output invoice.pdf\n```"},"servers":[{"url":"https://www.pdf4.dev","description":"Current server"}],"security":[{"bearerAuth":[]}],"paths":{"/api/v1/render":{"post":{"operationId":"renderPdf","summary":"Generate a PDF","description":"Render a PDF from a saved template or raw HTML. Pass `template_id` to use a saved template, or `html` for one-off renders. Variables in `{{handlebars}}` syntax are replaced with values from `data`. Returns the PDF as binary data (`application/pdf`).\n\nErrors: 400 `invalid_json` (the body is not a JSON object), `invalid_data` (`data` is not an object), `invalid_format` (a `format` margin, or custom width or height, that cannot be read), `template_syntax_error` and `template_runtime_error` (the message names the template, header, footer or block that failed); 413 `request_too_large` for a body over 10 MB, refused before it is read; 422 `render_timeout` when the render takes longer than 60 seconds. With `delivery: \"url\"`: 413 `render_too_large` for a PDF over the URL-delivery size (base64 delivery takes it), 507 `render_storage_full` with `Retry-After` when stored renders are at their limit, 500 `storage_failed`. A failed render or URL delivery is logged as a failure, with its template and duration; a bad body is not logged.","tags":["Render"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RenderRequest"},"examples":{"with_template":{"summary":"Render from a saved template","value":{"template_id":"invoice","data":{"company_name":"Acme Corp","invoice_number":"INV-2025-001","total":"$4,500.00"}}},"with_html":{"summary":"Render from raw HTML","value":{"html":"<h1>Hello {{name}}</h1><p>Your order #{{order_id}} is confirmed.</p>","data":{"name":"John","order_id":"12345"}}},"with_format":{"summary":"Custom page format","value":{"html":"<h1>Landscape Report</h1>","format":{"preset":"a4-landscape","margins":{"top":"10mm","bottom":"10mm","left":"15mm","right":"15mm"},"background_color":"#ffffff","font_family":"Inter, sans-serif","font_size":"14px"}}}}}}},"responses":{"200":{"description":"PDF generated successfully. The body depends on `delivery`: a binary PDF when it is omitted, JSON when it is `base64` or `url`.","content":{"application/pdf":{"schema":{"type":"string","format":"binary"}},"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/RenderUrlResponse"},{"$ref":"#/components/schemas/RenderBase64Response"}]}}},"headers":{"Content-Disposition":{"schema":{"type":"string"},"example":"inline; filename=\"document.pdf\""}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"},"413":{"description":"The request body is over 10 MB (`request_too_large`), or, with `delivery: \"url\"`, the PDF is over the URL-delivery size (`render_too_large`): use base64 delivery.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"invalid_request_error","code":"request_too_large","message":"The request body is over the 10 MB (10000000 bytes) limit. Reference large images by URL instead of inlining them."}}}}},"422":{"description":"The render did not finish within 60 seconds (`render_timeout`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"invalid_request_error","code":"render_timeout","message":"The render took longer than 60 seconds"}}}}},"507":{"description":"With `delivery: \"url\"`: stored renders are at their limit (`render_storage_full`). Retry after the `Retry-After` seconds, or use base64 delivery.","headers":{"Retry-After":{"schema":{"type":"integer"},"example":60}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}},"/api/v1/templates":{"get":{"operationId":"listTemplates","summary":"List templates","description":"Returns all templates of the authenticated organization. Requires `full_access` API key scope.","tags":["Templates"],"responses":{"200":{"description":"Array of templates","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Template"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}},"post":{"operationId":"createTemplate","summary":"Create a template","description":"Create a new template. The `name` is required and a URL-safe `slug` is generated from it, unique in the organization. Header and footer components can be set with `header_component_id` / `footer_component_id` or with `<pdf4-header>` / `<pdf4-footer>` tags in `html`: a tag alone sets the matching id. Requires `full_access` API key scope.\n\nErrors: 400 `invalid_json`, `missing_parameter` (no `name`), `invalid_parameter`, `invalid_pdf_format`, `invalid_sample_data`, `component_not_found`, `component_type_mismatch`.","tags":["Templates"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateTemplateRequest"},"example":{"name":"Monthly Invoice","html":"<!DOCTYPE html><html><body><h1>Invoice #{{invoice_number}}</h1><p>Amount: {{total}}</p></body></html>","sample_data":{"invoice_number":"INV-001","total":"$1,000.00"},"pdf_format":{"preset":"a4","margins":{"top":"20mm","bottom":"20mm","left":"15mm","right":"15mm"}}}}}},"responses":{"201":{"description":"Template created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Template"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/templates/{id}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Template ID (`tmpl_xxx`) or slug (e.g. `monthly-invoice`)"}],"get":{"operationId":"getTemplate","summary":"Get a template","description":"Retrieve a single template by ID or slug. Requires `full_access` API key scope.","tags":["Templates"],"responses":{"200":{"description":"Template found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Template"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"operationId":"updateTemplate","summary":"Update a template","description":"Update a template by ID or slug. Only provided fields are updated; a `pdf_format` replaces the stored format as a whole (missing fields take the defaults, nothing is merged). The slug never changes, even on a rename. Requires `full_access` API key scope.\n\nErrors: 400 `invalid_json`, `invalid_parameter`, `invalid_pdf_format`, `invalid_sample_data`, `component_not_found`, `component_type_mismatch`. A refused update changes nothing.","tags":["Templates"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateTemplateRequest"},"example":{"html":"<h1>Updated Invoice #{{number}}</h1>","sample_data":{"number":"INV-002"}}}}},"responses":{"200":{"description":"Template updated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Template"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"operationId":"deleteTemplate","summary":"Delete a template","description":"Permanently delete a template by ID or slug. This action cannot be undone. Requires `full_access` API key scope.","tags":["Templates"],"responses":{"200":{"description":"Template deleted","content":{"application/json":{"schema":{"type":"object","properties":{"deleted":{"type":"boolean"}}},"example":{"deleted":true}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/components":{"get":{"operationId":"listComponents","summary":"List components","description":"Returns all components (headers, footers, blocks). Use header/footer IDs in templates for repeating page elements. Block components are referenced via <pdf4-block> tags in template HTML. An unknown `type` answers 400 `invalid_parameter`. Requires `full_access` API key scope.","tags":["Components"],"parameters":[{"name":"type","in":"query","description":"Filter by component type","schema":{"type":"string","enum":["header","footer","block"]}}],"responses":{"200":{"description":"Array of components","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Component"}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}},"post":{"operationId":"createComponent","summary":"Create a component","description":"Create a header, footer or block component. Use {{variables}} for data. In a header or footer, page numbers are written `<span class=\"pageNumber\"></span>` / `<span class=\"totalPages\"></span>` or `{{pageNumber}}` / `{{totalPages}}`: PDF4.dev stamps them on each page after rendering, and they are not data variables. Errors: 400 `invalid_json`, `missing_parameter`, `invalid_parameter` (an empty name, an unknown type, a non-string html or preview). Requires `full_access` API key scope.","tags":["Components"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateComponentRequest"}}}},"responses":{"201":{"description":"Component created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Component"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/components/{id}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Component ID (comp_xxx)"}],"get":{"operationId":"getComponent","summary":"Get a component","description":"Retrieve a single component. Requires `full_access` API key scope.","tags":["Components"],"responses":{"200":{"description":"Component found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Component"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"operationId":"updateComponent","summary":"Update a component","description":"Update a component's name, type or HTML. Errors: 400 `invalid_json`, `invalid_parameter` (an empty name, an unknown type, a non-string html or preview). Requires `full_access` API key scope.","tags":["Components"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateComponentRequest"}}}},"responses":{"200":{"description":"Component updated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Component"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"operationId":"deleteComponent","summary":"Delete a component","description":"Permanently delete a component. Templates that reference it render without it: their `header_component_id` / `footer_component_id` becomes null and a tag left in their HTML prints nothing. Requires `full_access` API key scope.","tags":["Components"],"responses":{"200":{"description":"Component deleted","content":{"application/json":{"schema":{"type":"object","properties":{"deleted":{"type":"boolean"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/templates/{id}/duplicate":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Template ID (`tmpl_xxx`) or slug of the template to duplicate"}],"post":{"operationId":"duplicateTemplate","summary":"Duplicate a template","description":"Creates a copy of the template with \"(copy)\" appended to its name and a new slug. The copy keeps the stored HTML, format, sample data and components as they are. Requires `full_access` API key scope.","tags":["Templates"],"responses":{"201":{"description":"Template duplicated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Template"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/logs":{"get":{"operationId":"getLogs","summary":"List PDF generation logs","description":"Returns logs of all PDF generations with cursor-based pagination. Filter by status, template, or date range. Requires `full_access` API key scope.\n\nErrors: 400 `invalid_cursor` (the cursor names no log of this organization, such as one deleted since), `invalid_parameter` (an unknown `status`, or a `from` / `to` that is not a date).","tags":["Logs"],"parameters":[{"name":"limit","in":"query","description":"Results per page, 1 to 100 (a larger value is clamped to 100, a fraction rounded down)","schema":{"type":"integer","default":50,"minimum":1,"maximum":100}},{"name":"cursor","in":"query","description":"Cursor for pagination. Use `next_cursor` from a previous response to fetch the next page. A cursor that names no log of this organization is 400 `invalid_cursor`.","schema":{"type":"string"}},{"name":"status","in":"query","description":"Filter by generation status","schema":{"type":"string","enum":["success","error"]}},{"name":"template_id","in":"query","description":"Filter by template ID","schema":{"type":"string"}},{"name":"from","in":"query","description":"Start date (ISO 8601)","schema":{"type":"string","format":"date-time"}},{"name":"to","in":"query","description":"End date (ISO 8601)","schema":{"type":"string","format":"date-time"}}],"responses":{"200":{"description":"Logs with cursor pagination","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CursorPaginatedLogs"}}}},"400":{"description":"The cursor names no log of this organization (`invalid_cursor`), or `status`, `from` or `to` is invalid (`invalid_parameter`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"invalid_request_error","code":"invalid_cursor","message":"Invalid cursor"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/stats":{"get":{"operationId":"getStats","summary":"Get usage statistics","description":"Returns aggregated usage statistics including template count, total renders, success rate, average duration, and total size. Optionally filter by time period (an unknown period answers all time). The average duration covers successful renders only, and the success rate is rounded down, so a single failure never reads as 100%. Session auth only.","tags":["Stats"],"parameters":[{"name":"period","in":"query","description":"Time period filter. Omit for all-time statistics.","schema":{"type":"string","enum":["1h","24h","7d","30d"]}}],"responses":{"200":{"description":"Usage statistics","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Stats"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/api-keys":{"get":{"operationId":"listApiKeys","summary":"List API keys","description":"Returns all API keys of the organization. Only key prefix is shown, not the full token. Session auth, organization admins only (another member gets 401).","tags":["Api keys"],"responses":{"200":{"description":"Array of API keys","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ApiKey"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"operationId":"createApiKey","summary":"Create an API key","description":"Create a new API key. The full token is returned only once in the response: store it securely. Session auth, organization admins only (another member gets 401).\n\nErrors: 400 `invalid_json` (the body is not a JSON object), `missing_parameter` (no `name`), `invalid_parameter` (a `name` that is not a string of 1 to 100 characters, or an unknown `permission`).","tags":["Api keys"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Display name for the key, 1 to 100 characters after trimming","minLength":1,"maxLength":100,"example":"Production"},"permission":{"type":"string","enum":["full_access","render_only"],"description":"Permission scope. Defaults to full_access.","example":"full_access"}}}}}},"responses":{"201":{"description":"API key created. The `key` field contains the full token: this is the only time it is shown.","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/ApiKey"},{"type":"object","properties":{"key":{"type":"string","description":"Full API key token (shown only once)","example":"p4_live_abc123..."}}}]}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/api-keys/{id}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"API key ID"}],"delete":{"operationId":"deleteApiKey","summary":"Delete an API key","description":"Permanently revoke an API key. Any requests using this key will immediately fail. Session auth only.","tags":["Api keys"],"responses":{"200":{"description":"API key deleted","content":{"application/json":{"schema":{"type":"object","properties":{"deleted":{"type":"boolean"}}},"example":{"deleted":true}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/account":{"delete":{"operationId":"deleteAccount","summary":"Delete account","description":"Permanently delete the user account. Teams where the user is the only member are deleted with their data (templates, components, API keys, logs). In a team shared with others, what the user created is handed to the oldest other admin (else the oldest other member) and the team keeps it. This action cannot be undone. Session auth only.\n\nErrors: 409 `last_admin` when the user is the last admin of a team that has other members (nothing is deleted: make another member an admin first); 500 `deletion_failed`.","tags":["Account"],"responses":{"200":{"description":"Account deleted","content":{"application/json":{"schema":{"type":"object","properties":{"deleted":{"type":"boolean"}}},"example":{"deleted":true}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"409":{"description":"The user is the last admin of a team that has other members (`last_admin`). Nothing was deleted.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"invalid_request_error","code":"last_admin","message":"Make another member an admin of Acme before deleting your account."}}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Key","description":"API key from Settings page. Keys start with `p4_live_` prefix."}},"schemas":{"RenderRequest":{"type":"object","description":"Either `template_id` or `html` is required. If both are provided, `template_id` takes precedence. Header and footer components come from the `<pdf4-header>` / `<pdf4-footer>` tags in the HTML: a tag wins, and one whose component does not exist renders nothing. The template's `header_component_id` / `footer_component_id` is used when the HTML has no tag for that slot, and also by a template saved before writes kept the two in sync whose tag names another component: it keeps printing its stored one until it is saved again.","properties":{"template_id":{"type":"string","description":"Template ID (`tmpl_xxx`) or slug. The template must belong to the authenticated user. `null` reads as omitted.","example":"invoice"},"html":{"type":"string","description":"Raw HTML string. Supports Handlebars `{{variables}}` syntax. Use this for one-off renders without saving a template. `null` reads as omitted.","example":"<h1>Hello {{name}}</h1>"},"data":{"type":"object","additionalProperties":true,"description":"Data to replace `{{variables}}` in the template. A JSON object: `null`, `\"\"`, `false` and `0` read as omitted, anything else answers 400 `invalid_data`. Supports strings, numbers, booleans, nested objects, and arrays (for `{{#each}}` blocks).","example":{"name":"World","company":"Acme Corp"}},"format":{"allOf":[{"$ref":"#/components/schemas/PdfFormat"}],"description":"Page format for this render. It replaces the template's format as a whole: missing fields take the defaults (A4 portrait, 20mm top/bottom and 15mm left/right margins), they are not read from the template. It prints as renders always have: an unknown preset prints a4, an unknown alignment or footer position is ignored, and a `margins` object prints a side it leaves out at 0 (the default margins apply only when `margins` is left out). `null`, `\"\"`, `false` and `0` read as omitted. Only a margin (or a custom width or height) that cannot be read answers 400 `invalid_format`."},"delivery":{"type":"string","enum":["base64","url"],"description":"How to return the PDF. Omit for a binary `application/pdf` body (the default). `base64` returns JSON with the bytes inline. `url` stores the render and returns a signed URL valid for 24 hours, which is the recommended path for PDFs over 1 MB and for AI agents that cannot hold binary in context. An organization keeps at most 200 stored renders (500 MiB) by default; past that its oldest are deleted first, so a URL can stop working sooner. After expiry the URL answers 404 `render_expired`.","example":"url"}}},"RenderUrlResponse":{"type":"object","description":"Returned when `delivery` is `url`.","properties":{"url":{"type":"string","description":"Signed URL to `GET /api/v1/renders/{id}`. Needs no API key: the token carries its own expiry.","example":"https://pdf4.dev/api/v1/renders/render_a1b2c3d4e5f6a7b8?token=1758531600000.AbCdEf"},"expires_at":{"type":"string","format":"date-time","description":"When the URL stops resolving.","example":"2026-09-24T09:00:00.000Z"},"size_bytes":{"type":"integer","example":48213},"duration_ms":{"type":"integer","example":287}}},"RenderBase64Response":{"type":"object","description":"Returned when `delivery` is `base64`.","properties":{"pdf_base64":{"type":"string","description":"The PDF bytes, base64 encoded."},"size_bytes":{"type":"integer","example":48213},"duration_ms":{"type":"integer","example":287}}},"Template":{"type":"object","properties":{"id":{"type":"string","description":"Unique template ID","example":"tmpl_a1b2c3d4e5f6"},"name":{"type":"string","description":"Display name","example":"Invoice"},"slug":{"type":"string","description":"URL-safe identifier, unique per organization. Set at creation from the name and never changed, even when the template is renamed. Can be used as `template_id` in render requests and in place of the ID in `/api/v1/templates/{id}`.","example":"invoice"},"html":{"type":"string","description":"HTML template with Handlebars variables"},"plain_text":{"type":"string","description":"Plain text version of the template"},"pdf_format":{"$ref":"#/components/schemas/PdfFormat"},"sample_data":{"type":"object","additionalProperties":true,"description":"Default sample values for preview. These are NOT used during API rendering: you must pass `data` explicitly."},"header_component_id":{"type":"string","nullable":true,"description":"Header component ID (comp_xxx). Repeats on every page when rendering. Kept in agreement with the `<pdf4-header>` tag in `html`, which is what renders."},"footer_component_id":{"type":"string","nullable":true,"description":"Footer component ID (comp_xxx). Repeats on every page when rendering. Kept in agreement with the `<pdf4-footer>` tag in `html`, which is what renders."},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"CreateTemplateRequest":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Template name. A slug is auto-generated from this."},"html":{"type":"string","description":"HTML template content. Supports Handlebars `{{variables}}`."},"plain_text":{"type":"string","description":"Plain text version of the template"},"pdf_format":{"$ref":"#/components/schemas/PdfFormat"},"sample_data":{"type":"object","additionalProperties":true,"description":"Default sample values for preview. Must be a JSON object (an array answers 400 `invalid_sample_data`)."},"header_component_id":{"type":"string","nullable":true,"description":"A header component (comp_xxx) of your organization. The `<pdf4-header>` tag in `html` is what renders: setting an ID rewrites a tag that names another component, `null` (or an empty string) clears it and removes the tag, and when omitted the ID follows a tag in the `html` sent (`html` without one keeps the current ID, which still prints). An unknown ID or one of another organization answers 400 `component_not_found`, a component that is not a header 400 `component_type_mismatch`."},"footer_component_id":{"type":"string","nullable":true,"description":"A footer component (comp_xxx) of your organization. The `<pdf4-footer>` tag in `html` is what renders: setting an ID rewrites a tag that names another component, `null` (or an empty string) clears it and removes the tag, and when omitted the ID follows a tag in the `html` sent (`html` without one keeps the current ID, which still prints). An unknown ID or one of another organization answers 400 `component_not_found`, a component that is not a footer 400 `component_type_mismatch`."}}},"UpdateTemplateRequest":{"type":"object","description":"Only provided fields are updated.","properties":{"name":{"type":"string","description":"New name. The slug does not change."},"html":{"type":"string"},"plain_text":{"type":"string"},"pdf_format":{"allOf":[{"$ref":"#/components/schemas/PdfFormat"}],"description":"Replaces the stored format as a whole: missing fields take the defaults. `null` resets it to the default format."},"sample_data":{"type":"object","nullable":true,"additionalProperties":true,"description":"A JSON object, or `null` to clear it."},"header_component_id":{"type":"string","nullable":true,"description":"A header component (comp_xxx) of your organization. The `<pdf4-header>` tag in `html` is what renders: setting an ID rewrites a tag that names another component, `null` (or an empty string) clears it and removes the tag, and when omitted the ID follows a tag in the `html` sent (`html` without one keeps the current ID, which still prints). An unknown ID or one of another organization answers 400 `component_not_found`, a component that is not a header 400 `component_type_mismatch`."},"footer_component_id":{"type":"string","nullable":true,"description":"A footer component (comp_xxx) of your organization. The `<pdf4-footer>` tag in `html` is what renders: setting an ID rewrites a tag that names another component, `null` (or an empty string) clears it and removes the tag, and when omitted the ID follows a tag in the `html` sent (`html` without one keeps the current ID, which still prints). An unknown ID or one of another organization answers 400 `component_not_found`, a component that is not a footer 400 `component_type_mismatch`."}}},"Component":{"type":"object","properties":{"id":{"type":"string","description":"Unique component ID","example":"comp_a1b2c3d4e5f6"},"name":{"type":"string","description":"Display name","example":"Company header"},"type":{"type":"string","enum":["header","footer","block"],"description":"Component type. Headers repeat at the top of every page, footers at the bottom, blocks render inline where placed."},"html":{"type":"string","description":"HTML with Handlebars variables"},"preview":{"type":"string","description":"Plain text preview (auto-generated from HTML if omitted)"},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"CreateComponentRequest":{"type":"object","required":["name","type"],"properties":{"name":{"type":"string","description":"Component name (e.g. Company header)"},"type":{"type":"string","enum":["header","footer","block"],"description":"Component type. Headers repeat on every page (via <thead>), footers repeat on every page (via <tfoot>), blocks render inline where placed."},"html":{"type":"string","description":"HTML with {{handlebars}} variables"},"preview":{"type":"string","description":"Plain text preview (auto-generated from HTML if omitted)"}}},"UpdateComponentRequest":{"type":"object","description":"Only provided fields are updated.","properties":{"name":{"type":"string"},"type":{"type":"string","enum":["header","footer","block"],"description":"Change component type. Headers repeat on every page (via <thead>), footers repeat on every page (via <tfoot>), blocks render inline. Templates that already use the component keep it in the slot they put it in: changing the type does not move it."},"html":{"type":"string"},"preview":{"type":"string","description":"Plain text preview (auto-generated from HTML if omitted)"}}},"PdfFormat":{"type":"object","description":"Page format configuration. Every field is optional: `preset` defaults to `a4` and each missing margin side to 20mm (top, bottom) or 15mm (left, right). A format replaces the stored or template format as a whole, it is never merged with it. Margins, `width` and `height` take px, pt, pc, mm, cm or in, or a bare number of px; a number is stored as `\"<n>px\"`, an empty margin is 0. `component_gap` is CSS: any length unit (`em`, `rem`, `%` too) or `calc()`. Presets and alignments are case-insensitive. On a template write, an unknown preset, alignment or footer position, or a length that cannot be read, answers 400 `invalid_pdf_format`; a value sent back exactly as stored is kept. On a render, `format` prints as renders always have: an unknown preset prints a4, an unknown alignment or footer position is ignored, a number is accepted for a CSS value, and only a margin (or a custom width or height) that cannot be read answers 400 `invalid_format`. Unknown keys are ignored.","properties":{"preset":{"type":"string","enum":["a4","a4-landscape","letter","letter-landscape","square","custom"],"description":"Page size preset. Use `custom` with `width`/`height` for arbitrary dimensions.","example":"a4"},"width":{"type":"string","description":"Custom width (only used when preset is `custom`). Defaults to 210mm.","example":"210mm"},"height":{"type":"string","description":"Custom height (only used when preset is `custom`). Defaults to 297mm.","example":"297mm"},"margins":{"type":"object","description":"Page margins. Each missing side takes its default (20mm top and bottom, 15mm left and right); an empty side is 0.","properties":{"top":{"type":"string","example":"20mm"},"bottom":{"type":"string","example":"20mm"},"left":{"type":"string","example":"15mm"},"right":{"type":"string","example":"15mm"}}},"background_color":{"type":"string","description":"Page background color (CSS value)","example":"#ffffff"},"font_family":{"type":"string","description":"Default font family injected into the page","example":"Inter, sans-serif"},"font_size":{"type":"string","description":"Default font size injected into the page","example":"14px"},"text_align":{"type":"string","description":"Default text alignment for the page","enum":["left","center","right","justify"],"example":"left"},"horizontal_align":{"type":"string","description":"Horizontal content alignment on the page","enum":["left","center","right"],"example":"left"},"vertical_align":{"type":"string","description":"Vertical content alignment on the page (useful for single-page documents like certificates)","enum":["top","center","bottom"],"example":"top"},"google_fonts_url":{"type":"string","description":"Google Fonts URL or any @import-compatible CSS URL. Loads in <head>, available to template and all components.","example":"https://fonts.googleapis.com/css2?family=Roboto&display=swap"},"color":{"type":"string","description":"Default text color injected into the page","example":"#333333"},"line_height":{"type":"string","description":"Default line-height injected into the page","example":"1.5"},"component_gap":{"type":"string","description":"Gap between header/footer components and page content. Applied as CSS padding between the repeated header/footer and the body content, so any CSS length works (`5mm`, `1em`, `2%`, `calc(...)`); a bare number is px.","example":"5mm"},"footer_position":{"type":"string","enum":["after-content","page-bottom"],"description":"Footer position mode. \"after-content\" (default) places the footer right after the last content row. \"page-bottom\" pins the footer to the bottom of every page, including the last page.","example":"after-content"}}},"ApiError":{"type":"object","description":"Structured error response","properties":{"error":{"type":"object","properties":{"type":{"type":"string","enum":["authentication_error","invalid_request_error","not_found_error","api_error"],"description":"Error category"},"code":{"type":"string","description":"Machine-readable error code","example":"missing_parameter"},"message":{"type":"string","description":"Human-readable error message","example":"Either template_id or html is required"}}}}},"PdfLog":{"type":"object","properties":{"id":{"type":"string"},"template_id":{"type":"string","nullable":true},"template_name":{"type":"string","nullable":true,"description":"Template name at the time of generation (may differ if template was renamed)"},"api_key_id":{"type":"string","nullable":true},"status":{"type":"string","enum":["success","error"]},"duration_ms":{"type":"integer","description":"PDF generation time in milliseconds"},"size_bytes":{"type":"integer","nullable":true,"description":"PDF file size in bytes (null if generation failed)"},"error":{"type":"string","description":"Error message, omitted if the render succeeded"},"created_at":{"type":"string","format":"date-time"}}},"CursorPaginatedLogs":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/PdfLog"}},"has_more":{"type":"boolean","description":"Whether there are more results after this page"},"next_cursor":{"type":"string","nullable":true,"description":"Cursor to pass as `cursor` query parameter to fetch the next page. Null if no more results."}}},"Stats":{"type":"object","properties":{"templates":{"type":"integer","description":"Total number of templates"},"total_renders":{"type":"integer","description":"Total number of PDF renders"},"success_rate":{"type":"integer","description":"Success rate as a percentage (0-100), rounded down; 100 when nothing was rendered"},"avg_duration_ms":{"type":"integer","description":"Average duration of successful renders, in milliseconds"},"total_size_bytes":{"type":"integer","description":"Total size of all generated PDFs in bytes"},"success_count":{"type":"integer","description":"Number of successful renders"},"error_count":{"type":"integer","description":"Number of failed renders"}}},"ApiKey":{"type":"object","properties":{"id":{"type":"string","description":"API key ID"},"name":{"type":"string","description":"Display name","example":"Production"},"prefix":{"type":"string","description":"Key prefix for identification","example":"p4_live_abc..."},"permission":{"type":"string","enum":["full_access","render_only"],"description":"Permission scope"},"created_at":{"type":"string","format":"date-time"}}}},"responses":{"BadRequest":{"description":"Bad request: the body is not a JSON object (`invalid_json`), or a parameter is missing (`missing_parameter`) or invalid (`invalid_parameter`, `invalid_pdf_format`, `invalid_sample_data`, `component_not_found`, `component_type_mismatch`). The message names the field.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"invalid_request_error","code":"missing_parameter","message":"Either template_id or html is required"}}}}},"Unauthorized":{"description":"Unauthorized: missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"authentication_error","code":"unauthorized","message":"Unauthorized"}}}}},"Forbidden":{"description":"Forbidden: the API key is valid but `render_only`, and this endpoint needs `full_access`","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"authentication_error","code":"insufficient_permissions","message":"Your API key does not have the required permissions for this endpoint."}}}}},"NotFound":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"},"example":{"error":{"type":"not_found_error","code":"resource_not_found","message":"Template not found"}}}}}}},"tags":[{"name":"Render","description":"Generate PDFs from templates or raw HTML. This is the core endpoint: most integrations only need this."},{"name":"Templates","description":"CRUD operations for HTML templates. Templates support Handlebars `{{variables}}` and can be referenced by ID or slug in render requests. Requires `full_access` API key scope."},{"name":"Components","description":"Reusable HTML fragments: headers (repeat at top of every page), footers (repeat at bottom), and blocks (render inline). Attach a header or footer with a <pdf4-header> / <pdf4-footer> tag in the template HTML or with header_component_id / footer_component_id: template writes keep the two in sync, and the tag wins at render time (a template saved before they were kept in sync, whose tag names another component, keeps printing its stored one). Reference blocks via <pdf4-block> tags in template HTML. Requires `full_access` API key scope."},{"name":"Logs","description":"View PDF generation history. Each render (success or error) is logged with duration, file size, and metadata. Requires `full_access` API key scope."}]}