API Documentation
Integrate PixelCrush image compression into your applications with our simple REST API.
Quick Start
Compress an image with a single cURL command:
curl -X POST https://pixelcrush.app/api/v1/compress \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "quality=80" \
-F "format=webp" \
-o compressed.webpAuthentication
All API requests require authentication via Bearer token. Include your API key in the Authorization header.
Authorization: Bearer pk_xxxxxxxxxxxxxxxxxxxxxGet your API key from the Dashboard
Endpoint
POST
/api/v1/compressParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| file | File | Yes* | Image file (multipart/form-data) |
| url | String | Yes* | Image URL to fetch and compress |
| quality | Number | No | Compression quality 1-100 (default: 80) |
| format | String | No | Output format: auto, jpeg, png, webp, avif (default: auto) |
| maxWidth | Number | No | Maximum width in pixels |
| maxHeight | Number | No | Maximum height in pixels |
* Either file or url is required
Response Headers
X-Original-SizeOriginal file size in bytesX-Compressed-SizeCompressed file size in bytesX-Compression-RatioCompression percentageX-Image-FormatOutput image formatX-Processing-TimeProcessing timeCode Examples
JavaScript (fetch)
const formData = new FormData();
formData.append('file', imageFile);
formData.append('quality', '80');
formData.append('format', 'webp');
const response = await fetch('https://pixelcrush.app/api/v1/compress', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
},
body: formData
});
const compressedImage = await response.blob();
console.log('Compression ratio:', response.headers.get('X-Compression-Ratio'));Python (requests)
import requests
with open('image.png', 'rb') as f:
response = requests.post(
'https://pixelcrush.app/api/v1/compress',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
files={'file': f},
data={'quality': 80, 'format': 'webp'}
)
with open('compressed.webp', 'wb') as f:
f.write(response.content)
print(f"Saved {response.headers['X-Compressed-Size']} bytes")Compress from URL
curl -X POST https://pixelcrush.app/api/v1/compress \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "url=https://example.com/image.jpg" \
-F "quality=75" \
-o compressed.jpgSupported Formats
JPEG
PNG
WebP
AVIF
GIF
Use format=auto for automatic format selection based on image content and browser support.
Rate Limits
| Plan | Monthly Images | Max File Size |
|---|---|---|
| Free | 50 | 5 MB |
| Pro | 5,000 | 50 MB |
| Enterprise | Unlimited | 100 MB |