Image Optimizer
Resize, compress, and convert images. Supports WebP, AVIF, PNG, and JPEG.
POST
/v1/image/optimizeUpload 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)
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| image | file | Yes | - | The image file to optimize (max 10MB). |
| format | string | No | original | Output format: png, jpeg, webp, or avif. |
| width | integer | No | original | Resize width in pixels. Height scales proportionally. |
| height | integer | No | original | Resize height in pixels. Width scales proportionally. |
| quality | integer | No | 80 | Compression quality (1-100). Lower = smaller file. |
| fit | string | No | cover | How 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.webpResponse
Returns the optimized image as binary data. The response includes these additional headers:
| Header | Description |
|---|---|
| X-Original-Size | Original file size in bytes |
| X-Optimized-Size | Optimized file size in bytes |
| X-Savings-Percent | Percentage reduction in file size |
Error Codes
| Status | Error | Description |
|---|---|---|
| 400 | missing_image | No image file was provided in the request. |
| 400 | invalid_format | Unsupported output format. |
| 400 | invalid_dimensions | Width or height must be a positive integer. |
| 401 | unauthorized | Missing or invalid API key. |
| 413 | payload_too_large | Image exceeds the 10MB limit. |
| 415 | unsupported_media_type | The uploaded file is not a supported image format. |
| 429 | rate_limit_exceeded | Too many requests. |