Documentation menu

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.

all options, with defaults
{
  "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:

OperationSections read
CompressThe 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.
Convertconvert only. Conversion uses fixed encoder settings, described in Convert files.
Strip metadataNone. 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.

bash
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 true or false. Numbers are written in decimal.
  • to, page and dpi are short forms of convert.to, convert.page and convert.dpi.
  • Two query parameters are not options. filename names the file you are sending, and preset names 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.

bash
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.avif

For a job, put the same object in the options property of the request body. Jobs take options as JSON only.

POST /v1/jobs body
{
  "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.

bash
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.avif

Precedence

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.

FieldTypeDescription
image.formatstringoriginal, 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.qualityinteger0 to 100. Default 75. For PNG and WebP, 96 and above is lossless. See The quality scale.
image.resizeobject or falseThe box to resize into. Default { "mode": "fit", "width": 2000, "height": 2000 }. Send false to keep the pixel dimensions.
image.resize.modestringfit, fill, width or height. Default fit.
image.resize.widthintegerWidth of the box in pixels. Default 2000. Values below 100 are raised to 100, values above 9999 are lowered to 9999.
image.resize.heightintegerHeight of the box in pixels. Default 2000. Clamped to 100 to 9999 in the same way.
image.strip_metadatabooleanRemove 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:

bash
# 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.

pdf

Used when a PDF is compressed. See Compress PDFs.

FieldTypeDescription
pdf.qualitystringtiny, 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.

FieldTypeDescription
video.formatstringContainer: mp4, mov, webm or mkv. Default mp4.
video.codecstringh265, h264 or vp9. Default h265. WebM output always uses VP9, whatever this is set to.
video.qualitystringtiny, low, balanced, high, maximum or web. Default high.
video.resolutionstringoriginal, 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_audiobooleanRemove the audio track. Default false.
video.slowbooleanUse the slow encoder preset instead of medium: a smaller file for more processing time. Default false.
video.crfinteger or null0 to 63. Sets the encoder CRF directly and overrides video.quality. Default null.
video.presetstring or nullultrafast, superfast, veryfast, faster, fast, medium, slow, slower or veryslow. Overrides video.slow. Default null.
video.audio_qualitystringQuality 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.

FieldTypeDescription
audio.formatstringaac, m4a, mp3, ogg, opus, wav, flac, alac or original. Default aac, written as an .m4a file.
audio.qualitystringtiny (64 kbit/s), low (96), balanced (128), high (192) or maximum (320). Default high. Ignored for the lossless formats.
audio.channelsstringstereo, mono or original. Default stereo. mono mixes down to one channel. The other two values keep the channels of the input.
audio.strip_metadatabooleanRemove tags such as title, artist and album. Default false.
audio.bitrate_kbpsinteger or null16 to 512. Sets the bitrate directly and overrides audio.quality. Default null.
audio.sample_rate_hzinteger or null8000 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.

FieldTypeDescription
convert.to *stringThe 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.pageintegerPDF to image only: the page to render, counting from 1. Default 1.
convert.dpiintegerPDF 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.

bash
curl -X POST "https://api.smolmac.com/v1/compress?image.qualty=60" \
  -H "Authorization: Bearer $SMOL_API_KEY" \
  --data-binary @photo.jpg
400 response
{
  "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:

Sentparammessage
image.quality=120image.qualityimage.quality must be a whole number between 0 and 100.
pdf.quality=bestpdf.qualitypdf.quality must be one of: tiny, small, medium, large, original.
{ "images": { } }imagesUnknown 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.