API Reference

Authentication

All requests require an API key. Include it in the X-API-Key header.

Example
curl -X POST https://api.tailpdf.com/pdf \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{"content": "<div class=\"p-8\">Hello World</div>"}' \
  --output document.pdf
Header Required Value
X-API-Key Required Your API key from the dashboard

Get Your API Key

1

Sign in to TailPDF

Go to tailpdf.com and access your dashboard.

2

Navigate to API Tokens

Find the API Tokens section in your team settings.

3

Create & copy your token

Click "Create Token"copy it immediately, it won't be shown again.

Security Best Practices

Keep keys secret

Never expose in client-side code, repos, or logs.

Use environment variables

Store keys in env vars, not hardcoded.

Rotate keys regularly

Create new keys periodically, disable old ones.

Separate environments

Use different keys for dev, staging, production.

Code Examples

PHP

<?php
$apiKey = getenv('TAILPDF_API_KEY');

$ch = curl_init('https://api.tailpdf.com/pdf');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'X-API-Key: ' . $apiKey,
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'content' => '<div class="p-8">Hello World</div>',
    ]),
]);

$pdf = curl_exec($ch);
curl_close($ch);

file_put_contents('document.pdf', $pdf);

JavaScript

const apiKey = process.env.TAILPDF_API_KEY;

const response = await fetch('https://api.tailpdf.com/pdf', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': apiKey,
  },
  body: JSON.stringify({
    content: '<div class="p-8">Hello World</div>',
  }),
});

const pdf = await response.arrayBuffer();
// Save or process the PDF

Python

import os
import requests

api_key = os.environ['TAILPDF_API_KEY']

response = requests.post(
    'https://api.tailpdf.com/pdf',
    headers={
        'Content-Type': 'application/json',
        'X-API-Key': api_key,
    },
    json={
        'content': '<div class="p-8">Hello World</div>',
    },
)

with open('document.pdf', 'wb') as f:
    f.write(response.content)

Authentication Errors

401
missing_api_key

X-API-Key header not included in request.

401
invalid_api_key

API key is invalid or has been disabled.

429
quota_exceeded

Monthly PDF generation quota has been exceeded.