Image Optimizer

Resize, compress, and convert images. Supports WebP, AVIF, PNG, and JPEG.

POST/v1/image/optimize

Upload an image and get back an optimized version. Resize, compress, and convert between formats including WebP and AVIF. Supports PNG, JPEG, WebP, GIF, and AVIF inputs.

Authentication

Requires x-api-key header.

Request Body (multipart/form-data)

NameTypeRequiredDefaultDescription
imagefileYes-The image file to optimize (max 10MB).
formatstringNooriginalOutput format: png, jpeg, webp, or avif.
widthintegerNooriginalResize width in pixels. Height scales proportionally.
heightintegerNooriginalResize height in pixels. Width scales proportionally.
qualityintegerNo80Compression quality (1-100). Lower = smaller file.
fitstringNocoverHow to fit when both width and height are set: cover, contain, fill, inside, outside.

Example Request

-blue-400 font-semibold">curl -X POST -emerald--amber-400">400">"https://api.aicores.io/v1/image/optimize" \
  -H -emerald--amber-400">400">"x-api-key: sk_live_your_key_here" \
  -F -emerald--amber-400">400">"image=@photo.jpg" \
  -F -emerald--amber-400">400">"format=webp" \
  -F -emerald--amber-400">400">"width=-amber-400">800" \
  -F -emerald--amber-400">400">"quality=-amber-400">75" \
  --output optimized.webp

Response

Returns the optimized image as binary data. The response includes these additional headers:

HeaderDescription
X-Original-SizeOriginal file size in bytes
X-Optimized-SizeOptimized file size in bytes
X-Savings-PercentPercentage reduction in file size

Error Codes

StatusErrorDescription
400missing_imageNo image file was provided in the request.
400invalid_formatUnsupported output format.
400invalid_dimensionsWidth or height must be a positive integer.
401unauthorizedMissing or invalid API key.
413payload_too_largeImage exceeds the 10MB limit.
415unsupported_media_typeThe uploaded file is not a supported image format.
429rate_limit_exceededToo many requests.