Convert AVIF to WebP
To convert AVIF to WebP, send one POST to /v1/image-convert with the AVIF source and "format": "webp" in the body. Each call costs $0.003 in USDC on Base via x402, with no account and no API key. The source file can be up to 25 MB.
- Endpoint
POST /v1/image-convert- Price
- $0.003 per call
- Service
- image-convert
01Limits
| Limit | Value |
|---|---|
| Largest source file | 25 MB (26,214,400 bytes) |
| Timeout | 60 s |
| Source formats | AVIF, GIF, JPEG, PNG, SVG, TIFF, WebP |
| Output formats | JPEG, PNG, WebP |
| Option quality | default 80 |
02Example
A real AVIF to WebP run of image-convert.
POST /v1/image-convert
content-type: application/json
payment-signature: <base64 x402 payload>
{
"url": "https://grist.tools/samples/images/pair-note.avif",
"quality": 80,
"format": "webp"
}200 OK
payment-response: <base64 settlement receipt>
{
"source_url": "https://grist.tools/samples/images/pair-note.avif",
"source_format": "avif",
"format": "webp",
"mime_type": "image/webp",
"width": 556,
"height": 100,
"bytes": 940,
"image_base64": "UklGRqQDAABXRUJQVlA4IJgDAAAQPgCdASosAmQAPm0qkUW/oqGYf+wB+AbEtLdw..."
}Source file: images/pair-note.avif, 1 KB (1,029 bytes). Lossless AVIF of the same 556x100 raster as ocr-scan.png: two uppercase lines drawn from a hand-written 5x7 bitmap font, SAMPLE SCAN FOR OCR and SECOND LINE 2026. The request sets quality to 80. The recorded run returned 940 bytes of WebP, 91% of the source size, with an image of 556x100 pixels. Decoded, the WebP in image_base64 opens with 52 49 46 46 A4 03 00 00 57 45 42 50 (ASCII RIFF and WEBP).
In the sample itself, the ftyp box names major brand avif, minor version 0 and compatible brands mif1, avif and miaf; the top-level boxes run ftyp, meta and mdat; its ispe property gives an image of 556 by 100 pixels; the primary item is coded as av01. In the returned WebP: the RIFF header counts 932 bytes after itself, and the one chunk is a lossy VP8 bitstream of 920 bytes that starts with a key frame of 556 by 100 pixels.
03Format notes
AVIF as a source
AVIF images live inside an ISO base-media file. Grist reads the ftyp box marker at byte four and accepts the avif or avis brand at byte eight. Without that brand test the media sniffer, which looks only for ftyp, would take the same bytes for an MP4 container. Decoding goes through the heif loader compiled into the bundled libvips, and the recorded AVIF conversion examples show a full decode through it. HEIC uses the same container family and loader but has no page here, because no real HEIC has been decoded in this project and HEVC support differs between libheif builds. AVIF reaches image-convert only, since the OCR detector has no AVIF signature. The encoder cannot write AVIF either, so the format appears purely as a source whose decoded pixels are re-encoded, with metadata dropped.
WebP as a target
Selecting WebP in image-convert always yields lossy WebP. The pinned options switch off lossless and near-lossless modes and smart subsampling, and fix the encoder effort so the search does not vary between builds; the caller's quality value is the one setting that changes the result. A lossless source such as PNG is therefore re-encoded lossily when WebP is the destination. The pixel grid stays as it was and the response reports width and height. Metadata blocks are removed because sharp is never asked to keep them, and animation is not written: the decoder reads the first frame only. Vector sources reach this encoder through image-convert, which rasterises them at sharp's default density with no density option, so an SVG becomes a WebP at its intrinsic size rather than at a caller-chosen resolution.
04Errors
| Code | HTTP |
|---|---|
invalid_input | 400 |
blocked_target | 403 |
unreachable_target | 424 |
upstream_timeout | 424 |
unsupported_content_type | 415 |
too_large | 413 |
unprocessable | 422 |
internal | 500 |
When each is raised, and what it means for payment: /docs/image-convert.
05Questions
- What does it cost to convert AVIF to WebP?
- $0.003 per call, paid in USDC on Base via x402.
- How large can the AVIF file be?
- Up to 25 MB (26,214,400 bytes). Past a limit the call answers too_large (413).
- What happens if the conversion fails?
- The tool answers with a typed JSON error from the errors table. Payment is settled only after the tool has produced its result; a call that fails inside the tool is never settled.