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:
| Scenario | Content-Type |
|---|---|
| JSON body (most endpoints) | application/json |
| Multipart form data (template uploads) | multipart/form-data |
| GET requests | No Content-Type needed |
Response content types depend on the endpoint:
| Scenario | Response Content-Type |
|---|---|
| Document generation | application/pdf, image/png, image/jpeg, or image/webp |
| Account, jobs, assets, storage | application/json |
All document generation responses return the raw file binary directly.
Response content types vary by endpoint and mode:
| Scenario | Response 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, storage | application/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,
storagealso defaults totrue. Whenasyncistrue(the default), the generated file is automatically stored and accessible via the Assets endpoint. You can set"storage": falseto disable storage, but this requires"async": falseas 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.
| Header | Description |
|---|---|
X-RateLimit-Limit | Maximum requests allowed in the current window |
X-RateLimit-Remaining | Requests remaining in the current window |
X-RateLimit-Reset | Unix 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
| Code | Meaning | Description |
|---|---|---|
200 | OK | Request succeeded. Response body contains the result. |
201 | Created | Resource created successfully (e.g., storage configuration). |
202 | Accepted | Request accepted for asynchronous processing (v2 async mode). |
400 | Bad Request | The request body is malformed or missing required parameters. |
401 | Unauthorized | Missing or invalid API key. |
402 | Payment Required | Your account has exceeded its usage limits or has an unpaid balance. |
403 | Forbidden | Your API key does not have permission for this action. |
404 | Not Found | The requested resource does not exist. |
422 | Unprocessable Entity | The request is well-formed but contains invalid parameter values. |
429 | Too Many Requests | Rate limit exceeded. Retry after the X-RateLimit-Reset time. |
500 | Internal Server Error | Something went wrong on our end. Contact support if it persists. |
502 | Bad Gateway | Temporary upstream issue. Retry with exponential backoff. |
504 | Gateway Timeout | The 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"
}
}
}
| Field | Type | Description |
|---|---|---|
error.code | string | A machine-readable error code (e.g., INVALID_PARAMETER, RATE_LIMIT_EXCEEDED). |
error.message | string | A human-readable description of the error. |
error.details | object | Additional 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)
| Parameter | Type | Default | Description |
|---|---|---|---|
async | boolean | true | Process 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. |
storage | boolean | true | Store 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)
| Parameter | Type | Description |
|---|---|---|
autoScroll | boolean | Scroll the page to trigger lazy-loaded content before capture. |
delay | number | Wait time in milliseconds after the page loads before capturing. |
filename | string | Set the Content-Disposition filename for the response. |
timeout | number | Maximum time in milliseconds to wait for the page to load. |
viewPort | object | Configure the browser viewport dimensions and device emulation. |
waitUntil | string | When to consider navigation complete (load, domcontentloaded, networkidle0, networkidle2). |
PDF-Specific Parameters
| Parameter | Type | Description |
|---|---|---|
format | string | Page size (letter, legal, tabloid, a0-a6, etc.). |
margin | object | Page margins with unit support (px, in, cm, mm). |
landscape | boolean | Use landscape orientation. |
printBackground | boolean | Include background colors and images. |
headerTemplate | object | Custom header for each page. |
footerTemplate | object | Custom footer for each page. |
Image-Specific Parameters
| Parameter | Type | Description |
|---|---|---|
imageType | string | Output format: png, jpg, or webp. |
transparent | boolean | Render with a transparent background (PNG and WebP only). |
trim | boolean | Trim 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:
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | number | 25 | Number of items to return (max 100). |
offset | number | 0 | Number of items to skip. |
Next Steps
- HTML to PDF — Generate PDFs from raw HTML
- URL to PDF — Capture any web page as a PDF
- Template to PDF — Generate PDFs from reusable templates
- HTML to Image — Generate images from raw HTML
- URL to Image — Capture any web page as an image
- Template to Image — Generate images from reusable templates