Skip to content

Mermaid to SVG

One call that takes a Markdown document with ```mermaid code blocks, or a single diagram as text, and returns each diagram as SVG, with the line where its block starts.

  • Your agent’s cue: it wrote or found a Mermaid diagram and the task needs the picture, not the code: a page to publish, a file to commit, a preview to show.
  • You’ll reach for it when the document is going somewhere that does not render Mermaid itself, or when you want the SVG checked in next to the Markdown so the two never drift apart.

You are building an internal tool in Base44 that documents team processes. The agent writes each process as a flowchart in Mermaid; a backend function sends the document to MarkdownScribe and stores the SVGs it gets back, and the tool shows them on its pages. The SVG is made for web pages and Markdown renderers: it scales with the page and keeps the text selectable. No rendering library in the app, nothing to install.

Your coding agent writes an architecture document with three diagrams and one of them has a syntax error. The call still succeeds: the two good diagrams come back in diagrams, the broken one is listed in errors with the line of its code block and the renderer’s message, and only the two rendered diagrams are charged. The agent fixes the line and calls again. From the terminal, mdscribe mermaid writes the good SVGs and exits with code 8, so a check step does not pass with a broken diagram in the document.

A docs build renders the diagrams of every page and commits the SVGs next to the Markdown. The same diagram text returns the same SVG byte for byte, so running the job again on an unchanged document produces no diff. Each SVG carries an id that follows the diagram’s position in the document, so inserting a new diagram above an existing one changes the ids inside the SVGs that follow: expect those files to change in that commit, and only in that one.

  • No browser to install. Rendering Mermaid needs a browser engine. Ours runs on our side; your agent makes an HTTP call.
  • One document in, every diagram out. Send the whole Markdown file. Each diagram comes back with its index and the line of its opening fence, so you know where to put it.
  • Partial results are results. A document with one broken diagram still returns the others, lists the failure with its line, and charges only what rendered.
Terminal window
curl https://api.markdownscribe.com/v1/md/mermaid \
-H "X-API-Key: $MDSCRIBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown":"# How a call flows\n\n```mermaid\nflowchart LR\n Agent -->|POST /v1/md/lint| API\n API -->|findings + credits| Agent\n```\n"}'
import { MarkdownScribeClient } from "@markdownscribe/sdk";
const client = new MarkdownScribeClient({ apiKey: process.env.MDSCRIBE_API_KEY! });
const result = await client.mermaid({
markdown: "# How a call flows\n\n```mermaid\nflowchart LR\n Agent -->|POST /v1/md/lint| API\n API -->|findings + credits| Agent\n```\n",
});

Save the markdown value above as how-a-call-flows.md, then:

Terminal window
mdscribe mermaid how-a-call-flows.md

Writes how-a-call-flows-diagram-1.svg next to the file.

Captured from the API on 2026-10-23. svg is cut after its opening tag here; the full value is about 12,000 characters.

{
"diagrams": [
{
"index": 0,
"svg": "<svg id=\"mmd-0\" width=\"100%\" xmlns=\"http://www.w3.org/2000/svg\" class=\"flowchart\" style=\"max-width: 374.25px;\" viewBox=\"…",
"line": 3
}
],
"errors": [],
"summary": {
"total": 1,
"rendered": 1,
"failed": 0
},
"meta": {
"request_id": "01M5MY6PRSK28KKMV5E33MPPNB",
"duration_ms": 2040,
"credits": 5
}
}

To render a single diagram without a document, send diagram instead of markdown: {"diagram": "flowchart LR\n A --> B"}. The CLI does the same for a .mmd file.

From 1 credit per call. 1 when the document contains no diagram. Otherwise 5 for the first rendered diagram plus 2 for each additional rendered one; diagrams that fail to render are not counted, and a call where none renders is an error (422 render_failed) and costs nothing. Each response says what it cost in the X-Credits-Charged header. Error responses are never charged.

  • Input: markdown (a document with ```mermaid blocks) or diagram (one diagram as text), up to 1,048,576 characters.
  • Output: SVG for web pages and Markdown renderers. If you need a PDF or an e-mail attachment, convert the SVG with your own tooling.
  • Time limit: the call gives up after 35 seconds of rendering. Every diagram in the document is rendered in the same call, so send fewer diagrams per call when a document is large.
  • Rate limit: Mermaid and URL to Markdown share a lower per-minute limit than the other operations, because both run a browser. See rate_limited.
Error When
render_failed None of the diagrams in the call could be rendered. Each entry in errors has the diagram’s index, line and message. Nothing is charged.
validation The body has neither markdown nor diagram, or is not valid JSON.
payload_too_large The document is longer than 1,048,576 characters.
timeout Rendering took longer than 35 seconds.
service_unavailable Our rendering service is down. Retry in a moment.
unauthorized, insufficient_credits, rate_limited The key, the balance or the per-minute limit, as on every operation.

Alternatives, and when MarkdownScribe is worth it

Section titled “Alternatives, and when MarkdownScribe is worth it”

Checked on 2026-10-23 against the tool’s own documentation.

  • Mermaid CLI. npx -p @mermaid-js/mermaid-cli mmdc -i diagram.mmd -o diagram.svg renders one diagram file, and mmdc -i page.md -o page.out.md replaces the diagrams in a Markdown file with images (github.com/mermaid-js/mermaid-cli). It downloads and runs a browser engine on the machine. Use MarkdownScribe when your agent runs where it cannot install a browser (the Lovable or Base44 editor, a function with a small runtime, a locked-down CI image), or when you want the diagram’s line and the per-diagram errors in JSON instead of parsing a tool’s output.