Batch Generate PDFs
Generate multiple PDFs in a single API request for improved efficiency
Overview
The batch generate endpoint allows you to create multiple PDFs in a single API call. This is significantly more efficient than making individual requests, reducing overhead and improving throughput.
Performance tip: Batch generation uses promise pipelining internally to process PDFs in parallel, achieving up to 10x faster processing compared to sequential individual requests.
Endpoint
POSThttps://api.speedstein.com/v1/pdf/batch
Authentication
This endpoint requires API key authentication via the Authorization header.
Authorization: Bearer YOUR_API_KEY
Request Body
{
"pdfs": [
{
"html": "<html>...</html>",
"options": {
"format": "A4",
"orientation": "portrait",
"margin": { "top": "1cm", "bottom": "1cm" }
},
"metadata": {
"filename": "invoice-001.pdf",
"reference_id": "inv_001"
}
},
{
"html": "<html>...</html>",
"options": { "format": "Letter" },
"metadata": {
"filename": "invoice-002.pdf",
"reference_id": "inv_002"
}
}
]
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| pdfs | array | Yes | Array of PDF generation requests (max 100) |
| pdfs[].html | string | Yes | HTML content to convert to PDF |
| pdfs[].options | object | No | PDF generation options (format, orientation, margins) |
| pdfs[].metadata | object | No | Custom metadata for tracking and identification |
Response
{
"success": true,
"results": [
{
"success": true,
"pdf_id": "pdf_1a2b3c4d",
"download_url": "https://cdn.speedstein.com/pdf_1a2b3c4d.pdf",
"pages": 5,
"size_bytes": 245760,
"metadata": {
"filename": "invoice-001.pdf",
"reference_id": "inv_001"
}
},
{
"success": true,
"pdf_id": "pdf_5e6f7g8h",
"download_url": "https://cdn.speedstein.com/pdf_5e6f7g8h.pdf",
"pages": 3,
"size_bytes": 189440,
"metadata": {
"filename": "invoice-002.pdf",
"reference_id": "inv_002"
}
}
],
"total": 2,
"successful": 2,
"failed": 0,
"processing_time_ms": 1850
}Code Examples
cURL
curl -X POST https://api.speedstein.com/v1/pdf/batch \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"pdfs": [
{
"html": "<html><body><h1>Invoice #001</h1></body></html>",
"options": { "format": "A4" },
"metadata": { "reference_id": "inv_001" }
},
{
"html": "<html><body><h1>Invoice #002</h1></body></html>",
"options": { "format": "A4" },
"metadata": { "reference_id": "inv_002" }
}
]
}'Node.js
const response = await fetch('https://api.speedstein.com/v1/pdf/batch', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.SPEEDSTEIN_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
pdfs: [
{
html: '<html><body><h1>Invoice #001</h1></body></html>',
options: { format: 'A4' },
metadata: { reference_id: 'inv_001' }
},
{
html: '<html><body><h1>Invoice #002</h1></body></html>',
options: { format: 'A4' },
metadata: { reference_id: 'inv_002' }
}
]
})
});
const result = await response.json();
console.log(`Generated ${result.successful} PDFs in ${result.processing_time_ms}ms`);Rate Limits
Batch generation requests count towards your quota based on the number of PDFs generated.
| Tier | Max PDFs per Batch | Rate Limit |
|---|---|---|
| Free | 10 PDFs | 10 requests/minute |
| Starter | 50 PDFs | 60 requests/minute |
| Pro | 100 PDFs | 300 requests/minute |
| Enterprise | Unlimited | Custom |
Error Handling
If any PDFs fail to generate, the batch request will still succeed with partial results. Check the success field for each result.
{
"success": true,
"results": [
{
"success": true,
"pdf_id": "pdf_1a2b3c4d",
"download_url": "https://cdn.speedstein.com/pdf_1a2b3c4d.pdf"
},
{
"success": false,
"error": {
"code": "INVALID_HTML",
"message": "Malformed HTML content"
}
}
],
"total": 2,
"successful": 1,
"failed": 1
}