LossLessimg.com
Developer API Reference

LossLessimg.com provides a fast, developer-friendly REST API to help you automate image optimization in your publishing chains, mobile applications, or custom web portals. Authenticating requests with secure personal access tokens allows you to programmatically compress images and convert formats, preserving visual details and transparency.

Authentication

All API requests must include the following headers for security and format negotiation:

Header Value / Format Description
Authorization Bearer YOUR_API_KEY The secure API token generated in your dashboard.
Accept application/json Required to ensure the server responds with a JSON payload.

Generate and manage your keys in your API Keys settings panel. Keep your keys secret!

Compress Image

POST /api/v1/compress

Request Body Parameters (Multipart Form)

Parameter Type Required Details & Limitations
image file Optional* The raw image file binary. Supported MIME types: image/jpeg, image/png, and image/webp. File size limit: 75MB. (*Either image, images[], or image_url is required).
images[] array of files Optional* An array of raw image file binaries to process in a single batch request. Supports same file size and MIME types as image.
image_url string (URL) Optional* The remote absolute URL pointing to a single image file (e.g. https://example.com/photo.jpg). Supported image formats: JPEG, PNG, WebP, GIF, SVG. File size limit: 75MB. (*Provide either image, images[], or image_url).
convert_to string No Target output format extension: webp, png, jpeg, jpg, or avif. If provided, the API automatically converts and optimizes the image in the selected format.
zip boolean No If set to 1 or true, the API packages the optimized files into a ZIP archive and returns the file download directly.
response_format string No Output response representation format: json (default) or zip. If set to zip, returns a direct ZIP stream download.

JSON Response Fields

Key Name Type Description
success boolean Returns true if the file was compressed and stored successfully.
original_name string The original filename of the image uploaded.
original_size integer File size in bytes before optimization.
compressed_size integer Optimized file size in bytes after running lossless compression.
saved_bytes integer Absolute size difference in bytes (original size - compressed size).
percentage_saved float Savings percentage achieved by the optimizer.
download_url string Secure URL link to download the optimized output asset.
pay_as_you_go_charged boolean Indicates if this compression counted towards excess pay-as-you-go usage.
converted_to string|null The final output format if conversion was requested and successful (e.g. webp).
results array An array of individual file compression result objects (each sharing this same structure). Returned only when batch uploading using images[].

Code Examples

# 1. Compress a single image and convert it to WebP:
curl -X POST "https://www.losslessimg.com/api/v1/compress" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -F "image=@/path/to/my_image.png" \
  -F "convert_to=webp"

# 2. Batch upload and convert multiple files in one request:
curl -X POST "https://www.losslessimg.com/api/v1/compress" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -F "images[]=@/path/to/img1.png" \
  -F "images[]=@/path/to/img2.jpg" \
  -F "convert_to=webp"
// Example: Batch upload and convert multiple files to WebP
const formData = new FormData();
formData.append('convert_to', 'webp');

// Append files to the images[] batch array
filesArray.forEach((file) => {
  formData.append('images[]', file);
});

fetch('https://www.losslessimg.com/api/v1/compress', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Accept': 'application/json'
  },
  body: formData
})
.then(response => response.json())
.then(data => {
  if (data.success && data.results) {
    data.results.forEach(result => {
      console.log(`File: ${result.original_name} -> Converted: ${result.converted_to}`);
      console.log(`Download: ${result.download_url}`);
    });
  }
})
.catch(err => console.error(err));
// Example: Batch upload & convert to WebP using Guzzle
$client = new \GuzzleHttp\Client();

$response = $client->post('https://www.losslessimg.com/api/v1/compress', [
  'headers' => [
    'Authorization' => 'Bearer YOUR_API_KEY',
    'Accept' => 'application/json',
  ],
  'multipart' => [
    [
      'name' => 'convert_to',
      'contents' => 'webp'
    ],
    [
      'name' => 'images[]',
      'contents' => fopen('/path/to/image1.png', 'r'),
      'filename' => 'image1.png'
    ],
    [
      'name' => 'images[]',
      'contents' => fopen('/path/to/image2.jpg', 'r'),
      'filename' => 'image2.jpg'
    ]
  ]
]);

$data = json_decode($response->getBody(), true);
if ($data['success']) {
  foreach ($data['results'] as $result) {
    echo "Optimized: " . $result['original_name'] . " -> " . $result['download_url'] . "\n";
  }
}
# Example: Batch upload & convert to WebP
import requests

url = "https://www.losslessimg.com/api/v1/compress"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Accept": "application/json"
}

# Define files array using images[] key
files = [
    ('images[]', ('img1.png', open('image1.png', 'rb'), 'image/png')),
    ('images[]', ('img2.jpg', open('image2.jpg', 'rb'), 'image/jpeg'))
]

data = {"convert_to": "webp"}

response = requests.post(url, headers=headers, files=files, data=data)
res_json = response.json()

if res_json.get('success'):
    for r in res_json['results']:
        print(f"File: {r['original_name']} -> {r['download_url']}")

API Sandbox

API Bearer Token *
Image File *
Convert Format (Optional)
Request Preview (cURL)
curl -X POST "https://www.losslessimg.com/api/v1/compress" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -F "image=@photo.png"