AI-native document infrastructure

Build a template with AI.
Call it from your API.

Create templates from prompts, screenshots, references, and sample JSON. Map the fields, publish, then generate PDFs with an API your developers can read.

Base URL: api.docujson.comVersion 1.0REST + JSONcURL · JS · Python · Ruby · Go · PHP

Quickstart (5 minutes)

Generate your first PDF in under 5 minutes. All you need is an API key.

1

Sign up and grab your API key

Create a free account, head to API Keys, and generate a new key. Your key format: dj_ followed by 32 characters. Treat it like a password — never commit it to a public repo.

2

Build a template (or use a preset)

Use the AI Template Builder to draft a layout from a prompt, screenshot, reference PDF, or sample JSON. Or start from a public template like invoice-basic.

3

Make your first request

Send a POST request with your template ID and data.

bash
curl -X POST https://api.docujson.com/v1/generate \
  -H "Authorization: Bearer dj_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "invoice-basic",
    "data": {
      "invoice_number": "INV-0001",
      "issue_date": "2026-04-13",
      "due_date": "2026-05-13",
      "from": { "name": "Your Company" },
      "to":   { "name": "Customer Corp" },
      "line_items": [
        { "description": "Consulting", "quantity": 10, "unit_price": 150 }
      ],
      "tax_rate": 0.0875
    }
  }'
4

You get back a PDF URL

A standard HTTPS URL. Download it, email it, or store it according to your retention requirements.

json
{
  "success": true,
  "pdfUrl": "https://blob.vercel-storage.com/...",
  "templateId": "invoice-basic",
  "generatedAt": "2026-04-13T12:00:00.000Z"
}

Authentication

All API requests require authentication via an API key. Keys use the format dj_<uuid> and are created from your dashboard. Only a SHA-256 hash of the key is stored on our side.

You can pass the key using either header:

bash
# Recommended: Authorization Bearer header
curl -H "Authorization: Bearer dj_your_api_key" https://api.docujson.com/v1/generate

# Also supported: X-API-Key header
curl -H "X-API-Key: dj_your_api_key" https://api.docujson.com/v1/generate

Keep your API key secure

Never expose your API key in client-side code. Use it from server-side scripts, automation platforms, or scripting extensions like Airtable.

AI Template Builder

The AI Template Builder is how you go from an idea to a published, mapped template. It is a creation workflow, not the standard runtime generation path. Inputs are accepted as a prompt, a screenshot, a reference PDF or HTML document, or sample JSON.

Draft from anything
Prompt, screenshot, reference doc, or sample JSON.
Visual field mapping
Connect JSON paths like customer.name or line_items[] to document regions.
Publish to a workspace
Published templates expose a stable templateId for your API.
Iterate with revisions
Refine via natural-language chat until the layout matches.

Generate PDF

POST/api/v1/generate

Generate a PDF document from a published template and data. Returns a hosted PDF URL by default.

Request Body

ParameterTypeRequiredDescription
templateIdstringRequiredTemplate to use. Public templates: invoice-basic, weekly-report, calendar-schedule, kpi-dashboard. Or a custom published templateId.
dataobjectRequiredData that matches the template schema. See Template Payloads below.
optionsobjectOptionalPDF output options (format, orientation, margins). See PDF Options.
outputFormatstringOptional"url" (default), "base64", or "buffer". See Output Formats.
webhookobjectOptionalAsync delivery. Object with url (string) and optional headers (object). See Webhooks.

Response

ParameterTypeRequiredDescription
successbooleanRequiredWhether the request succeeded
pdfUrlstringOptionalHosted PDF URL (when outputFormat is "url")
base64stringOptionalBase64-encoded PDF (when outputFormat is "base64")
templateIdstringRequiredThe template that was used
generatedAtstringRequiredISO 8601 timestamp

Response Headers

ParameterTypeRequiredDescription
X-Generation-Time-MsnumberRequiredTime taken to generate the PDF (ms)
X-PDF-Size-BytesnumberRequiredSize of the generated PDF (bytes)
X-Usage-RemainingnumberRequiredRemaining PDF generations for the current billing period
X-RateLimit-LimitnumberRequiredRequests allowed per minute
X-RateLimit-RemainingnumberRequiredRequests left in this window
X-RateLimit-ResetnumberRequiredUnix timestamp when the window resets

Example

javascript
const response = await fetch('https://api.docujson.com/v1/generate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer dj_your_api_key',
  },
  body: JSON.stringify({
    templateId: 'weekly-report',
    data: {
      reportTitle: 'Engineering Weekly Status',
      versionAsOf: '04/13/2026',
      projects: [
        {
          title: 'Platform Migration',
          status: 'In Progress',
          progress: 68,
          releaseDate: '05/15/2026',
        },
      ],
    },
    options: {
      format: 'Letter',
      orientation: 'portrait',
    },
  }),
});

