API & MCP

Everything a person can do on SVG Optimizer, a program or AI agent can do with the same inputs and get the identical result.

HTTP API

SVG Optimizer

Optimises an SVG file in your choice of steps and shows how many bytes each one saved: removes comments, metadata and Inkscape/Illustrator editor data, hidden and empty elements, rounds numbers, rewrites path data in its shortest form and collapses whitespace. It also removes scripts, event handlers and external references, so the result is safe to embed.

Inputs of SVG Optimizer
FieldTypeDefaultDescription
svgFilefile—SVG file. An .svg or .svgz file, max 5 MB. Alternatively paste the SVG code below.
svgTexttextarea—Or paste SVG code
precisioninteger3Decimal places. Coordinates and lengths are rounded to this many decimals. 1–3 is usually invisible; transforms keep two more.
minifyPathsbooleantrueMinify path data (shortest relative/absolute commands)
removeHiddenbooleantrueRemove hidden elements and unused definitions
removeDimensionsbooleanfalseRemove width/height (keep viewBox so the SVG scales responsively)

Example request

Inkscape export with a script

curl -X POST https://svgoptimizer.usefulweb.site/api/v1/calculate -H 'content-type: application/json' -d '{"svgText":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!-- Created with Inkscape (http://www.inkscape.org/) -->\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" width=\"120.000000\" height=\"80.000000\" viewBox=\"0 0 120 80\" version=\"1.1\" onload=\"alert('hi')\">\n  <sodipodi:namedview id=\"namedview1\" pagecolor=\"#ffffff\" inkscape:zoom=\"2.0\"/>\n  <metadata id=\"metadata1\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"/></metadata>\n  <script>alert('x')</script>\n  <g inkscape:label=\"Layer 1\" inkscape:groupmode=\"layer\" id=\"layer1\">\n    <rect x=\"10.0000001\" y=\"10.123456\" width=\"40.000000\" height=\"30.000000\" fill=\"#1652f0\" />\n    <path d=\"M 60.000000 10.000000 L 110.000000 10.000000 L 110.000000 40.000000 L 60.000000 40.000000 Z\" fill=\"#f0a500\" />\n    <circle cx=\"35.555555\" cy=\"60.444444\" r=\"12.0000\" fill=\"#0f8a5f\" style=\"display:none\" />\n    <g></g>\n  </g>\n</svg>\n","precision":2}'

Every result contains

inputs (normalised, defaults applied), summary, result (validated against the published schema), units, assumptions, sources, warnings, computedAt and links.

MCP (Model Context Protocol)

{
  "mcpServers": {
    "svg-optimizer": { "type": "http", "url": "https://svgoptimizer.usefulweb.site/mcp" }
  }
}