API

API Overview

The cloudlayer.io API lets you generate PDFs and images from HTML, URLs, and templates. All endpoints follow REST conventions and return standard HTTP status codes.

Base URL

All API requests are made to:

https://api.cloudlayer.io/v1

Every endpoint path in this documentation is relative to this base URL. For example, POST /v1/html/pdf means you send your request to https://api.cloudlayer.io/v1/html/pdf.

All API requests are made to:

https://api.cloudlayer.io/v2

Every endpoint path in this documentation is relative to this base URL. For example, POST /v2/html/pdf means you send your request to https://api.cloudlayer.io/v2/html/pdf.


Authentication

Every request must include your API key in the X-API-Key header. You can find and manage your API keys in the cloudlayer.io dashboard.

X-API-Key: your-api-key-here

Requests without a valid API key receive a 401 Unauthorized response.

Example: Authenticated Request

cURL

curl -X GET "https://api.cloudlayer.io/v1/account" \
  -H "X-API-Key: your-api-key-here"

JavaScript (fetch)

const response = await fetch("https://api.cloudlayer.io/v1/account", {
  method: "GET",
  headers: {
    "X-API-Key": "your-api-key-here",
  },
});

const data = await response.json();

Python (requests)

import requests

response = requests.get(
    "https://api.cloudlayer.io/v1/account",
    headers={"X-API-Key": "your-api-key-here"},
)

data = response.json()

cURL

curl -X GET "https://api.cloudlayer.io/v2/account" \
  -H "X-API-Key: your-api-key-here"

JavaScript (fetch)

const response = await fetch("https://api.cloudlayer.io/v2/account", {
  method: "GET",
  headers: {
    "X-API-Key": "your-api-key-here",
  },
});

const data = await response.json();

Python (requests)

import requests

response = requests.get(
    "https://api.cloudlayer.io/v2/account",
    headers={"X-API-Key": "your-api-key-here"},
)

data = response.json()

Security tip: Never expose your API key in client-side code. Always call the cloudlayer.io API from your server.


Content Types

Most endpoints accept JSON request bodies. Set the Content-Type header accordingly:

ScenarioContent-Type
JSON body (most endpoints)application/json
Multipart form data (template uploads)multipart/form-data
GET requestsNo Content-Type needed

Response content types depend on the endpoint:

ScenarioResponse Content-Type
Document generationapplication/pdf, image/png, image/jpeg, or image/webp
Account, jobs, assets, storageapplication/json

All document generation responses return the raw file binary directly.

All v2 responses return JSON:

ScenarioResponse Content-Type
Document generation (async — default)application/json (job metadata)
Document generation (sync, async: false)application/json (completed job with asset URL)
Account, jobs, assets, storageapplication/json

v2 always returns JSON with job metadata. Only v1 returns raw binary file content directly.


Synchronous vs. Asynchronous Requests

All document generation requests in v1 are processed synchronously. The API waits for the document to be generated and returns the raw file binary (PDF or image) directly in the response body.

curl -X POST "https://api.cloudlayer.io/v1/html/pdf" \
  -H "X-API-Key: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{"html": "PGgxPkhlbGxvIFdvcmxkPC9oMT4="}' \
  --output result.pdf

The response is the raw PDF binary. Use --output (cURL) or handle the response as a binary stream.

Tip: For large or complex documents that take a long time to render, consider switching to the v2 API which supports asynchronous processing.

By default, document generation endpoints in v2 process your request asynchronously. The API returns a JSON response immediately with the job ID, and the generated file is stored and accessible via the Assets endpoint once processing completes.

Asynchronous (default)

curl -X POST "https://api.cloudlayer.io/v2/html/pdf" \
  -H "X-API-Key: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{"html": "PGgxPkhlbGxvIFdvcmxkPC9oMT4="}'

Returns a JSON response immediately:

{
  "id": "1705312200000",
  "status": "pending"
}

