Image format converter API
Convert between JPEG, PNG, WebP and AVIF.
| Endpoint | POST https://astralbatch.com/api/v1/image-convert |
| Auth | Bearer token, free |
| Sends | input: base64 |
| Returns | result: base64 |
| option | jpeg | png | webp | avif |
| Price | Free. 1,000 calls a day, 60 a minute. |
When to call it
WebP and AVIF are the single largest saving available on an image-heavy page, often more than half the bytes at the same quality. Converting in the upload path means the modern format exists for everything, not only for the images somebody converted by hand.
For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.
Example
curl
curl -X POST https://astralbatch.com/api/v1/image-convert \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "iVBORw0KGgoAAAANSUhEUg...", "option": "avif"}'response
{
"tool": "image-convert",
"result": "AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0...",
"chars": 18304,
"ms": 240
}In your language
JavaScript
const res = await fetch("https://astralbatch.com/api/v1/image-convert", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"input": "iVBORw0KGgoAAAANSUhEUg...", "option": "avif"}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();Python
import os, requests
res = requests.post(
"https://astralbatch.com/api/v1/image-convert",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"input": "iVBORw0KGgoAAAANSUhEUg...", "option": "avif"},
timeout=30,
)
res.raise_for_status()
result = res.json()["result"]Parameters
| Field | Type | Notes |
|---|---|---|
| input | string | Required. The file, base64 encoded. A data: URL is accepted too. Up to 10,000,000 characters per call. |
| option | string | One of: jpeg, png, webp, avif. |
Errors
Errors are RFC 7807 problem documents with a stable type you can branch on.
| missing-token | 401 | No Authorization header. |
| bad-request | 400 | input missing or the wrong type. |
| bad-option | 400 | option is not one of the listed values. |
| tool-failed | 422 | The input could not be processed. detail says why. |
| quota-exceeded | 429 | Past 1,000 calls today. |
Questions
- Which format should I pick?
- AVIF for the smallest file, WebP for the best balance of size and support, JPEG when something old has to read it, PNG when you need lossless or transparency.
- Is transparency preserved?
- Yes, into PNG, WebP and AVIF. Converting a transparent image to JPEG flattens it, because JPEG has no alpha channel at all.
- Is the size changed?
- No. Only the encoding changes. Resize first with the resize endpoint if you want both.
Other endpoints
A token takes thirty seconds
Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.
Get a free token