catalogue / tools / Images / JPEG to WebP

Convert JPEG to WebP

To convert JPEG to WebP, send one POST to /v1/image-convert with the JPEG 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

01Limits

LimitValue
Largest source file25 MB (26,214,400 bytes)
Timeout60 s
Source formatsAVIF, GIF, JPEG, PNG, SVG, TIFF, WebP
Output formatsJPEG, PNG, WebP
Option qualitydefault 80

02Example

A real JPEG to WebP run of image-convert.

Request
POST /v1/image-convert
content-type: application/json
payment-signature: <base64 x402 payload>

{
  "url": "https://grist.tools/samples/images/pair-note.jpg",
  "quality": 80,
  "format": "webp"
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/images/pair-note.jpg",
  "source_format": "jpeg",
  "format": "webp",
  "mime_type": "image/webp",
  "width": 556,
  "height": 100,
  "bytes": 942,
  "image_base64": "UklGRqYDAABXRUJQVlA4IJoDAAAwPgCdASosAmQAPm0qkUW/oqGYf+wB+AbEtLdw..."
}

Source file: images/pair-note.jpg, 5.2 KB (5,346 bytes). Quality 95 JPEG 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 942 bytes of WebP, 18% of the source size, with an image of 556x100 pixels. Decoded, the WebP in image_base64 opens with 52 49 46 46 A6 03 00 00 57 45 42 50 (ASCII RIFF and WEBP).

In the sample itself, the segments before the first scan run DQT, DQT, SOF0, DHT, DHT, DHT, DHT and SOS, and the baseline frame header declares 556 by 100 pixels, 8-bit precision and 3 components. In the returned WebP: the RIFF header counts 934 bytes after itself, and the one chunk is a lossy VP8 bitstream of 922 bytes that starts with a key frame of 556 by 100 pixels.

03Format notes

JPEG as a source

A JPEG file holds lossy raster data and has no alpha channel. Grist identifies it by the leading bytes FF D8 FF and never by the content-type header the server sent. Two of the conversion services on these pages read it. image-convert sniffs that signature, confirms the bundled libvips decoder can read the format, then reads width and height off the header so that an image over the shared pixel budget is refused before any pixel is decoded. ocr-image-to-text repeats its own check for the same three bytes before the offline Tesseract engine receives the image. Decoding does not undo JPEG compression: block artefacts become ordinary pixel values, so a lossless re-encode stores that noise along with the picture, and a lossy target compresses it again. Metadata blocks such as EXIF are not copied into image-convert output.

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

CodeHTTP
invalid_input400
blocked_target403
unreachable_target424
upstream_timeout424
unsupported_content_type415
too_large413
unprocessable422
internal500

When each is raised, and what it means for payment: /docs/image-convert.

05Questions

What does it cost to convert JPEG to WebP?
$0.003 per call, paid in USDC on Base via x402.
How large can the JPEG 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.

06Related