Poll the Jobs endpoint or use Webhooks to be notified when the job completes. Once complete, retrieve the result from the Assets endpoint.

Synchronous

To process a request synchronously, include "async": false in your request body. The API still returns JSON, but waits for processing to complete before responding:

curl -X POST "https://api.cloudlayer.io/v2/html/pdf" \
  -H "X-API-Key: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{"html": "PGgxPkhlbGxvIFdvcmxkPC9oMT4=", "async": false}'

The response is JSON with the completed job details, including the asset URL for downloading the generated file.

Note: In v2, storage also defaults to true. When async is true (the default), the generated file is automatically stored and accessible via the Assets endpoint. You can set "storage": false to disable storage, but this requires "async": false as well.


Rate Limits

All accounts are rate-limited to 60 requests per 60 seconds. This limit applies to all endpoints and all plans equally. Exceeding the limit returns a 429 Too Many Requests response.

Separately, your plan has a usage quota — a total number of API calls allowed per billing period. The cl-calls-remaining response header shows how many calls remain in your current period.

HeaderDescription
cl-calls-remainingNumber of API calls remaining in your current billing period

Best practice: Implement retry logic with exponential backoff for 429 responses. Monitor cl-calls-remaining to track usage against your plan quota.


HTTP Status Codes

CodeMeaningDescription
200OKRequest succeeded. Response body contains the result.
400Bad RequestThe request body is malformed or missing required parameters.
401UnauthorizedMissing or invalid API key, or account has exceeded its usage limits.
404Not FoundThe requested resource does not exist (e.g., invalid route).
429Too Many RequestsRate limit exceeded (60 requests per 60 seconds). Retry with exponential backoff.
500Internal Server ErrorSomething went wrong on our end. Contact support if it persists.

Error Response Format

When an error occurs, the API returns a JSON body with the status code and a message:

{
  "statusCode": 400,
  "message": "The 'html' field is required and must be a base64-encoded string."
}
FieldTypeDescription
statusCodenumberThe HTTP status code (matches the response status).
messagestringA human-readable description of the error.

Some error responses may also include a status field with the value "error":

{
  "status": "error",
  "message": "Generation failed: page timeout exceeded."
}

Common Request Parameters

Several parameters appear across multiple document generation endpoints. These are documented in detail on each endpoint page, but here is a quick reference:

Async & Storage Parameters (v2 only)

ParameterTypeDefaultDescription
asyncbooleantrueProcess the request asynchronously. When true, the API returns immediately with a job ID. Set to false to wait for processing to complete before the API responds (response is still JSON).
storagebooleantrueStore the generated file in cloudlayer.io storage. When true, the file is accessible via the Assets endpoint. Requires a plan that supports storage.

Base Parameters (all generation endpoints)

ParameterTypeDescription
autoScrollbooleanScroll the page to trigger lazy-loaded content before capture.
delaynumberWait time in milliseconds after the page loads before capturing.
filenamestringSet the Content-Disposition filename for the response.
timeoutnumberMaximum time in milliseconds to wait for the page to load.
viewPortobjectConfigure the browser viewport dimensions and device emulation.
waitUntilstringWhen to consider navigation complete (load, domcontentloaded, networkidle0, networkidle2).

PDF-Specific Parameters

ParameterTypeDescription
formatstringPage size (letter, legal, tabloid, a0-a6, etc.).
marginobjectPage margins with unit support (px, in, cm, mm).
landscapebooleanUse landscape orientation.
printBackgroundbooleanInclude background colors and images.
headerTemplateobjectCustom header for each page.
footerTemplateobjectCustom footer for each page.

Image-Specific Parameters

ParameterTypeDescription
imageTypestringOutput format: png, jpg, jpeg, webp, or svg.
transparentbooleanRender with a transparent background (PNG and WebP only).
trimbooleanTrim whitespace from the edges of the image.

List Results

List endpoints (GET /jobs, GET /assets) return the 10 most recent items, ordered by creation date (newest first). There are no pagination query parameters.


Next Steps