Reimply API
Optimize image API
Shrink an image to an exact byte cap, such as 100 KB, by searching quality and size. If the cap cannot be reached, the job returns 422 target_unreachable with the smallest size achieved, and nothing is charged.
Example
Endpoint POST /v1/optimize. Options used here: max_bytes, format.
curl https://reimply.com/v1/optimize \
-H "Authorization: Bearer $REIMPLY_API_KEY" \
-H "Accept: application/octet-stream" \
-F "file=@photo.jpg" \
-F 'options={"max_bytes":100000,"format":"jpg"}' \
-o resultimport { readFile, writeFile } from 'node:fs/promises'
const form = new FormData()
form.append('file', new Blob([await readFile('photo.jpg')]), 'photo.jpg')
form.append('options', JSON.stringify({"max_bytes":100000,"format":"jpg"}))
const res = await fetch('https://reimply.com/v1/optimize', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.REIMPLY_API_KEY}` },
body: form,
})
const job = await res.json()
if (!res.ok) throw new Error(job.error.message)
for (const o of job.outputs) {
const file = await fetch(o.url)
await writeFile(o.name, Buffer.from(await file.arrayBuffer()))
}
console.log(job.id, 'used', job.credits.charged, 'credit(s)')import os, requests
with open("photo.jpg", "rb") as f:
res = requests.post(
"https://reimply.com/v1/optimize",
headers={"Authorization": f"Bearer {os.environ['REIMPLY_API_KEY']}"},
files={"file": f},
data={"options": '{"max_bytes":100000,"format":"jpg"}'},
)
job = res.json()
res.raise_for_status()
for o in job["outputs"]:
with open(o["name"], "wb") as out:
out.write(requests.get(o["url"]).content)
print(job["id"], "used", job["credits"]["charged"], "credit(s)")Files over 4 MB: create a presigned upload first and pass its upload_id, and the job runs in the background with an optional webhook.
Use cases
- Profile photos with a hard size cap
- Attachments that must stay under a form limit
- Keep image uploads inside a storage budget
Pricing
This job uses 1 conversion. Free accounts get 250 conversions a month, and paid plans start at £12 a month for 3,000. Pricing.
Questions
How many conversions does a Optimize image job use?
One conversion per file, whatever the size. Video and audio jobs use 3. Failed jobs are free.
What if the target size cannot be reached?
The job fails with 422 target_unreachable. The error includes the smallest size achieved (bytes_achieved) and nothing is charged.
Can I try it for free?
Yes. Every account gets 250 free conversions a month, no card needed. Create a key in your account and run the sample above.
What happens to my files?
Files are processed on Reimply servers and deleted automatically 60 minutes after the job, along with the results.
Just need to do this once? Use the free Optimize image tool on reimply.com.