Skip to main content

How to Avoid Timeout Errors When Merging a Large Number of PDFs

Updated over 2 weeks ago

When merging a very large number of PDF files using the PDF Merge API (/v1/pdf/merge), you may encounter a timeout error — even when using asynchronous mode.

This behavior is expected due to processing time limits and how serverless infrastructure handles long-running tasks.


Why Timeouts Occur

PDF.co uses Lambda-based compute for processing. This means:

  • Synchronous requests have a strict limit of 30 seconds

  • Asynchronous requests have a maximum processing time of 3 minutes

If your merge operation requires more than these limits — which often happens when merging hundreds of PDFs — the job may:

  • Time out

  • Fail with a processing error

This is especially common when merging large files in a single request.


Recommended Workaround: Merge in Batches

To reliably handle large merges, we strongly recommend splitting the operation into smaller batches.

Suggested batching strategy:

  1. Group PDFs into batches of ~150–200 files each

  2. Merge each batch separately using /v1/pdf/merge

  3. Take the few resulting merged PDFs (e.g., 3 or 4 final files)

  4. Run one last merge to combine those batch outputs into the final single PDF


Why This Works

Batch merging:

  • Keeps each merge task well below the time limits

  • Prevents long-running operations from timing out

  • Reduces server load and speeds up processing

  • Offers much more predictable and stable performance

  • Works reliably even for workflows requiring 500–1,000 PDFs


Example Workflow

Batch 1: merge PDFs 1–200 → result batch1.pdf
Batch 2: merge PDFs 201–400 → result batch2.pdf
Batch 3: merge PDFs 401–542 → result batch3.pdf

Final merge: batch1.pdf + batch2.pdf + batch3.pdf → final_output.pdf

Need Further Help?

If you're unsure how to structure your batching logic, or if you need help optimizing your workflow in Make, Zapier, n8n, or custom code — feel free to reach out and we’ll be glad to assist.

Did this answer your question?