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.

Response content types vary by endpoint and mode:

ScenarioResponse Content-Type
Document generation (async — default)application/json (job details)
Document generation (sync, async: false)application/pdf, image/png, image/jpeg, or image/webp
Account, jobs, assets, storageapplication/json

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": "job_abc123",
  "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 response body will be the raw generated file (PDF or image):

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}' \
  --output result.pdf

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

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

Rate limits depend on your subscription plan. When you exceed your rate limit, the API returns a 429 Too Many Requests response.

HeaderDescription
X-RateLimit-LimitMaximum requests allowed in the current window
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp when the rate limit window resets

Best practice: Check the X-RateLimit-Remaining header and implement backoff logic before hitting the limit.


HTTP Status Codes

CodeMeaningDescription
200OKRequest succeeded. Response body contains the result.
201CreatedResource created successfully (e.g., storage configuration).
202AcceptedRequest accepted for asynchronous processing (v2 async mode).
400Bad RequestThe request body is malformed or missing required parameters.
401UnauthorizedMissing or invalid API key.
402Payment RequiredYour account has exceeded its usage limits or has an unpaid balance.
403ForbiddenYour API key does not have permission for this action.
404Not FoundThe requested resource does not exist.
422Unprocessable EntityThe request is well-formed but contains invalid parameter values.
429Too Many RequestsRate limit exceeded. Retry after the X-RateLimit-Reset time.
500Internal Server ErrorSomething went wrong on our end. Contact support if it persists.
502Bad GatewayTemporary upstream issue. Retry with exponential backoff.
504Gateway TimeoutThe request took too long to process. Consider increasing the timeout parameter or simplifying your content.

Error Response Format

When an error occurs, the API returns a JSON body with details:

{
  "error": {
    "code": "INVALID_PARAMETER",
    "message": "The 'html' field is required and must be a base64-encoded string.",
    "details": {
      "field": "html",
      "reason": "missing"
    }
  }
}
FieldTypeDescription
error.codestringA machine-readable error code (e.g., INVALID_PARAMETER, RATE_LIMIT_EXCEEDED).
error.messagestringA human-readable description of the error.
error.detailsobjectAdditional context about the error (varies by error type).

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 receive the generated file directly in the response.
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, or webp.
transparentbooleanRender with a transparent background (PNG and WebP only).
trimbooleanTrim whitespace from the edges of the image.

Pagination

List endpoints (GET /v1/jobs, GET /v1/assets) return paginated results. Use standard pagination query parameters:

List endpoints (GET /v2/jobs, GET /v2/assets) return paginated results. Use standard pagination query parameters:

ParameterTypeDefaultDescription
limitnumber25Number of items to return (max 100).
offsetnumber0Number of items to skip.

Next Steps