PDFThin API
Upload PDFs, compress by size or quality, and download results via a simple REST API.
Overview
All uploads use multipart/form-data. Responses are JSON.
- Base URL: https://pdfthin.com (or your SITE_URL).
- Rate limit: RATE_LIMIT_RPM per IP (default 60/min).
- Max upload: MAX_UPLOAD_MB (default 200 MB).
- Files auto-delete after 60 hours.
- Supported inputs: PDF file; optional watermark PNG/JPG up to 5MB.
- Upload variants: single file (optimize/split) or multiple files (organize).
Server configuration
Key environment variables that affect API behavior.
- REDIS_URL: job queue and status storage.
- S3_ENDPOINT/S3_BUCKET/S3_ACCESS_KEY/S3_SECRET_KEY: object storage (optional, else local).
- Files auto-delete after 60 hours.
- RATE_LIMIT_RPM and DOWNLOAD_TOKEN_TTL_MIN.
Create job (optimize or split)
POST /api/jobs with multipart/form-data.
- mode=split ignores quality and returns parts if needed.
- When quality is set, preset/custom_mb are ignored.
- When quality_mode=smart, the API tries high-to-low quality to fit the size.
file
PDF file to process.
mode
optimize (default) or split.
preset
gmail25 | outlook20 | outlook25 | custom. Required for size targets when quality is not set.
custom_mb
Required when preset=custom. Target size in MB.
quality
screen | ebook | printer | prepress or 1-100. Not allowed for split.
quality_mode
Use "smart" to hit size target by trying quality ladder; requires preset/custom_mb.
watermark
Watermark image up to 5MB.
cURL: size preset
curl -X POST https://pdfthin.com/api/jobs -F "[email protected]" -F "preset=gmail25" -F "mode=optimize"
cURL: smart quality (size target)
curl -X POST https://pdfthin.com/api/jobs -F "[email protected]" -F "preset=custom" -F "custom_mb=12" -F "quality_mode=smart" -F "mode=optimize"
cURL: fixed quality
curl -X POST https://pdfthin.com/api/jobs -F "[email protected]" -F "quality=printer" -F "mode=optimize"
Create job (organize)
Use mode=organize to merge, rotate, delete, reorder, and split pages.
- If multiple files are uploaded they are merged in upload order.
- At least one operation or multiple files is required.
file
One or more PDF files (multiple allowed).
mode
organize.
rotate_angle
90 | 180 | 270.
rotate_pages
Page list like 1,3-5.
delete_pages
Pages to remove, e.g. 2,4,7-9.
order_pages
Explicit page order, e.g. 3,1,2.
split_after
Split after pages, e.g. 2,4,7.
watermark
Watermark image up to 5MB.
cURL: merge + rotate
curl -X POST https://pdfthin.com/api/jobs -F "[email protected]" -F "[email protected]" -F "mode=organize" -F "rotate_angle=90" -F "rotate_pages=1-2"
Check status
GET /api/jobs/{id} returns job state and result files.
- Status values: queued | processing | done | failed.
Example response
{
"id": "job-id",
"status": "done",
"progress_pct": 100,
"expires_at": "2026-01-22T11:02:51Z",
"result": {
"kind": "single",
"files": [
{
"name": "output.pdf",
"size": 503937,
"download_url": "/api/jobs/job-id/download?index=0"
}
]
}
}
Download results
GET /api/jobs/{id}/download?index=0
- Use index=0..n for multi-part outputs.
- If called without token, the API returns a redirect with a short-lived token.
- Token TTL is DOWNLOAD_TOKEN_TTL_MIN minutes.
cURL: download
curl -L "https://pdfthin.com/api/jobs/job-id/download?index=0" -o output.pdf
Delete job
DELETE /api/jobs/{id} removes stored files and status.
- Returns 204 No Content.
cURL: delete
curl -X DELETE https://pdfthin.com/api/jobs/job-id
Error codes
Errors use JSON: {"error":{"code":"...","message":"..."}}
- ERR_INVALID_FILE
- ERR_TOO_LARGE
- ERR_PASSWORD_PROTECTED
- ERR_CANNOT_FIT_SINGLE_PAGE
- ERR_TIMEOUT
- ERR_INTERNAL
- ERR_NOT_FOUND
- ERR_NOT_READY
- ERR_TOKEN_USED
- ERR_FORBIDDEN
OpenAPI (draft)
Minimal OpenAPI 3.0 snippet for quick integration.
openapi.yaml
openapi: 3.0.3
info:
title: PDFThin API
version: "1.0"
paths:
/api/jobs:
post:
summary: Create a job
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
mode:
type: string
preset:
type: string
custom_mb:
type: integer
quality:
type: string
quality_mode:
type: string
watermark:
type: string
format: binary
responses:
"202":
description: Accepted
/api/jobs/{id}:
get:
summary: Get job status
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
"200":
description: OK
delete:
summary: Delete job
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
"204":
description: No Content
/api/jobs/{id}/download:
get:
summary: Download result
parameters:
- in: path
name: id
required: true
schema:
type: string
- in: query
name: index
schema:
type: integer
responses:
"303":
description: See Other