catalogue / tools / Images / SVG to WebP

Convert SVG to WebP

To convert SVG to WebP, send one POST to /v1/image-convert with the SVG 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 SVG 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/svg-badge.svg",
  "quality": 80,
  "format": "webp"
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/images/svg-badge.svg",
  "source_format": "svg",
  "format": "webp",
  "mime_type": "image/webp",
  "width": 64,
  "height": 48,
  "bytes": 570,
  "image_base64": "UklGRjICAABXRUJQVlA4WAoAAAAQAAAAPwAALwAAQUxQSEYAAAABUBPZavQrEIFF..."
}

Source file: images/svg-badge.svg, 365 bytes. 64x48 geometric SVG badge (rounded card, circle, square and a rule, no text), so its raster carries no font-dependent pixels. The request sets quality to 80. The recorded run returned 570 bytes of WebP, 1.6 times the source size, with an image of 64x48 pixels. Decoded, the WebP in image_base64 opens with 52 49 46 46 32 02 00 00 57 45 42 50 (ASCII RIFF and WEBP).

In the sample itself, the root svg element sets width 64, height 48 and viewBox 0 0 64 48, and below it come 2 rect, 1 circle and 1 path elements. In the returned WebP: the RIFF header counts 562 bytes after itself, and the first chunk is the extended VP8X header with the alpha flag set, for a canvas of 64 by 48 pixels, and the next chunk is ALPH.

03Format notes

SVG as a source

SVG is text, so recognition cannot rest on a binary signature. After an optional byte order mark and leading whitespace, the head of the document must open with an XML prolog that is followed by an svg element, an SVG doctype, a comment followed by an svg element, or the svg tag itself. An HTML page that merely mentions svg somewhere is refused. The dedicated svg-to-png renderer never resolves external references, since the libvips SVG loader does not fetch remote hrefs, and it rejects malformed markup instead of returning a partial image. Its density option drives the natural raster size proportionally. Through image-convert the document is rasterised without that option and then re-encoded at its intrinsic size. As vector content, an SVG can be rendered at a new resolution without resampling a stored bitmap.

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