Mermaid.ink API
Turn Mermaid diagram source into a PNG, JPEG, SVG or PDF with a single URL. No key, no JavaScript, works in READMEs and email. Verified example included.
Endpoint tested and returned HTTP 200 on 2026-08-21
What is the Mermaid.ink API?
Mermaid.ink renders Mermaid diagrams server-side. Base64-encode your diagram source and request `https://mermaid.ink/img/{base64}?type=png` for an image, or `/svg/{base64}` for vector output. No API key is required.
Mermaid normally needs a JavaScript runtime, which rules it out of exactly the places diagrams are most useful: READMEs on forges that do not render Mermaid, HTML email, PDFs and chat unfurls. Mermaid.ink moves the rendering to a server and puts the entire diagram in the URL, so an `<img>` tag is the whole integration.
Two encoding details decide whether it works. The path segment is base64 of the raw diagram source, and it must be base64url, using `-` and `_` in place of `+` and `/`, because a bare `/` would break the path. And despite the `/img/` prefix the default output is JPEG, not PNG, which produces visibly muddy text on line diagrams. Add `?type=png` for crisp output, or use the `/svg/` path when the destination can render vectors. Long diagrams also run into URL length limits, so the project supports a pako-compressed form for larger sources.
Quick facts
- Base URL
https://mermaid.ink- Authentication
- No key. The hosted instance is a courtesy; the project is open source and containerised for self-hosting.
- Rate limit
- Not published. Cache rendered images rather than re-rendering the same diagram on every page view.
- Pricing
- Free and open source, self-hostable.
- CORS
- Enabled — callable directly from browser JavaScript
- Official docs
- Read the docs
How to use the Mermaid.ink API
Every request below was executed against the live API on 2026-08-21, and the response shown is the real body it returned — not an illustration.
1. Render a Mermaid flowchart as PNG
GET https://mermaid.ink/img/Z3JhcGggVEQ7CiAgQVtDbGllbnRdLS0-QltBUEldOwogIEItLT5DWyhEYXRhYmFzZSldOw==?type=png
curl 'https://mermaid.ink/img/Z3JhcGggVEQ7CiAgQVtDbGllbnRdLS0-QltBUEldOwogIEItLT5DWyhEYXRhYmFzZSldOw==?type=png'const res = await fetch("https://mermaid.ink/img/Z3JhcGggVEQ7CiAgQVtDbGllbnRdLS0-QltBUEldOwogIEItLT5DWyhEYXRhYmFzZSldOw==?type=png");
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
const data = await res.json();
console.log(data);import requests
res = requests.get("https://mermaid.ink/img/Z3JhcGggVEQ7CiAgQVtDbGllbnRdLS0-QltBUEldOwogIEItLT5DWyhEYXRhYmFzZSldOw==?type=png", timeout=20)
res.raise_for_status()
print(res.json())# This endpoint returns image/png, not JSON.
# The response body is the image itself, so it can be used directly as an
# <img src="..."> or saved to a file — there is nothing to parse.
#
# Verified: HTTP 200, Content-Type: image/pngParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
{base64} | path | Required | Base64url encoding of the diagram source. Use `-` and `_` instead of `+` and `/`. Z3JhcGggVEQ7... |
type | string | Optional | Output format on the `/img/` path. Defaults to `jpeg`; pass `png` or `webp` for better text rendering. png |
/svg/{base64} | path | Optional | Vector output as `image/svg+xml`, which stays sharp at any size. /svg/Z3JhcGgg... |
/pdf/{base64} | path | Optional | PDF output, useful for print-ready documentation. /pdf/Z3JhcGgg... |
bgColor | string | Optional | Background colour as a hex value without the hash, or `!white` for a named colour. ffffff |
theme | string | Optional | Mermaid theme: `default`, `neutral`, `dark` or `forest`. dark |
Response fields
(body)image/png- The rendered diagram. There is no JSON envelope; the response body is the image itself, usable directly in an `<img src>`.
(default content type)image/jpeg- Without `?type=png` the `/img/` path returns JPEG, whose compression blurs thin diagram lines and small text.
(svg path)image/svg+xml- The `/svg/` path returns text-based SVG, which scales cleanly and can be styled or embedded inline.
(400 responses)n/a- A syntax error in the diagram, or invalid base64, returns an error rather than an image. Test the source in the Mermaid live editor first.
What you can build with the Mermaid.ink API
- Embed architecture diagrams in a README on a forge that does not render Mermaid
- Include flowcharts in HTML email or a PDF report
- Generate sequence diagrams from code comments during a docs build
- Post a diagram into Slack or Discord as an image
- Render diagrams in a static site generator without adding a JavaScript dependency
Common errors and how to fix them
400
Invalid base64, or a Mermaid syntax error in the decoded source.
Fix: Verify the diagram renders in the Mermaid live editor, then re-encode with base64url. Standard base64 containing `/` will break the path.
Blurry text in the image
The default `/img/` output is JPEG.
Fix: Append `?type=png`, or use the `/svg/` path for text-heavy diagrams.
URL too long
Large diagrams exceed the URL length limits of proxies and some clients.
Fix: Use the project's pako-compressed encoding, or render once and host the resulting image yourself.
Mermaid.ink API — frequently asked questions
Do I need an API key for Mermaid.ink?
No. The hosted service is free and unauthenticated. Because it is donated infrastructure, cache your rendered images rather than regenerating them on every request.
Why is my diagram blurry?
The `/img/` path returns JPEG by default, which compresses thin lines poorly. Add `?type=png`, or switch to the `/svg/` path.
How do I encode the diagram?
Base64url-encode the raw Mermaid source and put it in the path. Replace `+` with `-` and `/` with `_`, since a literal slash would be read as a path separator.
Can I self-host it?
Yes. The project ships as a container image, which is the right answer for any product that renders diagrams at volume or handles private information.
Tools that pair with this API
SVG to PNG Converter
Convert SVG vector files to PNG at any resolution you choose. Render crisp raster images from SVG in your browser — free, instant and private.
SVG Minifier
Minify SVG files in your browser: strip comments, metadata and editor junk, round coordinates, collapse whitespace — with a live preview and size savings.
Base64 Encoder
Encode text or files to Base64 instantly in your browser. UTF-8 safe, with a URL-safe Base64 option, copy and download. Free online Base64 encoder.
Base64URL Encoder
Encode text to URL-safe Base64URL online — the JWT variant with - and _ instead of + and /, no padding. UTF-8 aware, instant and 100% in your browser.
Image to Base64 Converter
Convert an image to a Base64 data URL online. Get copy-ready HTML img tags and CSS background-image snippets. Free, instant and fully private.
Mermaid.ink is an independent third-party service and is not affiliated with ByteTools or ByteVancer. Details on this page were verified on 2026-08-21; always check the official documentation before relying on this API in production, as terms and limits can change.