API

POST /api/v1/compress

One endpoint. Every format.

A REST API you can integrate in minutes - from PHP, Node, Python or anything that speaks HTTP. Compress, convert and resize in a single call.

bash
# compress + convert to AVIF
curl https://api.octosqueeze.com/api/v1/compress \
  -H "Authorization: Bearer $OCTO_KEY" \
  -F file=@photo.jpg \
  -F format=avif -F mode=balanced
On this page

Quick Start

Compress your first image in under a minute. All you need is an API key.

cURL
curl -X POST https://api.octosqueeze.com/api/v1/compress \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@/path/to/image.jpg" \
  -F "mode=balanced"

Base URL: https://api.octosqueeze.com/api/v1

Authentication

All API requests require authentication using a Bearer token. Include your API key in the Authorization header:

HTTP Header
Authorization: Bearer YOUR_API_KEY

You can generate API keys from your dashboard. Keep your API keys secure and never expose them in client-side code.

Security: Never commit API keys to version control or expose them in frontend code.

Compress Image

POST /api/v1/compress

Compress an image by uploading a file or providing a URL. Returns compression results and a temporary download URL.

Option 1: File Upload

Send a multipart/form-data request with the image file:

HTTP
POST /api/v1/compress HTTP/1.1
Host: api.octosqueeze.com
Authorization: Bearer YOUR_API_KEY
Content-Type: multipart/form-data

file: [binary image data]
format: webp
mode: balanced

Option 2: URL

Send a JSON request with an image URL:

JSON
{
  "url": "https://example.com/image.jpg",
  "format": "webp",
  "mode": "balanced"
}

Batch Compression

POST /api/v1/compress-batch

Compress multiple images from URLs in a single request (up to 100 images). Batch requests are on the Pro and Unlimited plans; on Free and Starter the API answers 403 with feature_not_available, and you send one image per request instead.

JSON
{
  "items": [
    {
      "url": "https://example.com/image1.jpg",
      "image_id": "my-id-1",
      "options": { "mode": "size", "format": "webp" }
    },
    {
      "url": "https://example.com/image2.png",
      "image_id": "my-id-2"
    }
  ],
  "options": {
    "mode": "balanced",
    "format": "webp"
  }
}

The options at the root level apply to all items. Per-item options override the defaults.

Check Status

GET /api/v1/status/{jobId}

Check the status of a compression job. status is processing, success or failed; download_url is set only on success.

Response
{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "success",
    "original_size": 2457600,
    "compressed_size": 491520,
    "savings_percent": 80,
    "format": "webp",
    "download_url": "https://api.octosqueeze.com/api/v1/download/550e8400...",
    "created_at": "2024-01-15T10:30:00Z"
  }
}

Download

GET /api/v1/download/{id}

Download a compressed image. Returns the binary file data.

A download link works for 24 hours; the files are deleted after 7 days. Store the compressed image on your own servers.

Usage & Account

Get Usage Statistics

GET /api/v1/usage

A limit your plan does not have is null (Unlimited has no monthly or daily limit).

Response
{
  "success": true,
  "state": "ok",
  "data": {
    "plan": "Pro",
    "period": { "start": "2026-11-01T00:00:00+13:00", "end": "2026-11-30T23:59:59+13:00" },
    "usage": { "compressions": 1250, "limit": 25000, "remaining": 23750, "percentage": 5 },
    "daily": { "api_calls": 150, "limit": 10000 },
    "bytes": { "processed": 1310720000, "saved": 524288000 },
    "limits": { "max_file_size_mb": 50, "api_calls_per_day": 10000, "rate_limit_per_minute": 120 },
    "formats": ["jpeg", "png", "webp", "avif"],
    "reset_date": "2026-12-01T00:00:00+13:00"
  }
}

Get Account Info

GET /api/v1/account

Returns account details including subscription status and API key limits.

Parameters

Parameter Type Required Description
file File Required* Image file: JPEG, PNG, WebP, AVIF, GIF or HEIC, up to your plan's file size. Required if url not provided.
url String Required* Image URL. Required if file not provided.
format String Optional Output: jpeg, png, webp, avif, or auto (we try several formats and return the smallest). Default: same as input
mode String Optional size, balanced (default), quality or lossless
quality Integer Optional 1-100. Overrides mode.
width Integer Optional Max width (px). Aspect ratio preserved.
height Integer Optional Max height (px). Aspect ratio preserved.
exif Boolean Optional Keep EXIF and other metadata. Default: false, so metadata is removed

