Docs

PHP SDK

Use composer require relaypdf/relaypdf in PHP 8.1+ when you want the official client instead of raw curl. Request JSON field names match REST; methods are camelCase. The package README is the full method and error reference.

The official PHP SDK uses ext-curl and ext-json and mirrors the Node client. Field names in request bodies match REST. Methods are camelCase.

Installation

Requires PHP 8.1+ with curl, json, and hash.

Package: relaypdf/relaypdf. Current line is 0.1.x. The README is the full method and error reference.

composer
composer require relaypdf/relaypdf

Quick start

apiKey is required. Load RELAYPDF_API_KEY from the env file written by relaypdf setup.

index.php
<?php
use RelayPDF\RelayPDF;

$client = new RelayPDF(getenv('RELAYPDF_API_KEY'));
$pdf = $client->pdf->fromHtml(
    '<h1>Invoice #1042</h1><p>Total: $1,200.00</p>',
    ['filename' => 'invoice.pdf'],
);
$pdf->save('invoice.pdf');

URL, Markdown, templates

Same sources as REST. fromTemplate takes a published template id or slug plus an array.

fromUrl / fromMarkdown / fromTemplate
$pdf = $client->pdf->fromUrl('https://example.com', [
    'filename' => 'page.pdf',
    'options' => ['format' => 'A4', 'printBackground' => true],
]);
$md = $client->pdf->fromMarkdown("# Hello\n\nFrom **Markdown**.");
$invoice = $client->pdf->fromTemplate('invoice', ['number' => 'INV-1042', 'total' => 1458], [
    'filename' => 'invoice.pdf',
    'strict' => true,
]);

Binary, URL, and async results

Default is binary with save(). response=url returns a 24-hour link. response=async returns a job; wait then download.

response modes
$urlResult = $client->pdf->fromHtml('<h1>Hi</h1>', ['response' => 'url']);
$job = $client->convert->fromPath('deck.pptx', ['to' => 'pdf', 'response' => 'async']);
$done = $client->jobs->wait($job->id);
$client->files->download($done['id'])->save('deck.pdf');

Errors

HTTP failures throw RelayPDFError with status, code, message, and optional retryAfter.

RelayPDFError
try {
    $client->pdf->fromUrl('https://example.com');
} catch (RelayPDF\RelayPDFError $err) {
    echo $err->status, $err->code, $err->getMessage(), $err->retryAfter;
}

SDK reference

JSON bodies keep REST camelCase. Methods are camelCase. The Composer README lists every helper.

MethodHTTPDescription
health() / account()GET /health · /v1/accountLiveness and wallet. Account is not billed.
pdf.fromHtml / fromUrl / fromMarkdown / fromTemplate / createPOST /v1/pdfHTML, URL, Markdown, or template → PDF
pdf.merge / extract / protect / unlock / bookmarks / raster / fromImages / stamp / rotate / deletePages / compress / info / text / formFields / formFillPOST /v1/pdf/*PDF tools
images.fromHtml / fromUrlPOST /v1/imagesScreenshot
convert.create / fromHtml / fromPath / wkhtmlPOST /v1/convertLibreOffice or wkhtmltopdf
templates.*/v1/templatesHandlebars drafts including preview/generate
barcodes.create / qr · zip.createPOST /v1/barcodes · /v1/zipBarcode, QR, zip
jobs.get / wait · files.downloadGET /v1/jobs/:id · /v1/files/:idPoll and 24h download
Webhooks::verifyRelayPDF-SignatureHMAC-SHA256

Document platform release support

The release adds ocr, pdfa, crop, resize, repair, optimize, attachments, extract-images, redact, compress, image-convert, and email processing. Every official SDK exposes process / ProcessAsync plus files.upload, files.delete, billingUsage / billing_usage, and billingLimits / billing_limits. Availability requires the matching released package. Older published versions may not contain these methods.

See /docs/files, /docs/billing, and each operation guide for field names and limits.

For safe retries, use URL or async output with Idempotency-Key. Per-request caps use X-RelayPDF-Max-Charge-Microdollars (integer millionths of USD). Billing APIs preserve microdollar precision; legacy account millicent fields are not the complete precise balance.

Native OCR with a per-job cap

Requires relaypdf/relaypdf 0.1.2 or a compatible newer release. Replace the example URL with your own publicly accessible scan. The 40000-microdollar cap authorizes at most $0.04; it is not a price estimate. Reuse the idempotency key only for retries of the same request.

$client->files->upload / delete; $client->billingUsage / billingLimits

Files and billing APIs do not require a separate client. See /docs/files, /docs/billing, and /docs/idempotency for ownership, precision, and retry behavior.

document.php
<?php
require 'vendor/autoload.php';
use RelayPDF\RelayPDF;

$client = new RelayPDF(
    getenv('RELAYPDF_API_KEY'),
);
$job = $client->process('ocr', [
    'url' => 'https://example.com/scan.pdf',
    'response' => 'async',
], [
    'idempotencyKey' => 'scan-001',
    'maxChargeMicrodollars' => 40000,
]);