← Home

Compress PDF API

Compress PDF files from your own code, scripts and automations. One HTTPS request in, a smaller PDF out. Free plan with an API key.

Get started: get a free API key (email sign-in, no password) · API reference · OpenAPI spec · source code on GitHub

How this differs from our website tools: the free tools on editpdf.tools run in your browser and never upload your files. The API is different by design: your PDF is sent over HTTPS to our processing server, compressed, returned in the same response, and deleted right after. Details are in the API terms and data handling.

Quick start

Send the PDF as multipart/form-data with your key in the X-API-Key header. The response body is the compressed PDF.

curl -X POST https://api.editpdf.tools/v1/compress \
  -H "X-API-Key: YOUR_KEY" \
  -F "file=@input.pdf" \
  -F "level=recommended" \
  -o compressed.pdf

Python

import requests

with open("input.pdf", "rb") as f:
    r = requests.post(
        "https://api.editpdf.tools/v1/compress",
        headers={"X-API-Key": "YOUR_KEY"},
        files={"file": ("input.pdf", f, "application/pdf")},
        data={"level": "recommended"},
        timeout=180,
    )

if r.status_code == 200:
    open("compressed.pdf", "wb").write(r.content)
    print(r.headers["X-Original-Size"], "->", r.headers["X-Compressed-Size"])
else:
    print(r.status_code, r.json())

Node.js (18 or newer)

import { readFile, writeFile } from "node:fs/promises";

const form = new FormData();
form.append("file", new Blob([await readFile("input.pdf")], { type: "application/pdf" }), "input.pdf");
form.append("level", "recommended");

const res = await fetch("https://api.editpdf.tools/v1/compress", {
  method: "POST",
  headers: { "X-API-Key": process.env.EDITPDF_API_KEY },
  body: form,
});

if (res.ok) await writeFile("compressed.pdf", Buffer.from(await res.arrayBuffer()));
else console.error(res.status, await res.json());

Endpoints

POST /v1/compress

FieldWhereDetails
X-API-KeyHeaderRequired. Authorization: Bearer YOUR_KEY also works.
fileForm fieldRequired. One PDF file.
levelForm field or queryOptional. light, recommended (default) or strong.

A successful call returns 200 with the PDF (application/pdf) and these headers:

  • X-Original-Size and X-Compressed-Size: sizes in bytes.
  • X-Compressed: false means compression did not make the file smaller, so you get your original file back unchanged.
  • X-Level: the level used. X-Quota-Remaining: files left this month.

GET /v1/me

Checks your key and returns your current limits and usage, for example:

{"email":"you@example.com","month":"2026-11","files_used":3,"monthly_quota":30,
 "files_remaining":27,"max_file_mb":10,"seconds_between_files":60}

Compression levels

LevelImages are resampled toUse it for
light300 dpiPrint quality, smallest change
recommended150 dpiEmail, uploads and forms (default)
strong72 dpiSmallest file, screen viewing only

Scanned and photo-heavy PDFs shrink the most. Text-only or already optimized PDFs may not get smaller; in that case the original is returned.

Limits (free plan)

LimitValue
Max file size10 MB
Files per month30 (resets on the 1st, UTC)
Rate1 file per minute
InputPDF only. Password-protected PDFs are not supported.

Processing time. Most text PDFs finish in a few seconds. Scanned or image-heavy PDFs close to 10 MB can take up to about 2 minutes on the free plan, so set your HTTP client timeout to at least 180 seconds. If the service has been idle it may also need up to a minute to start; in that case retry after the time in the Retry-After header.

Errors

Errors are JSON, for example {"error":"file_too_large","max_mb":10,"message":"File must be 10 MB or smaller on your plan."}

StatuserrorWhat to do
400missing_file, bad_levelSend the PDF in the file field; use a valid level.
401invalid_api_keyCheck the key, or create a new one in your dashboard.
403account_blockedContact support.
411content_length_requiredSend a normal upload with a Content-Length header.
413file_too_largeUse a file within max_mb.
415use_multipart_form_data, not_a_pdfSend multipart/form-data with a real PDF.
422pdf_is_password_protected, could_not_read_pdf, could_not_process_pdfRemove the password or repair the PDF, then try again.
429rate_limited, monthly_quota_reachedWait retry_after_seconds, or until next month.
503service_starting_retry_in_60s, processing_timeout, service_capacity_reached_this_month, temporarily_unavailableRetry later. A timeout usually means the file is too heavy; try strong or a smaller file.

Your files and data

  • Files travel over HTTPS, are compressed with Ghostscript and are deleted as soon as the response is sent. We do not keep copies.
  • We store your email, a hash of your API key and monthly usage counts. We never store the key itself.
  • Full details: API terms and data handling.

Open source

The API code is public under the AGPL-3.0 license: github.com/chanbuilsdai/compress-pdf-api. Compression uses the unmodified Ghostscript program by Artifex Software (AGPL) and qpdf (Apache-2.0) for file checks.

Support

Questions or a higher limit for a project? Use the contact form or email support@editpdf.tools. Prefer no code? Our Compress PDF tool works in your browser without uploading the file.

© 2026 editpdf.tools™. All rights reserved.