Smart crop and social sizes are in the dashboard, not in API v1.

Response Format

Successful responses return JSON with compression results:

200 OK
{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "compressed": true,
    "original_size": 2457600,
    "compressed_size": 491520,
    "savings_bytes": 1966080,
    "savings_percent": 80,
    "format": "webp",
    "download_url": "https://api.octosqueeze.com/api/v1/download/550e8400.../signed?...",
    "expires_at": "2026-10-24T12:00:00+00:00"
  }
}

The download_url works for 24 hours (see expires_at); the files are deleted after 7 days. Store the compressed image on your own servers.

Code Examples

PHP

PHP
<?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => 'https://api.octosqueeze.com/api/v1/compress',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer YOUR_API_KEY'
    ],
    CURLOPT_POSTFIELDS => [
        'file' => new CURLFile('/path/to/image.jpg'),
        'format' => 'webp',
        'mode' => 'balanced'
    ]
]);

$response = curl_exec($curl);
$result = json_decode($response, true);

if ($result['success']) {
    $downloadUrl = $result['data']['download_url'];
    file_put_contents('compressed.webp', file_get_contents($downloadUrl));
}

curl_close($curl);

Node.js

Node.js 18 or later, no packages to install. Save it as compress.mjs and run OCTOSQUEEZE_API_KEY=your_key node compress.mjs.

JavaScript
import { readFile, writeFile } from 'node:fs/promises';

const form = new FormData();
form.append('file', new Blob([await readFile('/path/to/image.jpg')], { type: 'image/jpeg' }), 'image.jpg');
form.append('format', 'webp');
form.append('mode', 'balanced');

