Node.js SDK
The official Pictify SDK for Node.js provides a type-safe, promise-based interface for the Pictify API — generate images, PDFs, and GIFs from raw HTML, live URLs, and reusable templates.Installation
Quick Start
Configuration
The client is constructed with a config object.apiKey is required; every request is sent with an Authorization: Bearer <API_KEY> header.
Render an Image from HTML
renderHtml(options) — POST /image. Returns { url, id, createdAt }.
/image endpoint accepts a single html field, so any css you pass is injected into a <style> tag prepended to the HTML. format is mapped to the endpoint’s fileExtension.
Screenshot a Live URL
renderUrl(options) — POST /image with url. Returns { url, id, createdAt }.
Render a Template
render(options) — POST /templates/:uid/render. Returns a results[] envelope with a convenience url getter (results[0]?.url).
Render a Specific Layout
Pass a singlelayout to render one named variant.
Render Multiple Layouts
renderLayouts(options) — POST /templates/:uid/render with layouts (max 20).
Templates can have layout variants (e.g. square, story) created via AI Resize in the Pictify editor. Use default for the base layout. Missing or invalid layouts come back in errors[] rather than throwing.
Render an Animated GIF
renderGif(options) — POST /gif. Provide exactly one source: html, url, or templateId. The API’s nested { gif: {...} } envelope is flattened to { url, uid, width, height, animationLength }.
The source HTML/URL must contain motion (e.g. a CSS animation). Static content produces no frames and returns a render error (HTTP 422).
Batch Rendering (async)
renderBatch(options) — POST /templates/:uid/batch-render. Returns immediately (HTTP 202) with a batchId; poll getBatchResults(batchId) (GET /templates/batch/:batchId/results) to track progress.
Templates
Get a Template
getTemplate(templateId) — GET /templates/:uid. Unwraps the { template } envelope.
List Templates
listTemplates(options) — GET /templates. Returns { templates, pagination }.
Create a Template
createTemplate(options) — POST /templates. Variables are auto-discovered from {{variableName}} tokens in the HTML body.
Error Handling
All API errors throw a typed subclass ofPictifyError.
Error Types
| Error Class | Code | HTTP | Description |
|---|---|---|---|
AuthenticationError | INVALID_API_KEY | 401 | Invalid or missing API key |
QuotaExceededError | QUOTA_EXCEEDED | 402 / 429 | Render quota exceeded |
TemplateNotFoundError | TEMPLATE_NOT_FOUND | 404 | Template (or batch job) not found |
RenderError | RENDER_FAILED | 422 (and other 4xx) | Render or input validation failed (error.errors holds field-level details) |
RateLimitError | RATE_LIMIT_EXCEEDED | 429 | Too many requests |
ServerError | SERVER_ERROR | 5xx | Server-side failure |
NetworkError | NETWORK_ERROR | — | Network request failed |
TimeoutError | TIMEOUT | — | Request timed out |