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 require relaypdf/relaypdfQuick start
apiKey is required. Load RELAYPDF_API_KEY from the env file written by relaypdf setup.
<?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.
$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.
$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.
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.
| Method | HTTP | Description |
|---|---|---|
| health() / account() | GET /health · /v1/account | Liveness and wallet. Account is not billed. |
| pdf.fromHtml / fromUrl / fromMarkdown / fromTemplate / create | POST /v1/pdf | HTML, URL, Markdown, or template → PDF |
| pdf.merge / extract / protect / unlock / bookmarks / raster / fromImages / stamp / rotate / deletePages / compress / info / text / formFields / formFill | POST /v1/pdf/* | PDF tools |
| images.fromHtml / fromUrl | POST /v1/images | Screenshot |
| convert.create / fromHtml / fromPath / wkhtml | POST /v1/convert | LibreOffice or wkhtmltopdf |
| templates.* | /v1/templates | Handlebars drafts including preview/generate |
| barcodes.create / qr · zip.create | POST /v1/barcodes · /v1/zip | Barcode, QR, zip |
| jobs.get / wait · files.download | GET /v1/jobs/:id · /v1/files/:id | Poll and 24h download |
| Webhooks::verify | RelayPDF-Signature | HMAC-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.
<?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,
]);