apyhub
Back
▣ INGESTION KIT · MEDIA KIT

Compress Image to Target Size API

What it does

Image Compressor reduces the size of an uploaded image and returns the compressed file as binary output. Send a JPEG, PNG, WebP, AVIF, TIFF, or GIF up to 10 MB and 40 megapixels, and choose whether to keep the original format or convert it to jpg, png, webp, or avif.

Use quality to set the compression level from 1 to 100, with 75 as the default. If you need a specific file size, target_kb lets you aim for a maximum size in KB for jpg, webp, and avif outputs. That makes it useful when you need to stay under upload limits, speed up image delivery, or reduce storage costs without changing your upload flow.

Because the response is binary, you can pass the result straight into your storage, CDN, or document pipeline. Image Compressor is a good fit for thumbnail generation, user-upload optimisation, and preparing image assets for web and mobile apps.

POST
Compress Image
https://api.eu.apyhub.com/frolic/compress-image-to-target-size/image/compress

QUICKSTART

GUIDE

Quickstart

Upload an image to convert it to another format.

curl -X POST "https://api.eu.apyhub.com/frolic/compress-image-to-target-size/image/compress" \
  -H "apy-token: $APY_TOKEN" \
  -F "file=@/path/to/image.jpg"

What you'll get back

Returns a binary file (string with format: binary) containing the converted image.

TRY ITLIVE · 10 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.
body
Image (max 10 MB, 40 megapixels): JPEG, PNG, WebP, AVIF, TIFF or GIF
Output format: jpg, png, webp or avif (default: same as the input)
1-100 (default 75)
Largest acceptable size in KB (5-10240), for jpg, webp and avif

About this endpoint

What it does

Compresses an uploaded image file and returns the compressed image as binary output. You can optionally choose the output format, quality, or a target maximum size in KB.

Request Body

ParameterTypeMandatoryDescription
fileStringYesImage file to compress. Accepted input formats: JPEG, PNG, WebP, AVIF, TIFF, or GIF. Maximum size: 10 MB; maximum resolution: 40 megapixels.
toENUMNoOutput format. Allowed values: jpg, png, webp, avif. Default: same as the input format.
qualityIntegerNoCompression quality from 1 to 100. Default: 75.
target_kbIntegerNoLargest acceptable output size in KB. Allowed range: 5 to 10240. Supported for jpg, webp, and avif.

Response

Returns a binary file containing the compressed image.

Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.

▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.