API reference for the Mermaid diagram rendering service
The Mermaid Renderer API allows you to generate SVG images containing Mermaid diagram code. The current implementation returns SVG files that display the Mermaid diagram code rather than rendered diagrams.
https://mr1.adptdedu.co/api
For production use, please note:
https://mr1.adptdedu.co/api/renderNo authentication is required for the current version of the API.
Generates an SVG file containing the Mermaid diagram code.
| Parameter | Type | Required | Description |
|---|---|---|---|
| code | string | Yes | The Mermaid diagram code to render |
| format | string | No | The output format: "svg" only (PNG format is no longer supported) |
curl -X POST https://mr1.adptdedu.co/api/render \
-H "Content-Type: application/json" \
-d '{
"code": "graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;",
"format": "svg"
}'
If successful, the response will contain an SVG file with the Mermaid code embedded, with the appropriate content type header:
Content-Type: image/svg+xml{
"error": "Missing required parameter: code"
}
{
"error": "Invalid diagram syntax",
"details": "Error message from mermaid-cli"
}
{
"error": "Failed to render diagram",
"details": "Error message"
}
const fetch = require('node-fetch');
const fs = require('fs');
async function renderDiagram() {
const mermaidCode = `graph TD;
A-->B;
A-->C;
B-->D;
C-->D;`;
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 15000); // 15 second timeout
const response = await fetch('https://mr1.adptdedu.co/api/render', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
code: mermaidCode,
format: 'svg'
}),
signal: controller.signal
});
clearTimeout(timeoutId);
if (!response.ok) {
const errorData = await response.json();
throw new Error(`API Error: ${errorData.error}`);
}
// Save the SVG file
const svgContent = await response.text();
fs.writeFileSync('diagram.svg', svgContent);
console.log('Diagram saved to diagram.svg');
} catch (error) {
console.error('Error:', error.message);
}
}
renderDiagram();
import requests
def render_diagram():
mermaid_code = """graph TD;
A-->B;
A-->C;
B-->D;
C-->D;"""
try:
response = requests.post(
'https://mr1.adptdedu.co/api/render',
json={
'code': mermaid_code,
'format': 'svg'
},
timeout=15 # 15 second timeout
)
response.raise_for_status()
# Save the SVG file
with open('diagram.svg', 'wb') as f:
f.write(response.content)
print('Diagram saved to diagram.svg')
except requests.exceptions.RequestException as e:
print(f'Error: {str(e)}')
if response.headers.get('Content-Type') == 'application/json':
print(f'API Error: {response.json()}')
render_diagram()