On this page ▾

API Reference

RapidPDF API Documentation

RapidPDF converts HTML content or public URLs into PDFs via a simple REST API. Generate invoices, reports, certificates, and any document — in milliseconds.

Base URL

https://api.rapidpdf.io/api/v1

Content Type

application/json
X-API-Key

API key authentication

All RapidPDF API requests are authenticated with an API key passed via the X-API-Key header. Create keys from your dashboard.


Authentication

RapidPDF uses API key authentication. Create an API key in your dashboard and pass it via the X-API-Key header on every request. Never expose keys in client-side code.

API Key headerbash
X-API-Key: rpdf_xxxxxxxxxxxxxxxxxxxx
⚠️
API keys are shown once at creation time. Store them securely — they cannot be retrieved again. Rotate immediately if exposed.

Endpoints

Generate PDF

POST/api/v1/generate

Convert HTML content or a URL to a PDF. Requires an API key. Returns a JSON envelope with a pre-signed S3 URL plus performance timing headers. Usage is tracked asynchronously per key.

ℹ️
Exactly one of htmlContent or url must be provided — not both, not neither.
ℹ️
Requires X-API-Key header. Rate limited to 100 requests per 60 seconds per key. Exceeding this returns 429.

Request body

ParameterTypeRequiredDescription
htmlContentstringrequiredHTML string to render. 10–1,000,000 characters. Required if url is not provided.
urlstringoptionalPublic URL to navigate to and render. Required if htmlContent is not provided.
pdfOptions.formatstringoptionalPage format: Letter, Legal, Tabloid, Ledger, A0–A6. Default: A4.
pdfOptions.landscapebooleanoptionalLandscape orientation. Default: false.
pdfOptions.marginobjectoptionalPage margins — top, right, bottom, left as CSS length strings (e.g. "1cm").

Example request

cURLbash
curl -X POST https://api.rapidpdf.io/api/v1/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: rpdf_xxxxxxxxxxxxxxxxxxxx" \
  -d '{
    "htmlContent": "<h1 style=\"font-family:sans-serif\">Invoice #1042</h1>",
    "pdfOptions": {
      "format": "A4",
      "landscape": false,
      "printBackground": true,
      "margin": { "top": "2cm", "bottom": "2cm", "left": "1.5cm", "right": "1.5cm" }
    }
  }'

Performance response headers

HeaderValue
Server-Timingpdf;dur=800, s3;dur=300, total;dur=1100
X-Perf-Pdf-Generation-MsPDF render duration in ms
X-Perf-S3-Upload-MsS3 upload duration in ms
X-Perf-Total-MsTotal end-to-end request duration in ms

Response

FieldTypeDescription
successbooleanAlways true on 200.
data.idstringUnique filename of the generated PDF.
data.urlstringPre-signed S3 URL valid for 24 hours.
data.expiresAtISO 8601 dateExpiry timestamp for the signed URL.
data.size_bytesnumberFile size of the generated PDF in bytes.
messagestringHuman-readable status message.
200 OKjson
{
  "success": true,
  "data": {
    "id": "1737048457123.pdf",
    "url": "https://your-bucket.s3.amazonaws.com/files/1737048457123.pdf?X-Amz-...",
    "expiresAt": "2026-05-07T10:24:17.123Z",
    "size_bytes": 48230
  },
  "message": "PDF generated successfully"
}

Health Check

GET/api/v1/health

Returns the current health of the API and its dependencies (MongoDB, Redis). Use for uptime monitoring. This endpoint does not require an API key — it is mounted on the public router so monitoring tools can reach it without authentication.

200 OKjson
{
  "status": "OK",
  "message": "API and dependencies are healthy",
  "checks": {
    "api": true,
    "mongodb": { "ok": true, "state": 1 },
    "redis": { "ok": true }
  },
  "timestamp": "2026-05-17T10:00:00.000Z"
}
503 Service Unavailablejson
{
  "status": "DEGRADED",
  "message": "One or more dependencies are unavailable",
  "checks": {
    "api": true,
    "mongodb": { "ok": false, "state": 0 },
    "redis": { "ok": true }
  },
  "timestamp": "2026-05-17T10:00:00.000Z"
}

PDF Options Reference

Pass any of these inside the pdfOptions object on either PDF endpoint. All fields are optional.

OptionTypeDefaultNotes
formatstring"A4"Letter, Legal, Tabloid, Ledger, A0–A6.
landscapebooleanfalseRotate page to landscape orientation.
printBackgroundbooleantrueRender CSS background colors and images.
scalenumber1Page scale factor. Range: 0.1–2.0.
margin.topstring"1cm"Top margin. Any CSS length (px, cm, mm, in).
margin.rightstring"1cm"Right margin.
margin.bottomstring"1cm"Bottom margin.
margin.leftstring"1cm"Left margin.
mediastring"screen"CSS media type. Use "print" for @media print styles.
widthstringCustom page width, overrides format (e.g. "210mm").
heightstringCustom page height, overrides format.

Full pdfOptions example

pdfOptions objectjson
{
  "pdfOptions": {
    "format": "A4",
    "landscape": false,
    "printBackground": true,
    "scale": 1,
    "margin": {
      "top": "2cm",
      "right": "1.5cm",
      "bottom": "2cm",
      "left": "1.5cm"
    },
    "media": "print"
  }
}
💡
For pixel-perfect rendering, use media: "print" if your HTML has @media print styles. Use media: "screen" (the default) to render what a user sees in the browser.

Error Reference

All errors follow a consistent JSON envelope. Validation errors include a per-field errors array.

Standard error responsejson
{
  "success": false,
  "message": "Validation failed",
  "errors": [
    { "field": "htmlContent", "message": "String must contain at least 10 character(s)" }
  ]
}
StatusError classWhen it occurs
400BadRequestError / ValidationErrorMalformed request, failed Zod validation, or HTML > 500 KB.
401UnauthorizedErrorMissing or invalid API key.
403ForbiddenErrorValid key but insufficient permissions.
422UnprocessableEntityErrorBoth url and htmlContent omitted.
429TooManyRequestsErrorRate limit exceeded. Respect Retry-After header.
500InternalServerErrorUnexpected server error. Reported to Sentry.
503ServiceUnavailableErrorMongoDB or Redis dependency unavailable.

Rate Limits

RapidPDF uses Redis-backed rate limiting. The generate endpoint is limited per API key.

Route groupLimitWindowBlock duration
API key generate endpoint100 req60 s5 min

Rate limit response headers

HeaderDescription
RateLimit-LimitMaximum requests allowed in the current window.
X-RateLimit-RemainingRequests remaining before the limit resets.
X-RateLimit-ResetUnix timestamp (ms) when the window resets.
429 Too Many Requestsjson
{
  "success": false,
  "message": "Too Many Requests",
  "retryAfter": 42
}
⚠️
When you receive a 429, wait retryAfter seconds before retrying. Continued requests during a block period will extend the block.

Interactive Playground

Test the authenticated PDF generator with your own API key. Paste your key, edit the request body, and click Run to hit /api/v1/generate and generate a real PDF.

POST/api/v1/generate
Request body
Response
Click Run to generate a PDF…
Tests run against /api/v1/generate with the API key you provide.