API Documentation
Everything you need to integrate MicroTools into your application.
Overview
MicroTools provides three developer APIs — webpage screenshots, HTML-to-PDF conversion, and image optimization — through a single, consistent interface. All endpoints are available at:
https://batian.icu/api/v1/
Authentication
All API requests require an API key passed in the Authorization header as a Bearer token.
Authorization: Bearer mt_your_api_key_here
Get your free API key at batian.icu/dashboard.
Error Handling
All errors return a consistent JSON structure:
{
"error": "error_code",
"message": "Human-readable description of what went wrong."
}
| Code | Error | Meaning |
|---|---|---|
| 400 | url_required, invalid_url, image_required | Bad request — check your parameters |
| 401 | missing_api_key, invalid_api_key | Missing or invalid API key |
| 403 | forbidden | Internal/private URLs are blocked |
| 429 | usage_limit_exceeded, rate_limited | Limit exceeded — upgrade plan or wait |
| 500 | screenshot_failed, pdf_failed, image_failed | Server error — retry or contact support |
| 504 | screenshot_timeout, pdf_timeout | Target page took too long to load |
Rate Limits & Headers
60 requests per minute. Usage is tracked per API key per calendar month. Response headers include:
| Header | Description |
|---|---|
X-Usage-Remaining | Requests remaining this month |
X-Request-Id | Unique request identifier |
X-Savings-Percent | (Image API only) Compression savings % |
API Endpoints
/api/v1/screenshot
Capture a screenshot of any webpage. Returns the image binary directly.
Parameters (JSON body)
| Field | Type | Default | Description |
|---|---|---|---|
url * | string | — | URL of the page to screenshot |
width | integer | 1280 | Viewport width (max 2560) |
height | integer | 800 | Viewport height (max 2048) |
full_page | boolean | false | Capture the entire scrollable page |
format | string | png | Output format: png or jpeg |
curl -X POST https://batian.icu/api/v1/screenshot \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com","width":1280,"full_page":true}' \
-o screenshot.png
import requests
resp = requests.post(
"https://batian.icu/api/v1/screenshot",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"url": "https://example.com", "width": 1280, "full_page": True}
)
with open("screenshot.png", "wb") as f:
f.write(resp.content)
print(f"Remaining: {resp.headers['X-Usage-Remaining']}")
const resp = await fetch("https://batian.icu/api/v1/screenshot", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({ url: "https://example.com", width: 1280, full_page: true })
});
const buffer = Buffer.from(await resp.arrayBuffer());
require("fs").writeFileSync("screenshot.png", buffer);
console.log("Remaining:", resp.headers.get("X-Usage-Remaining"));
/api/v1/pdf
Convert a URL or raw HTML string into a PDF document.
| Field | Type | Default | Description |
|---|---|---|---|
url | string | — | URL to convert (use url OR html) |
html | string | — | Raw HTML to convert (use url OR html) |
format | string | A4 | Page size: A4, Letter, Legal, Tabloid |
margin | string | 10mm | Page margin (CSS value) |
curl -X POST https://batian.icu/api/v1/pdf \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"Invoice
Amount: $500
","format":"A4","margin":"10mm"}' \
-o document.pdf
resp = requests.post(
"https://batian.icu/api/v1/pdf",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"url": "https://example.com/report", "format": "Letter"}
)
with open("report.pdf", "wb") as f:
f.write(resp.content)
const resp = await fetch("https://batian.icu/api/v1/pdf", {
method: "POST",
headers: { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" },
body: JSON.stringify({ html: "Hello
", format: "A4" })
});
// resp.body is the PDF binary
/api/v1/image
Optimize, resize, and convert images. Upload a file or pass an image URL. Supports WebP, AVIF, JPEG, PNG.
| Field | Type | Description |
|---|---|---|
file | file (multipart) | Image file to upload (max 10MB) |
url | string | URL of image to optimize (use instead of file) |
width | integer | Resize to width (preserves aspect ratio) |
height | integer | Resize to height (preserves aspect ratio) |
format | string | Convert to: webp, avif, jpeg, png |
quality | integer | Quality 1-100 (default 80) |
# File upload
curl -X POST https://batian.icu/api/v1/image \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@photo.jpg" \
-F "width=800" \
-F "format=webp" \
-F "quality=85" \
-o optimized.webp
# URL mode
curl -X POST https://batian.icu/api/v1/image \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/photo.jpg","width":800,"format":"webp"}' \
-o optimized.webp
# URL mode
resp = requests.post(
"https://batian.icu/api/v1/image",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"url": "https://example.com/img.jpg", "width": 800, "format": "webp"}
)
with open("optimized.webp", "wb") as f:
f.write(resp.content)
print(f"Savings: {resp.headers['X-Savings-Percent']}%")
# File upload mode
resp = requests.post(
"https://batian.icu/api/v1/image",
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"file": open("photo.jpg", "rb")},
data={"width": 800, "format": "webp"}
)
const formData = new FormData();
formData.append("file", fileInput.files[0]);
formData.append("width", "800");
formData.append("format", "webp");
const resp = await fetch("https://batian.icu/api/v1/image", {
method: "POST",
headers: { "Authorization": "Bearer YOUR_API_KEY" },
body: formData
});
/api/v1/usage
Get your current monthly usage and plan information.
curl https://batian.icu/api/v1/usage \
-H "Authorization: Bearer YOUR_API_KEY"
# Response:
# {"plan":"pro","usage_this_month":342,"limit":10000,"remaining":9658,"by_endpoint":[...]}
Account Endpoints
/api/auth/registercurl -X POST https://batian.icu/api/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"you@example.com","password":"your_password_min_8_chars"}'
# Response: {"api_key":"mt_...","plan":"free","token":"..."}
/api/auth/logincurl -X POST https://batian.icu/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"you@example.com","password":"your_password"}'
# Response: {"api_key":"mt_...","plan":"pro","token":"..."}