API Reference

API Documentation

Everything you need to generate PDFs with the PDFGen AI API. Simple REST endpoints, AI-powered features, and clear examples.

Authentication

All API requests require an API key passed as a Bearer token in the Authorization header.

Authorization: Bearer pk_your_api_key_here

Get your API key from the Dashboard → API Keys page after signing up.

Base URL

https://pdfgen.ai/api

Rate Limits

PlanPricePDFs/monthAI calls/month
Free$05010
Starter$192,000100
Pro$4915,000500
Business$99100,0002,000
Enterprise$299UnlimitedUnlimited
POST/api/generate

Generate PDF

Generate a PDF from HTML content or a saved template with data.

Request Body

{
  // Option 1: Raw HTML
  "html": "<h1>Hello {{name}}</h1>",
  "data": { "name": "World" },

  // Option 2: Saved template
  "template_id": "uuid-here",
  "data": { "name": "World" }
}

Response (200)

{
  "job_id": "uuid",
  "status": "completed",
  "url": "https://...supabase.co/storage/.../file.pdf"
}

Error Responses

StatusDescription
400Missing html or template_id
401Missing or invalid API key
429Rate limit exceeded
POST/api/ai/template

AI Template Generation

Describe a document in plain English and the AI generates a professional HTML template with {{variables}}.

Request Body

{
  "prompt": "Professional invoice with company name, date, line items table, and total",
  "save": true,
  "name": "My Invoice"
}

Response (200)

{
  "html": "<!DOCTYPE html><html>...</html>",
  "variables": ["company_name", "invoice_date", "line_items", "total"],
  "template_id": "uuid or null"
}

Error Responses

StatusDescription
400Missing prompt
401Missing or invalid API key
429AI rate limit exceeded
POST/api/ai/fill

AI Data Mapping

Send raw JSON data and a list of template variables. The AI intelligently maps fields — e.g. first_name + last_name → full_name.

Request Body

{
  "data": {
    "first": "John",
    "last": "Doe",
    "amt": 99.99,
    "order_date": "2026-04-24"
  },
  "variables": ["full_name", "amount", "date"],
  "context": "This is for an invoice"
}

Response (200)

{
  "mapped": {
    "full_name": "John Doe",
    "amount": "99.99",
    "date": "2026-04-24"
  }
}

Error Responses

StatusDescription
400Missing data or variables
401Missing or invalid API key
429AI rate limit exceeded
502AI returned invalid JSON

Quick Start

Generate your first PDF in 3 steps:

1

Sign up and get your API key

Create an account, then go to Dashboard → API Keys.

2

Generate a PDF from HTML

curl -X POST https://pdfgen.ai/api/generate \
  -H "Authorization: Bearer pk_your_key" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Hello World</h1><p>My first PDF!</p>"}'
3

Or let AI create a template

curl -X POST https://pdfgen.ai/api/ai/template \
  -H "Authorization: Bearer pk_your_key" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Professional invoice with line items", "save": true}'

Ready to start building?

Get your free API key and generate your first PDF in seconds.

Get Your Free API Key