const response = await fetch('https://api.octosqueeze.com/api/v1/compress', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.OCTOSQUEEZE_API_KEY}` },
  body: form,
  signal: AbortSignal.timeout(120_000),
});
const result = await response.json();

if (!response.ok || !result.success) {
  throw new Error(`OctoSqueeze ${response.status}: ${result.error?.code} ${result.error?.message}`);
}

// The download link works for 24 hours (see expires_at): save the file now.
const file = await fetch(result.data.download_url);
if (!file.ok) throw new Error(`Download failed: ${file.status}`);
await writeFile('compressed.webp', Buffer.from(await file.arrayBuffer()));

Python

Python
import requests

url = 'https://api.octosqueeze.com/api/v1/compress'
headers = {'Authorization': 'Bearer YOUR_API_KEY'}

with open('/path/to/image.jpg', 'rb') as f:
    files = {'file': f}
    data = {'format': 'webp', 'mode': 'balanced'}
    response = requests.post(url, headers=headers, files=files, data=data)

result = response.json()
if result['success']:
    download_url = result['data']['download_url']
    compressed = requests.get(download_url)
    with open('compressed.webp', 'wb') as f:
        f.write(compressed.content)

Client Libraries

  • PHP client: composer require octosqueeze/php-client (PHP 8.0+, MIT).
  • Laravel package (Laravel 10 to 12, PHP 8.1+, MIT). It is not on Packagist yet, so add the repository first:
composer config repositories.octosqueeze-laravel vcs https://github.com/octosqueeze/octosqueeze-laravel
composer require octosqueeze/octosqueeze-laravel

Webhooks

Add a webhook URL in your dashboard under Webhooks (Starter plan and up). We POST JSON for compression.completed, compression.failed, batch.completed, usage.limit_warning and usage.limit_reached, with X-OctoSqueeze-Event and X-OctoSqueeze-Delivery headers. The body is {"event": ..., "timestamp": ..., "data": {...}}.

Generate a signing secret for the webhook in the dashboard. Once it has one, every delivery also carries X-OctoSqueeze-Timestamp and X-OctoSqueeze-Signature: t=<timestamp>,v1=<signature>. The signature is HMAC-SHA256 of <timestamp>.<raw body> with your webhook secret; reject anything older than 5 minutes.

A delivery that fails is tried twice more, after 10 seconds and then after 1 minute.

Answer with a 2xx status within 30 seconds. Any other answer, a redirect or a timeout counts as a failed delivery and is tried again with the same X-OctoSqueeze-Delivery id, so handle each id once. A handler in plain PHP:

PHP webhook handler
<?php
// Verify the signature, then handle each delivery once
$body = file_get_contents('php://input');
$secret = getenv('OCTOSQUEEZE_WEBHOOK_SECRET');

parse_str(str_replace(',', '&', $_SERVER['HTTP_X_OCTOSQUEEZE_SIGNATURE'] ?? ''), $signature);
$timestamp = (int) ($signature['t'] ?? 0);
$expected = hash_hmac('sha256', $timestamp.'.'.$body, $secret);

if (abs(time() - $timestamp) > 300 || ! hash_equals($expected, (string) ($signature['v1'] ?? ''))) {
    http_response_code(401);
    exit;
}

// A retry carries the same X-OctoSqueeze-Delivery id: skip one you have handled.
// $seen is your own store, for example a table with a unique delivery_id column.
$delivery = $_SERVER['HTTP_X_OCTOSQUEEZE_DELIVERY'] ?? '';
if ($seen->has($delivery)) {
    http_response_code(200);
    exit;
}

$event = json_decode($body, true);
// Act on $event['event'] and $event['data'] here
$seen->add($delivery);
http_response_code(200);

Usage and Limits

  • Each image you compress counts once, including the format change and resize in the same request.
  • A batch of 20 URLs needs 20 images left in your month before it starts, and counts each image that compresses.
  • API images per day counts the images compressed through the API that day; checking status or usage and downloading a file do not count.
  • A request we refuse before any work (a wrong parameter, a file type we do not take, or a limit reached) does not count.
  • From 25 October 2026, a compression through the API that fails on our side does not count.
  • Monthly images reset on the 1st of each month, New Zealand time.
  • Every request counts toward your plan's requests per minute.
  • We send usage.limit_warning at 80% of your monthly images and usage.limit_reached when you reach the limit. Over a limit the API answers 429, and error.code says which limit (see Error Handling).

Rate Limits

API requests are rate limited based on your plan:

Plan Req/Min API images/day Images/month Max File
Free2020050025 MB
Starter601,0005,00025 MB
Pro12010,00025,00050 MB
Unlimited300UnlimitedUnlimited100 MB
EnterpriseCustomUnlimitedUnlimitedCustom

Rate limit headers are included in all responses:

  • X-RateLimit-Limit - Maximum requests per minute
  • X-RateLimit-Remaining - Remaining requests this minute
  • X-RateLimit-Reset - When the current minute window resets, as a Unix timestamp in seconds
  • Retry-After - Seconds to wait before retrying (when rate limited)

Error Handling

Error responses include a status code and descriptive message. This is the 422 for a file type the API does not take:

Error Response
{
  "success": false,
  "error": {
    "code": "validation_failed",
    "message": "The file field must be a file of type: jpeg, jpg, png, gif, webp, avif, heic, heif."
  },
  "message": "The file field must be a file of type: jpeg, jpg, png, gif, webp, avif, heic, heif.",
  "errors": {
    "file": ["The file field must be a file of type: jpeg, jpg, png, gif, webp, avif, heic, heif."]
  }
}

HTTP Status Codes

Code Description
200Success
400Bad request
401Missing or invalid API key (unauthenticated)
403Not on your plan, for example a batch request on Free or Starter (feature_not_available), or the key lacks the permission (missing_ability)
404Job or file not found (not_found)
410Download link expired (expired)
413File larger than your plan allows (file_too_large)
422A parameter or file type we do not take (validation_failed), or a format we cannot keep (format_not_preserved)
429A limit was reached; error.code says which: rate_limited (requests per minute, wait for Retry-After), daily_limit_exceeded (API images per day), usage_limit_exceeded or monthly_limit_exceeded (images per month), too_many_requests (another compression from your account was starting at the same moment, retry)
500Server error (compression_failed)

Ship faster images today

500 free images a month. No credit card to start.

No credit card required · 500 free images/month