Get started
Options
One options object controls every operation; this page lists each field with its type, allowed values and default, and the two ways to send it.
The options object
Options are grouped into five sections. This is the whole object, with every field set to its default. The defaults are the defaults of the Smol Mac app.
{
"image": {
"format": "original",
"quality": 75,
"resize": { "mode": "fit", "width": 2000, "height": 2000 },
"strip_metadata": true
},
"pdf": { "quality": "medium" },
"video": {
"format": "mp4",
"codec": "h265",
"quality": "high",
"resolution": "original",
"strip_audio": false,
"slow": false,
"crf": null,
"preset": null,
"audio_quality": "high"
},
"audio": {
"format": "aac",
"quality": "high",
"channels": "stereo",
"strip_metadata": false,
"bitrate_kbps": null,
"sample_rate_hz": null
},
"convert": { "to": null, "page": 1, "dpi": 144 }
}Every field is optional. Send only the fields you want to change.
Which section is used depends on the operation and on what the file is:
| Operation | Sections read |
|---|---|
| Compress | The one section that matches the type of the file: image, pdf, video or audio. The type is detected from the content of the file, not from its name. |
| Convert | convert only. Conversion uses fixed encoder settings, described in Convert files. |
| Strip metadata | None. The operation has no options. |
Sections that do not apply are still validated, then ignored. This lets you send one options object with a mixed set of files: the image settings apply to the images, the PDF setting to the PDFs.
Sending options
As query parameters
On the direct endpoints, write each field as a query parameter. The name is the path to the field, joined with dots.
curl -X POST "https://api.smolmac.com/v1/compress?image.format=avif&image.quality=60&image.resize.width=1200" \
-H "Authorization: Bearer $SMOL_API_KEY" \
--data-binary @photo.jpg \
-o photo.avif- Booleans are written
trueorfalse. Numbers are written in decimal. to,pageanddpiare short forms ofconvert.to,convert.pageandconvert.dpi.- Two query parameters are not options.
filenamenames the file you are sending, andpresetnames a saved set of options. Every other query parameter is read as an option, so an unknown one is an error.
As JSON
On the direct endpoints, send the request as multipart/form-data with the file in a part named file and the options, as a JSON string, in a part named options.
curl -X POST "https://api.smolmac.com/v1/compress" \
-H "Authorization: Bearer $SMOL_API_KEY" \
-F "[email protected]" \
-F 'options={"image":{"format":"avif","quality":60,"resize":{"width":1200}}}' \
-o photo.avifFor a job, put the same object in the options property of the request body. Jobs take options as JSON only.
{
"operation": "compress",
"input": { "upload": "upl_Zk3Vb9QeT1mXc7HsW0yN" },
"options": { "pdf": { "quality": "small" } }
}From a preset
A preset is an options object stored on your account under a name. A direct request names it with ?preset=, and a job with the preset field of its body. Options sent with the request are applied on top.
curl -X POST "https://api.smolmac.com/v1/compress?preset=web-hero&image.quality=80" \
-H "Authorization: Bearer $SMOL_API_KEY" \
--data-binary @photo.jpg \
-o photo.avifPrecedence
Three sources can set the same field. From weakest to strongest: the preset, the JSON options, the query string. The override is one field at a time, so fields that appear in only one source are kept. With the JSON above and ?image.quality=80, the request runs with format AVIF, width 1200 and quality 80.
image
Used when an image is compressed. See Compress images.
| Field | Type | Description |
|---|---|---|
| image.format | string | original, jpg, png, webp, avif, heic or gif. Default original, which keeps the format of the input. BMP and TIFF input becomes PNG, and camera RAW becomes JPEG. HEIC output, whether asked for by name or reached through original with a HEIC input, is in limited preview. |
| image.quality | integer | 0 to 100. Default 75. For PNG and WebP, 96 and above is lossless. See The quality scale. |
| image.resize | object or false | The box to resize into. Default { "mode": "fit", "width": 2000, "height": 2000 }. Send false to keep the pixel dimensions. |
| image.resize.mode | string | fit, fill, width or height. Default fit. |
| image.resize.width | integer | Width of the box in pixels. Default 2000. Values below 100 are raised to 100, values above 9999 are lowered to 9999. |
| image.resize.height | integer | Height of the box in pixels. Default 2000. Clamped to 100 to 9999 in the same way. |
| image.strip_metadata | boolean | Remove metadata from the output. Default true. It has no effect on PNG output, whose metadata is removed below quality 96 and kept at 96 and above. See Metadata. |
Turning resizing off
Resizing is on by default, so an image larger than 2000 by 2000 pixels is scaled down unless you say otherwise. To keep the pixel dimensions, set image.resize to false:
# query string
curl -X POST "https://api.smolmac.com/v1/compress?image.resize=false" ...
# JSON
{ "image": { "resize": false } }In the query string, setting image.resize.width, image.resize.height or image.resize.mode turns resizing on. A dimension you leave out keeps its default of 2000.
Used when a PDF is compressed. See Compress PDFs.
| Field | Type | Description |
|---|---|---|
| pdf.quality | string | tiny, small, medium, large or original. Default medium. Each preset sets how far the images inside the PDF are scaled down and recompressed. |
video
Used when a video is compressed. Video runs as a job. See Video.
| Field | Type | Description |
|---|---|---|
| video.format | string | Container: mp4, mov, webm or mkv. Default mp4. |
| video.codec | string | h265, h264 or vp9. Default h265. WebM output always uses VP9, whatever this is set to. |
| video.quality | string | tiny, low, balanced, high, maximum or web. Default high. |
| video.resolution | string | original, 3840, 1920, 1280 or 854: the largest width allowed. Default original. Video is only ever scaled down. In JSON the value may be a string or a number. |
| video.strip_audio | boolean | Remove the audio track. Default false. |
| video.slow | boolean | Use the slow encoder preset instead of medium: a smaller file for more processing time. Default false. |
| video.crf | integer or null | 0 to 63. Sets the encoder CRF directly and overrides video.quality. Default null. |
| video.preset | string or null | ultrafast, superfast, veryfast, faster, fast, medium, slow, slower or veryslow. Overrides video.slow. Default null. |
| video.audio_quality | string | Quality of the audio track: tiny, low, balanced, high or maximum. Default high (192 kbit/s). |
audio
Used when an audio file is compressed. See Audio.
| Field | Type | Description |
|---|---|---|
| audio.format | string | aac, m4a, mp3, ogg, opus, wav, flac, alac or original. Default aac, written as an .m4a file. |
| audio.quality | string | tiny (64 kbit/s), low (96), balanced (128), high (192) or maximum (320). Default high. Ignored for the lossless formats. |
| audio.channels | string | stereo, mono or original. Default stereo. mono mixes down to one channel. The other two values keep the channels of the input. |
| audio.strip_metadata | boolean | Remove tags such as title, artist and album. Default false. |
| audio.bitrate_kbps | integer or null | 16 to 512. Sets the bitrate directly and overrides audio.quality. Default null. |
| audio.sample_rate_hz | integer or null | 8000 to 192000. Default null, which keeps the sample rate of the input. Opus output accepts only 8000, 12000, 16000, 24000 and 48000. |
convert
Used by the convert operation. See Convert files.
| Field | Type | Description |
|---|---|---|
| convert.to * | string | The target format, for example webp or pdf. Required for the convert operation, and ignored by the others. Which targets are allowed depends on the input. |
| convert.page | integer | PDF to image only: the page to render, counting from 1. Default 1. |
| convert.dpi | integer | PDF to image only: the render resolution, 36 to 600. Default 144. |
Validation
Options are checked before the file is processed. A field that does not exist, or a value outside the allowed set, fails the request with 400 invalid_options. The API never falls back to a default for a field it does not recognise, because a misspelled option would then pass unnoticed.
curl -X POST "https://api.smolmac.com/v1/compress?image.qualty=60" \
-H "Authorization: Bearer $SMOL_API_KEY" \
--data-binary @photo.jpg{
"error": {
"type": "invalid_request_error",
"code": "invalid_options",
"message": "Unknown option \"image.qualty\".",
"param": "image.qualty",
"request_id": "req_7pWc2LxR9dKf0aTnM4vB",
"doc_url": "https://smolmac.com/docs/reference/errors#invalid_options"
}
}param is the dotted path of the field that caused the error, so you can point at it in your own logs or UI. The same applies to a bad value:
| Sent | param | message |
|---|---|---|
image.quality=120 | image.quality | image.quality must be a whole number between 0 and 100. |
pdf.quality=best | pdf.quality | pdf.quality must be one of: tiny, small, medium, large, original. |
{ "images": { } } | images | Unknown option section "images". Sections are: image, pdf, video, audio, convert. |
A few rules depend on the file and are checked during processing, for example a convert.page beyond the last page of the PDF, or a sample rate the output format does not support. These also fail with invalid_options, but param is null and the message names the field.