Image compression API tutorial

MiniPic offers an image compression API that is compatible with the HTTP Basic / Bearer auth and response shape of popular compression services, so in most cases you can migrate from TinyPNG and similar services just by swapping the API endpoint and key. Our in-house engine shrinks PNG, JPEG and WebP by 60% on average with no visible quality loss, there is a free monthly quota, and you are only billed for successful compressions. For the full endpoint reference, see the developer docs (minipic.cn/docs).

Why choose the MiniPic image compression API

Integrate in 3 steps

Step 1: create an API key in the console

Sign in to the MiniPic console and go to API key management to create a key. Keys are prefixed mp_live_ (production) / mp_test_ (sandbox); the full key is shown only once at creation, so store it safely.

Step 2: send your first compression request

Use HTTP Basic auth (username is always api, password is your key) to compress an image:

# Compress a PNG (Basic auth, user is always api) curl -s --user api:YOUR_API_KEY \ --data-binary @input.png \ -o output.png \ https://api.minipic.cn/v1/compress

Step 3: get and download the result

The compatibility endpoint /shrink returns 201 Created, with the result served over an encrypted private link that only you (the key holder) can access; the native /v1/compress endpoint returns the compressed binary directly. Re-downloading the same result is not billed.

Node.js example

// Node.js (>=18, built-in fetch): read a local image and compress it import { readFile, writeFile } from "node:fs/promises"; const key = process.env.MINIPIC_API_KEY; const auth = "Basic " + Buffer.from("api:" + key).toString("base64"); const res = await fetch("https://api.minipic.cn/v1/compress?quality=smart&format=keep", { method: "POST", headers: { Authorization: auth }, body: await readFile("input.png"), }); await writeFile("output.png", Buffer.from(await res.arrayBuffer())); console.log("Compressed, saved", res.headers.get("X-Ratio"));

Python example

# Python (requests): read a local image and compress it import os, requests key = os.environ["MINIPIC_API_KEY"] with open("input.jpg", "rb") as f: res = requests.post( "https://api.minipic.cn/v1/compress", params={"quality": "smart", "format": "keep"}, auth=("api", key), data=f.read(), ) with open("output.jpg", "wb") as out: out.write(res.content) print("Compressed, saved", res.headers.get("X-Ratio"))

Migrating from the TinyPNG API

MiniPic is compatible with the auth and response shape of popular compression services, so in most cases you can migrate from TinyPNG and similar services just by swapping the API endpoint and key, with no changes to your application code. Point the base URL at MiniPic (minipic.cn), swap in your MiniPic API key, and start compressing.

Quota, rate limits and billing

For the full endpoint reference and error-code table, see the developer docs; for the pricing tiers, see the pricing page; for billing details, see billing.

Frequently asked questions

How do I integrate the MiniPic image compression API?

Create an API key in the MiniPic console, then send your request to the compression endpoint using HTTP Basic auth (username api, password your key) or a Bearer token. The API is compatible with the auth and response shape of popular compression services, so in most cases you only need to swap the endpoint and the key.

Is the MiniPic image compression API free?

There is a free monthly quota that resets on the first day of each month. Beyond that, usage is billed per successfully compressed image at tiered rates. You are only charged for successful compressions — failures, oversized files and blocked requests are never billed.

Can I migrate from the TinyPNG API to MiniPic?

Yes. The MiniPic /shrink endpoint is compatible with the auth and response shape of popular compression services, so in most cases you can migrate by changing the API endpoint and key, with no changes to your application code.

Integrate in 3 steps, with a free monthly quota

Create an API key, then swap endpoint and key to start compressing.