API Documentation

Complete reference for the Phantom Ink PDF generation API.

Authentication

API Key Authentication

Pass your API key in the Authorization header:

Authorization: Bearer sk_live_abc123xyz789

x402 Protocol (Agent Payments)

Agents can omit the API key header. The API returns HTTP 402 Payment Required with payment instructions. Agent signs a USDC transaction on Polygon and resubmits the request.

Endpoints

MethodPathDescription
POST/api/generateGenerate a PDF from HTML, Markdown, or template
GET/api/documents/{id}Retrieve a previously generated document
GET/api/usageGet current credit balance and usage statistics
POST/api/templatesList available document templates
POST/api/healthHealth check endpoint

POST /api/generate

Request Body

{
  "format": "pdf",                    // "pdf" (required)
  "html": "<h1>Document</h1>",       // HTML string (one of: html, markdown, template)
  "markdown": "# Document",           // Markdown string (one of: html, markdown, template)
  "template": "invoice",              // Template name (one of: html, markdown, template)
  "data": {                           // Template variables
    "invoice_number": "INV-001",
    "amount": "1000.00"
  },
  "options": {
    "orientation": "portrait",        // "portrait" or "landscape"
    "margins": "1in",                 // CSS margin value
    "style": "minimal",               // CSS preset: "minimal", "formal", "modern"
    "width": "8.5in",                 // Page width
    "height": "11in"                  // Page height
  }
}

Response

{
  "success": true,
  "document_id": "doc_abc123xyz789",
  "url": "https://phantom-ink.melis.ai/documents/doc_abc123xyz789.pdf",
  "created_at": "2026-03-28T10:30:00Z",
  "cost_credits": 1,
  "pages": 1
}

Rate Limits

Basic Plan1,000 requests/month

$0.005 per document. No burst limits.

Premium PlanUnlimited requests

$0.03 per document. Priority queue.

Rate limit headers included in all responses. Exceeding limits returns 429 Too Many Requests.

Error Codes

200Success
400Bad Request — invalid parameters
401Unauthorized — missing or invalid API key
402Payment Required — x402 protocol
429Too Many Requests — rate limit exceeded
500Internal Server Error

Available Templates

Basic

  • • invoice
  • • receipt
  • • formal-letter
  • • data-report

Premium

  • • branded-invoice
  • • quarterly-report
  • • business-proposal
  • • certificate
  • • ebook-cover
  • • annual-report
  • • white-paper
  • • print-menu