Developer API

A REST API for server-side image compression — for automation, backends, and pipelines. This is a separate product from the free browser tool above: requests here are processed on our servers (in memory, never persisted to disk), gated by an API key tied to your plan. Get a key from the dashboard.

Select language

Installation

No installation needed — call the REST endpoint directly with any HTTP client.

Authentication

Pass your API key as a bearer token on every request:

Authorization: Bearer webpninja_live_<your_key>
Setting the Authorization header with a Bearer API key in Postman

Compress an image

POST /api/v1/compress — multipart form upload. Returns the compressed image bytes with the matching Content-Type.

Field Description
file The image to compress (multipart file field). Any format sharp can decode.
format Output format: webp, jpeg, png, or avif.
quality 10–100, default 80. Same compression settings as the browser tool at the same quality.
curl -X POST https://api.webpninja.com/api/v1/compress \
  -H "Authorization: Bearer webpninja_live_your_key" \
  -F "file=@photo.png" \
  -F "format=webp" \
  -F "quality=75" \
  --output photo.webp
Setting the file, format, and quality form-data fields in Postman

Quotas & rate limits

Free includes 15 compressions per day, resetting at midnight UTC, at up to 15 requests/min. Starter and Pro have no compression quota — unlimited compressions, at up to 60 and 120 requests/min respectively. Exceeding a quota or rate limit returns 429 Too Many Requests. See your current plan and usage on the dashboard.

Upload size limits

Each plan also caps the size of a single image: Free — 15 MB, Starter — 33 MB, Pro — 200 MB. A file over your plan's limit returns 413 Payload Too Large.

Errors

Status Meaning
400 Missing file, or an invalid format/quality value.
401 Missing, invalid, or revoked API key.
422 The file couldn't be decoded or compressed.
413 File exceeds your plan's upload size limit. Includes maxUploadMb, fileSizeMb and, when a plan allows a file that size, an upgrade object.
429 Daily quota (Free plan) or rate limit exceeded. Quota errors include quota, used, resetsAt (ISO timestamp) and an upgrade object.

Every error body has a human-readable error message. Plan-limit errors also include an upgrade object naming the cheapest plan that removes the limit, so your app can show its own upgrade prompt:

HTTP/1.1 413 Payload Too Large

{
  "error": "This file (17.84 MB) exceeds the 15 MB per-image limit of your Free plan. Upgrade to the Starter plan to compress images up to 33 MB: https://webpninja.com/pricing",
  "maxUploadMb": 15,
  "fileSizeMb": 17.84,
  "upgrade": {
    "plan": "starter",
    "name": "Starter",
    "priceInr": 299,
    "maxUploadMb": 33,
    "unlimitedCompressions": true,
    "url": "https://webpninja.com/pricing"
  }
}