const { success, pdfUrl } = await response.json();
console.log(pdfUrl);

List Templates

GET/api/v1/templates

Returns all available templates. No authentication required for public templates.

Query Parameters

ParameterTypeRequiredDescription
categorystringOptionalFilter by category: calendar, report, dashboard, invoice
idstringOptionalGet a specific template by ID

Example Response

json
{
  "templates": [
    { "id": "invoice-basic",     "name": "Basic Invoice",          "category": "invoice",   "version": "1.0.0" },
    { "id": "weekly-report",     "name": "Weekly Project Report",  "category": "report",    "version": "1.0.0" },
    { "id": "calendar-schedule", "name": "Project Calendar",       "category": "calendar",  "version": "1.0.0" },
    { "id": "kpi-dashboard",     "name": "KPI Dashboard",          "category": "dashboard", "version": "1.0.0" }
  ],
  "total": 4,
  "categories": ["calendar", "report", "dashboard", "invoice", "certificate", "custom"]
}

Template Schema

GET/api/v1/templates/:id/schema

Returns the JSON schema and default PDF options for a specific template. Use this to validate your data before calling the generate endpoint.

Path Parameters

ParameterTypeRequiredDescription
idstringRequiredTemplate ID (e.g., invoice-basic, weekly-report)

Example

bash
curl https://api.docujson.com/v1/templates/invoice-basic/schema
json
{
  "templateId": "invoice-basic",
  "templateName": "Basic Invoice",
  "schema": {
    "type": "object",
    "required": ["invoiceNumber", "items", "client"],
    "properties": {
      "invoiceNumber": { "type": "string", "description": "Invoice number" },
      "items": { "type": "array", "items": { ... } },
      "client": { "type": "object", "properties": { ... } }
    }
  },
  "defaultOptions": {
    "format": "Letter",
    "orientation": "portrait",
    "margin": { "top": "0.75in", "right": "0.75in", "bottom": "0.75in", "left": "0.75in" }
  }
}

Output Formats

Control how the generated PDF is delivered using the outputFormat field.

urlDefault

Returns a hosted PDF URL via Vercel Blob Storage. The URL is permanent and never expires. Best for Airtable attachment fields, email links, and most integrations.

base64

Returns the PDF as a base64-encoded string in the JSON response body. Useful when you need to process the PDF directly without downloading it.

buffer

Returns the raw PDF binary as the response body with Content-Type: application/pdf. Ideal for direct file downloads or piping to storage.

json
{
  "templateId": "invoice-basic",
  "data": { ... },
  "outputFormat": "base64"
}

// Response:
{
  "success": true,
  "base64": "JVBERi0xLjQKJeLjz9MKMSAwIG9ia...",
  "templateId": "invoice-basic",
  "generatedAt": "2026-04-13T12:00:00.000Z"
}

PDF Options

Customize the PDF output using the options field. These override template defaults.

ParameterTypeRequiredDescription
formatstringOptional"Letter" (default), "A4", or "Legal"
orientationstringOptional"portrait" (default) or "landscape"
marginobjectOptionalCustom margins: { top, right, bottom, left } as CSS strings (e.g., "0.5in", "10mm")
displayHeaderFooterbooleanOptionalShow header/footer in the PDF
headerTemplatestringOptionalCustom HTML header template
footerTemplatestringOptionalCustom HTML footer template
json
{
  "templateId": "kpi-dashboard",
  "data": { ... },
  "options": {
    "format": "A4",
    "orientation": "landscape",
    "margin": { "top": "0.5in", "right": "0.5in", "bottom": "0.5in", "left": "0.5in" }
  }
}

Webhooks

For long-running PDF generation, include a webhook.url in your request. DocuJSON will POST the result to your URL when the PDF is ready.

Webhooks are available on Starter and above. This is the recommended pattern when using platforms with short timeouts (Airtable 30s, Zapier 30s).

json
// Request
{
  "templateId": "calendar-schedule",
  "data": { ... },
  "webhook": {
    "url": "https://hooks.zapier.com/your-catch-hook",
    "headers": { "X-Webhook-Secret": "your-secret-value" }
  }
}

When the PDF is ready, DocuJSON sends a POST request to your webhook URL:

json
// Webhook payload (POST to your URL)
{
  "success": true,
  "pdfUrl": "https://blob.vercel-storage.com/calendar-abc123.pdf",
  "templateId": "calendar-schedule",
  "generatedAt": "2026-04-13T12:00:00.000Z"
}

Errors

Standard HTTP status codes. Error bodies follow this shape:

