Render Mermaid, Graphviz, D2 or Vega-Lite

POST/v1/render/diagram
RapidAPI ● LiveApyHub ● Live · /diagram

Turn diagram-as-code into SVG, PNG, PDF, JPEG, WebP or a JSON PNG data URI. Choose mermaid, graphviz, d2 or vegalite; syntax failures return a structured error with the source line (and column when the engine reports it).

SVG is the fastest vector output and has no pixel ceiling. Raster and PDF outputs are bounded by the published size limits. Vega-Lite data must be inline, and remote/file-reading features are blocked.

More examples and contract notes

More examples

Graphviz architecture

{
  "engine": "graphviz",
  "source": "digraph G { rankdir=LR; client -> gateway -> renderer; renderer -> cache; }",
  "layout": "dot",
  "format": "png",
  "width": 1200,
  "background": "#ffffff"
}

D2 sequence

{
  "engine": "d2",
  "source": "client -> gateway: request\ngateway -> renderer: render\nrenderer -> client: image",
  "layout": "dagre",
  "format": "svg"
}

Vega-Lite chart

{
  "engine": "vegalite",
  "source": "{\"data\":{\"values\":[{\"month\":\"Jan\",\"sales\":28},{\"month\":\"Feb\",\"sales\":55},{\"month\":\"Mar\",\"sales\":43}]},\"mark\":\"bar\",\"encoding\":{\"x\":{\"field\":\"month\",\"type\":\"nominal\"},\"y\":{\"field\":\"sales\",\"type\":\"quantitative\"}}}",
  "format": "png",
  "width": 800
}

Body parameters

application/json
formatjson · svg · png · pdf · jpeg · webp

Output format. `json` returns a PNG data URI plus metadata and is the default; `svg`/`png`/`pdf`/`jpeg`/`webp` return the bytes.

default "json"
scalenumber

Zoom the output 0.5–4×. Ignored when `width` is set. Raster and PDF output is capped at 8192×8192 px on the hosted plans (WebP 4096×4096); SVG has no ceiling.

default 1min 0.5max 4
widthinteger

Target width in pixels (16–4096); height follows the aspect ratio and must stay within the same pixel ceiling. Overrides `scale`.

min 16max 4096
backgroundstring

Background colour as `#rrggbb`/`#rgb`, a CSS name, or `transparent` for none.

enginemermaid · graphviz · d2 · vegaliteREQUIRED

Diagram engine: `mermaid`, `graphviz`, `d2` or `vegalite` (Vega-Lite JSON spec).

sourcestringREQUIRED

Diagram source: Mermaid text, DOT, D2 or a Vega-Lite JSON spec. ≤ 64 KiB via POST, ≤ 8 KiB via GET. Vega-Lite specs must inline their data (`url` is refused); Graphviz attributes that read local files (`image=`, `shapefile=`, …) are refused.

max length 65536
themestring

Engine-specific theme. Mermaid: `default|base|dark|forest|neutral`. D2: a numeric theme id — `0` (neutral default), `1`, `3`, `4`, `5`, `8`, `101`, `200` (dark), `300`, `301`. Vega-Lite: `default|dark`. Graphviz ignores it.

layoutstring

Graphviz layout (`dot|neato|fdp|sfdp|circo|twopi`) or D2 layout (`dagre|elk`). Mermaid and Vega-Lite ignore it.

Responses

The rendered output

application/json
formatstring
media_typestring
widthinteger
heightinteger
data_uristring
warningsstring[]
enginestring
engine_versionstring
cachehit · miss
render_msinteger
queued_msinteger
image/svg+xml

Binary response body.

image/png

Binary response body.

image/jpeg

Binary response body.

image/webp

Binary response body.

application/pdf

Binary response body.