Quick Start

Get up and running with Operyn.ai in under 5 minutes

Base URL: https://html2pdf.operyn.ai

Step 1: Get Your API Key

  1. Sign up for a starter account at operyn.ai
  2. Navigate to your dashboard
  3. Copy your API key

Step 2: Make Your First Request

cURL
curl -X POST https://html2pdf.operyn.ai/api/v1/pdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com"
  }'

Step 3: Get Your File

Response
{
  "success": true,
  "downloadUrl": "https://cdn.operyn.ai/files/abc123.pdf",
  "filename": "pdf_abc123.pdf",
  "size": 245678
}

Authentication

All API requests require authentication using your API key

API Key Authentication

Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

⚠️ Keep your API key secure! Never expose it in client-side code or public repositories.

PDF Generation API

Convert any URL or HTML to a pixel-perfect PDF

POST /api/v1/pdf

Request Parameters

Parameter Type Required Description
url string Yes The URL to convert to PDF
format string No Paper format: A4, Letter, Legal (default: A4)
options object No Additional PDF options (see below)

PDF Options

{
  "url": "https://example.com/invoice",
  "format": "A4",
  "options": {
    "printBackground": true,
    "margin": {
      "top": "20mm",
      "right": "20mm",
      "bottom": "20mm",
      "left": "20mm"
    },
    "displayHeaderFooter": false,
    "landscape": false
  }
}

Response

{
  "success": true,
  "downloadUrl": "/files/pdf_abc123.pdf",
  "filename": "pdf_abc123.pdf",
  "size": 245678
}

Screenshot API

Capture high-quality screenshots of any webpage

POST /api/v1/screenshot

Request Parameters

Parameter Type Required Description
url string Yes The URL to screenshot
width number No Viewport width (default: 2560)
fullPage boolean No Capture full page (default: true)
format string No png or jpeg (default: png)

Example Request

{
  "url": "https://example.com",
  "width": 1920,
  "fullPage": true,
  "format": "png"
}

Code Examples

Implementation examples in popular languages

JavaScript / Node.js

JavaScript
const response = await fetch('https://html2pdf.operyn.ai/api/v1/pdf', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com/invoice',
    format: 'A4'
  })
});

const data = await response.json();
console.log('PDF URL:', data.downloadUrl);

Python

Python
import requests

response = requests.post(
    'https://html2pdf.operyn.ai/api/v1/pdf',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'url': 'https://example.com/invoice',
        'format': 'A4'
    }
)

data = response.json()
print(f"PDF URL: {data['downloadUrl']}")

PHP

PHP
$ch = curl_init('https://html2pdf.operyn.ai/api/v1/pdf');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'url' => 'https://example.com/invoice',
    'format' => 'A4'
]));

$response = curl_exec($ch);
$data = json_decode($response);
echo "PDF URL: " . $data->downloadUrl;

Error Handling

Understanding and handling API errors

HTTP Status Codes

Code Meaning
200 Success - File generated
400 Bad Request - Invalid parameters
401 Unauthorized - Invalid API key
429 Too Many Requests - Rate limit exceeded
500 Server Error - Something went wrong

Error Response Format

{
  "error": "Invalid API key",
  "message": "The provided API key is invalid or expired"
}