json
{
  "error": {
    "code": "invalid_template_data",
    "message": "Field 'invoice_number' is required",
    "request_id": "req_xyz789"
  }
}

Include request_id when filing a support ticket — it makes debugging much faster.

StatusErrorDescription
400Missing required field: templateIdRequest body is missing templateId
400Missing required field: dataRequest body is missing data object
400Template 'x' not foundInvalid template ID. Returns list of available templates.
400Invalid data for templateData doesn't match the template schema. Returns validationErrors array.
401Missing API keyNo Authorization or X-API-Key header provided
401Invalid or inactive API keyAPI key is incorrect or has been deactivated
403Template 'x' is not enabledTemplate exists but isn't enabled for your workspace
403Workspace is suspendedYour workspace has been suspended
429Monthly PDF generation limit reachedYou've hit your plan's monthly limit.
500PDF generation failedInternal error during rendering. Returns details.

Rate Limits

PDF generation is rate-limited per workspace based on your plan. Every response includes rate-limit headers so you can adapt your client.

PlanMonthly PDFsTemplatesWebhooks
Hobby100All public
Starter1,000All + custom uploads
Included
Business10,000All + AI builder
Included
Enterprise100,000+Custom
Included

When you hit your limit, the API returns a 429 with your current usage. Limits reset on the 1st of each month. View full pricing

Template Payloads

Complete example payloads for each public template. Use the Schema API to get the full JSON schema for validation.

Basic Invoice

invoice-basicHobby

Required fields: invoiceNumber, items, client

json
{
  "templateId": "invoice-basic",
  "data": {
    "invoiceNumber": "INV-2026-001",
    "invoiceDate": "2026-04-13",
    "dueDate": "2026-05-13",
    "company": {
      "name": "Northwind Consulting",
      "address": "742 Evergreen Terrace, Suite 200",
      "email": "billing@northwind.io"
    },
    "client": {
      "name": "Meridian Technologies",
      "address": "1600 Innovation Blvd",
      "email": "accounts@meridiantech.com"
    },
    "items": [
      { "description": "Web Development", "quantity": 40, "unitPrice": 150, "amount": 6000 },
      { "description": "Design Review",   "quantity": 8,  "unitPrice": 125, "amount": 1000 }
    ],
    "subtotal": 7000,
    "tax": 630,
    "total": 7630
  }
}

Weekly Report

weekly-reportHobby

Required fields: projects

json
{
  "templateId": "weekly-report",
  "data": {
    "reportTitle": "Engineering Weekly Status",
    "versionAsOf": "04/13/2026",
    "projects": [
      {
        "title": "Platform Migration",
        "status": "In Progress",
        "releaseDate": "06/15/2026",
        "progress": 68,
        "milestones": [
          { "name": "Architecture Review", "startDate": "03/15/2026", "status": "Pending" }
        ],
        "updates": {
          "thisWeek": { "text": "Completed database schema migration." },
          "lastWeek": { "text": "API gateway configuration finalized." }
        }
      }
    ]
  }
}

Calendar Schedule

calendar-scheduleStarter

Required fields: months

json
{
  "templateId": "calendar-schedule",
  "data": {
    "projectTitle": "Product Launch 2026",
    "orientation": "Landscape",
    "masthead": ["04.13.26", "PRODUCT LAUNCH", "RELEASE SCHEDULE", "12 WEEKS"],
    "palette":   { "dev": "#7c3aed", "review": "#ea580c", "milestone": "#b45309" },
    "legend":    { "dev": "Development Sprint", "review": "Review", "milestone": "Milestone" },
    "months":    [{ "y": 2026, "m": 3 }, { "y": 2026, "m": 4 }, { "y": 2026, "m": 5 }],
    "events":    [{ "date": "2026-05-01", "kind": "milestone", "text": "Launch Day" }],
    "ranges":    [{ "start": "2026-04-01", "end": "2026-04-12", "kind": "review", "label": "QA" }]
  }
}

KPI Dashboard

kpi-dashboardStarter

Required fields: title, metrics

json
{
  "templateId": "kpi-dashboard",
  "data": {
    "title": "Q1 2026 Performance Dashboard",
    "subtitle": "January - March 2026",
    "metrics": [
      { "label": "Revenue",       "value": "$1.2M", "change": "+12%",  "trend": "up" },
      { "label": "Active Users",  "value": "8,432", "change": "+5%",   "trend": "up" },
      { "label": "Churn Rate",    "value": "2.1%",  "change": "-0.3%", "trend": "down" },
      { "label": "NPS Score",     "value": "72",    "change": "+4",    "trend": "up" }
    ]
  }
}

Ready to generate your first PDF?

Create a free account, draft your first template with AI, and ship it to your API in minutes.