POST /v1/imaging/image-compress

Compress an image

Aim at a quality level, or at a file size, and get told what you actually saved.

Make an image file smaller now No key, no code — 2 credits either way.

curl -X POST "$DOATHING_API/v1/imaging/image-compress" \
  -H "x-api-key: $DOATHING_KEY" \
  -H "content-type: application/json" \
  -d '{"file": {"filename": "photo.jpg", "content_type": "image/jpeg", "data_b64": "<base64>"}, "options": {"target_bytes": 200000}}'

Aim at a quality level, or at a file size, and get told what you actually saved.

Reduce image file size to a quality level or a target byte budget, reporting the achieved size.

Input

Send a file object with base64 data_b64, its content_type and a filename. Accepted types: image/png, image/jpeg, image/webp, image/gif, image/tiff.

The declared type is not trusted — the bytes are sniffed and a contradiction is rejected rather than corrected.

Response

The result carries your remaining balance alongside it, so you can track spend without a second call.

{
  "bytes_in": 2418123,
  "bytes_out": 197440,
  "saved_percent": 91.8,
  "quality": 62,
  "target_met": true,
  "request_id": "37f01edb-0163-42a1-ac51-0acaef979800",
  "credits_remaining": 96
}

Cost

2 credits per call, whether it is run from the site or from the API — the credential differs, the price does not. A new account starts with 20 credits.

A rejected request still costs a credit: the authorizer decrements before the tool validates. A call rejected for a missing or invalid key is free.

Parameters

Generated from the endpoint’s own validation, so this is exactly what it accepts. A body field goes at the top level; an option goes inside options.

NameInTypeDefaultNotes
formatoptionsstring"same"Output format, or 'same'. one of same, jpeg, webp, png, avif
target_bytesoptionsintegerAim for a file size. Quality is searched for. 1000 to 4000000
qualityoptionsinteger751 to 95. Ignored when target_bytes is given. 1 to 95