REST API
Call imgcompress from your app or scripts: convert, compress, edit, upscale and remove backgrounds on your own server via /api/v1. Same features as the web UI, with Swagger docs on your instance.
Call imgcompress from your app or scripts: convert, compress, edit, upscale and remove backgrounds on your own server via /api/v1. Same features as the web UI, with Swagger docs on your instance.
The web UI is just one client of /api/v1. Everything you can do in the browser, a script, a CMS or a blog plugin can do too: convert and compress 70+ formats, edit images, remove backgrounds and upscale with the built-in AI. Files stay in your container. Nothing is sent to a cloud.
For everyday use, prefer the web UI. This page covers setup. Every endpoint, field, range and error code is in the API Reference, generated from the OpenAPI document of 1.1.0-rc.6.
Only format is required. Every other option is off until you send it.
The public API is off by default. Existing installs do not change until you turn it on. To try the Open Beta, pin the release-candidate image and set the flags below.
In the root docker-compose.yml the container variables are unprefixed:
yamlservices: imgcompress: image: karimz1/imgcompress:1.1.0-rc.6 container_name: imgcompress restart: always ports: - "3001:5000" environment: - ENABLE_PUBLIC_API=true - PUBLIC_API_KEY=paste-a-long-random-string-here
Then:
bashdocker compose up -d
Pick a long random key, for example with openssl rand -hex 32. Do not commit it to a public repository.
Then call the API at http://localhost:3001 (leave out the Authorization line when no key is set):
bashcurl -fsS http://localhost:3001/api/v1/convert \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -F "files[]=@photo.jpg" -F format=webp -F quality=80 -F width=1600 \ -o photo.webp
Swagger UI is at http://localhost:3001/api/v1/docs.
A reverse proxy adds your own domain, but the quick start is for easy local use. Behind a proxy, set PUBLIC_BASE_URL to that address (for example https://imgcompress.example.com) and, for a public host, API_ONLY=true.
PUBLIC_BASE_URL is optional and is also used for notification share links; see the box at the top for how it changes Swagger and the curl examples.
The key is only a real login when the web UI is not served.
| Mode | Settings | Who can call /api/v1 |
|---|---|---|
| Default | Web UI on, ENABLE_PUBLIC_API off | Scripts on your network work. A browser request from another website gets 403 (CSRF defense). Swagger answers 404. No CORS. |
| Web UI + public API | ENABLE_PUBLIC_API=true, optional PUBLIC_API_KEY | Other websites may call the API (CORS, no cookies). Swagger is served. If a key is set, callers that are not the web UI must send it. The key is not a security boundary while the web UI is served: anyone who can open the UI can do the same. |
| API only | API_ONLY=true and a PUBLIC_API_KEY | The web UI is not served. Every /api/v1 call except health checks needs the key. This is a real boundary. The container will not start without a key. |
Public hosting: use API_ONLY plus a key, or put a login in front of the whole instance with your reverse proxy (Authelia, Authentik, or Basic Auth). For LAN use, mode 2 is usually enough. See also Production setup.
With a key set, send it as Authorization: Bearer <key> or X-API-Key: <key>. Without a key, leave the header out. Health checks and the Swagger pages never need it.
The examples below use the placeholder https://imgcompress.example.com. Replace it with your own address. Leave out the Authorization line when no key is set. Every step links to its endpoint in the API Reference.
What has to happen before each call. A job token comes only from POST /jobs or POST /jobs/{job_id}/claim; nothing else returns one. Tokens and ids are always used in full, exactly as the server returned them.
| Step | Call | Needs before | You get |
|---|---|---|---|
| 1 | POST /jobs | API key if one is set | 202 with id and token (shown only once) |
| 2 | GET /jobs/{job_id} | id and token from step 1, sent as X-Job-Token | status, progress; repeat every 1 to 2 seconds until done, failed or canceled |
| 3 | GET /jobs/{job_id}/files/{file_name} or GET /jobs/{job_id}/zip | status is done; file names from result.converted_files; same X-Job-Token | The file or a ZIP of all files |
| Optional | POST /jobs/{job_id}/notify | Job from step 1, X-Job-Token, NOTIFY_URL on the container | A push message with a /r/{job_id}/{share_token} link when the job ends |
| Optional | POST /jobs/{job_id}/claim | The share_token from that notification link, in the JSON body; never the job token | A new token for this device, used as X-Job-Token in steps 2 and 3 |
POST /convert and POST /edit need no job and no token: they answer directly.
Send the image and get the result in the answer with POST /convert. Several files come back as a ZIP.
bashcurl -fsS https://imgcompress.example.com/api/v1/convert \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -F "files[]=@photo.jpg" -F format=webp -F quality=80 -F width=1600 \ -o photo.webp
For AI upscaling, big batches, or anything that should survive a dropped connection.
Start the job with POST /jobs. It answers 202 with id and token. Keep both: the token is shown only once.
bashcurl -fsS https://imgcompress.example.com/api/v1/jobs \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -F "files[]=@small.png" -F format=png -F upscale=4x -F upscale_model=general # {"id":"ONxhNOQQ_I29XWiYuStLpA","token":"4tWCrC7EjooiC2SJJRpAvextegjFyTBFk5ajxCdBAos","status":"queued","progress":{"files_done":0,"files_total":1},"device":"Linux · curl","created_at":1763559000,"updated_at":1763559000,"server_time":1763559000.1}
Poll GET /jobs/{job_id} with the token in X-Job-Token every 1 to 2 seconds until status is done, failed or canceled. With done, result.converted_files lists the file names.
bashcurl -fsS https://imgcompress.example.com/api/v1/jobs/ONxhNOQQ_I29XWiYuStLpA \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -H "X-Job-Token: 4tWCrC7EjooiC2SJJRpAvextegjFyTBFk5ajxCdBAos"
Download one file with GET /jobs/{job_id}/files/{file_name}, or everything as a ZIP with GET /jobs/{job_id}/zip. Results are kept for 48 hours after the last access.
bashcurl -fsS https://imgcompress.example.com/api/v1/jobs/ONxhNOQQ_I29XWiYuStLpA/files/small.png \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -H "X-Job-Token: 4tWCrC7EjooiC2SJJRpAvextegjFyTBFk5ajxCdBAos" \ -o small.png curl -fsS https://imgcompress.example.com/api/v1/jobs/ONxhNOQQ_I29XWiYuStLpA/zip \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -H "X-Job-Token: 4tWCrC7EjooiC2SJJRpAvextegjFyTBFk5ajxCdBAos" \ -o results.zip
Optional: stop a running job with POST /jobs/{job_id}/cancel, or get a push message when it ends with POST /jobs/{job_id}/notify. Notify needs NOTIFY_URL on the container and answers 409 without it.
bashcurl -fsS -X POST https://imgcompress.example.com/api/v1/jobs/ONxhNOQQ_I29XWiYuStLpA/cancel \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -H "X-Job-Token: 4tWCrC7EjooiC2SJJRpAvextegjFyTBFk5ajxCdBAos" curl -fsS https://imgcompress.example.com/api/v1/jobs/ONxhNOQQ_I29XWiYuStLpA/notify \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -H "X-Job-Token: 4tWCrC7EjooiC2SJJRpAvextegjFyTBFk5ajxCdBAos" \ -H "Content-Type: application/json" \ -d '{"enabled": true, "language": "en"}'
With PUBLIC_BASE_URL set, the push message links to /r/{job_id}/{share_token} on your instance, for example:
texthttps://imgcompress.example.com/r/ONxhNOQQ_I29XWiYuStLpA/_jnqIyvSvFIRLYTbkRdWPclwAI9Lk6L0etL15lLYHGA
Trade the share token for a new job token of your device with POST /jobs/{job_id}/claim. Send the share token from the link in the body, not the job token.
bashcurl -fsS https://imgcompress.example.com/api/v1/jobs/ONxhNOQQ_I29XWiYuStLpA/claim \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{"share_token": "_jnqIyvSvFIRLYTbkRdWPclwAI9Lk6L0etL15lLYHGA"}' # {"id":"ONxhNOQQ_I29XWiYuStLpA","token":"KzzmGKeD-gUMS0rnC5xoYIA1V8xWVd46k82apvmgDqQ"}
Use the new token as X-Job-Token for polling and downloads, as in the background job steps above.
Optional: upload each picture for layers or a background once with POST /editor/assets. Keep session and asset.
bashcurl -fsS https://imgcompress.example.com/api/v1/editor/assets \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -F "file=@logo.png" # {"session":"Em2EkUr3Vs9v7XaHu6rcBgHuzUADFzni","asset":"asesAGzGGNBlXd3Qv05qxA","width":800,"height":600}
Render the image with POST /edit. render=true returns the full-size PNG; send it to POST /convert for another format.
bashcurl -fsS https://imgcompress.example.com/api/v1/edit \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -F "file=@photo.jpg" -F fit_width=1080 -F fit_height=1080 -F fit_mode=blur \ -F fit_session=Em2EkUr3Vs9v7XaHu6rcBgHuzUADFzni \ -F 'fit_layers=[{"type":"image","asset":"asesAGzGGNBlXd3Qv05qxA","x":0.85,"y":0.88,"width":0.2}]' \ -F render=true \ -o post.png
Storage routes see the files of every user of the container and answer 403 with DISABLE_STORAGE_MANAGEMENT=true.
List result files with GET /storage/files, then download one with GET /storage/files/download using its folder_path and filename (pass folder_path as folder and filename as file).
bashcurl -fsS https://imgcompress.example.com/api/v1/storage/files \ -H "Authorization: Bearer $PUBLIC_API_KEY" curl -fsS -G https://imgcompress.example.com/api/v1/storage/files/download \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ --data-urlencode "folder=/tmp/converted_k3x9q2mf" \ --data-urlencode "file=photo.webp" \ -o photo.webp
Free space with POST /storage/cleanup. Running jobs are kept.
bashcurl -fsS -X POST https://imgcompress.example.com/api/v1/storage/cleanup \ -H "Authorization: Bearer $PUBLIC_API_KEY"
The API Reference on this site lists every endpoint with parameters, ranges, responses and error codes, plus an interactive view. On your container, open Swagger UI at /api/v1/docs (see the box at the top).
/api/v1 is stable and only grows: new routes, new optional fields and new fields in answers may appear in any release. Nothing in v1 is renamed, removed or made stricter. A breaking change gets /api/v2, served next to v1 for at least one release. GET /api/health/backend is a deprecated alias of GET /api/v1/health and goes away in 2.0.