Monoize
Transforms

Image: compress request images

Re-encode inline user images and tool images before upstream encoding.

What it does

This transform re-encodes inline user images and typed images in tool results. It also processes image data URLs and image blocks in JSON function-tool arguments. It can resize eligible images to max_edge_px. It leaves custom-tool input and unrelated Base64 unchanged.

With skip_if_smaller on (the default), an image keeps its original bytes when compression does not shrink it.

For JPEG, PNG, and WebP bytes, the transform detects the actual format. It corrects a mismatched MIME type even when skip_if_smaller keeps the bytes.

When the selected output format is jpg, images with an alpha channel remain unchanged. The transform preserves their original bytes, media type, and dimensions. This applies even when every pixel is opaque. It overrides max_edge_px and skip_if_smaller to preserve transparency and image masks. Without a mask, formats that support alpha continue to use the configured compression settings.

If an edit request contains a mask, the transform skips all request images, including tool images. It preserves image and mask bytes, dimensions, and alignment before cache lookup.

Reference

PropertyValue
Type IDimage_compress_input
Phaserequest
ScopesProvider, API key

When to use

  • Clients send large photos or screenshots and upstream requests hit size limits.
  • You want to cap image resolution for cost control.

Configuration

OptionTypeRequiredDefaultDescription
output_formatstringNo"original"original, jpg, jpegxl_lossless, jpegxl, webp_lossless, webp, or png.
max_edge_pxintegerNo—Maximum width or height in pixels. Omit to keep the original dimensions.
jpeg_qualityintegerNo80Quality 1-100 for JPEG output.
jpegxl_qualityintegerNo90Quality 1-99 for lossy JPEG XL output.
jpegxl_effortintegerNo7JPEG XL encoding effort 1-10. Higher values compress more slowly.
webp_qualityintegerNo80Quality 1-100 for lossy WebP output.
skip_if_smallerbooleanNotrueKeep the original image when compression does not reduce the payload size.

Example rule

{
  "transform": "image_compress_input",
  "enabled": true,
  "phase": "request",
  "models": [
    "*"
  ],
  "config": {
    "output_format": "webp",
    "max_edge_px": 1568,
    "webp_quality": 80
  }
}

Set the environment variables MONOIZE_IMAGE_TRANSFORM_MAX_* to bound decode work. See Configuration.

On this page