API Documentation Page
Explore Our API Documentation Page
📚 API Documentation
Complete guide to integrating Smart Image Optimizer into your application
🔐 Authentication
All API requests require authentication using an API key. Include your API key in the request header:
X-API-Key: your_api_key_here
Get your API key from the API Keys page in your dashboard.
🌐 Base URL
https://tinysharp.com/wp-json/sio/v1
📤 Optimize Image
Upload and optimize a single image.
POST /optimize
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
image | File | Yes | Image file (JPEG, PNG, WebP, GIF) |
Example Request (cURL)
curl -X POST https://tinysharp.com/wp-json/sio/v1/optimize \
-H "X-API-Key: your_api_key" \
-F "image=@/path/to/image.jpg"
Example Request (JavaScript)
const formData = new FormData();
formData.append('image', fileInput.files[0]); fetch('https://tinysharp.com/wp-json/sio/v1/optimize', {
method: 'POST',
headers: {
'X-API-Key': 'your_api_key'
},
body: formData
})
.then(response => response.json())
.then(data => {
console.log('Optimized!', data);
// data.image contains base64 encoded optimized image
});
Example Request (PHP)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://tinysharp.com/wp-json/sio/v1/optimize');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: your_api_key'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'image' => new CURLFile('/path/to/image.jpg')
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch); $data = json_decode($response, true);
Response
{
"success": true,
"image": "base64_encoded_image_data",
"original_size": 1048576,
"optimized_size": 524288,
"saved": 524288,
"tokens_remaining": 999
}
🎟️ Check Token Balance
Check your remaining token balance and plan details.
GET /tokens
Example Request
curl -X GET https://tinysharp.com/wp-json/sio/v1/tokens \
-H "X-API-Key: your_api_key"
Response
{
"plan": "starter",
"total_tokens": 1000,
"used_tokens": 150,
"remaining_tokens": 850,
"expires_at": null,
"upgrade_url": null
}
⚠️ Error Handling
The API uses standard HTTP status codes:
| Code | Description |
|---|---|
200 | Success |
400 | Bad Request - Invalid parameters |
401 | Unauthorized - Invalid API key |
402 | Payment Required - Insufficient tokens |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Server Error |
Error Response
{
"code": "insufficient_tokens",
"message": "Insufficient tokens. Please upgrade your plan.",
"data": {
"status": 402,
"upgrade_url": "https://tinysharp.com/pricing-plans/"
}
}
💡 WordPress Plugin Integration
Use our WordPress plugin to automatically optimize all images on your site.
Installation
// Add to wp-config.php
define('SIO_API_KEY', 'your_api_key'); // Or use a plugin to integrate with media uploads
Example WordPress Integration
// Automatically optimize on upload
add_filter('wp_handle_upload', function($upload) {
$api_key = defined('SIO_API_KEY') ? SIO_API_KEY : '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://tinysharp.com/wp-json/sio/v1/optimize');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-API-Key: ' . $api_key]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'image' => new CURLFile($upload['file'])
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data['success']) {
file_put_contents($upload['file'], base64_decode($data['image']));
}
return $upload;
});
📊 Rate Limits
API rate limits by plan:
- Free: 10 requests per minute
- Starter: 30 requests per minute
- Pro: 100 requests per minute
🆘 Support
Need help? Contact us:
- 📧 Email: support@tinysharp.com
- 💬 Discord: Join our community
- 💲 Pricing: See full details