---
title: Compress Image to Target Size API
slug: compress-image-to-target-size
url: https://apyhub.com/frolic/service/compress-image-to-target-size
provider: Hakimi Labs
categories: [Ingestion Kit, Media Kit]
tags: [image-compression, media-processing, file-optimization, webp, avif]
auth: api_key
version: 1.0
service_type: sync
endpoints: 1
atoms: 10
mcp: true
---

# Compress Image to Target Size API

Compress uploaded images and return the binary file. Control output format, quality, or target size for faster uploads and smaller assets.

## Endpoints

| Method | URL | Description | Atoms |
| --- | --- | --- | --- |
| POST | `https://api.eu.apyhub.com/frolic/compress-image-to-target-size/image/compress` | What it does Compresses an uploaded image file and returns the compressed image as binary output. Y… | 10 |

## Endpoint reference

### Compress Image

`POST https://api.eu.apyhub.com/frolic/compress-image-to-target-size/image/compress` · 10 atoms · accepts `multipart/form-data` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `to` | body | string | no | Output format: jpg, png, webp or avif (default: same as the input) One of: jpg, png, webp, avif. |
| `file` | body | string (binary) | yes | Image (max 10 MB, 40 megapixels): JPEG, PNG, WebP, AVIF, TIFF or GIF |
| `quality` | body | integer (int32) | no | 1-100 (default 75) |
| `target_kb` | body | integer (int32) | no | Largest acceptable size in KB (5-10240), for jpg, webp and avif Example: `200`. |

#### Quickstart

Upload an image to convert it to another format.

```bash
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.

## About

## 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.

## Usage

Base URL: `https://api.eu.apyhub.com` (default region — see
`GET https://apyhub.com/api/public/regions` for the rest).

Authenticate with an ApyHub API key in the `apy-token` header.
Full docs and a live playground: https://apyhub.com/frolic/service/compress-image-to-target-size
