Mermaid Renderer API Documentation

API reference for the Mermaid diagram rendering service

API Overview

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.

Base URL
https://mr1.adptdedu.co/api
Production Configuration

For production use, please note:

  • The service is accessible at https://mr1.adptdedu.co/api/render
  • Make sure your client properly handles HTTPS
  • Set an appropriate timeout (10+ seconds recommended)
  • The service may have rate limits
Authentication

No authentication is required for the current version of the API.

Endpoints

POST /api/render

Generates an SVG file containing the Mermaid diagram code.

Request Body Parameters
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)
Example Request
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"
  }'
Response
200 OK The SVG file containing the Mermaid code

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 Responses
400 Bad Request Invalid input
{
  "error": "Missing required parameter: code"
}
400 Bad Request Invalid diagram syntax
{
  "error": "Invalid diagram syntax",
  "details": "Error message from mermaid-cli"
}
500 Internal Server Error Server error
{
  "error": "Failed to render diagram",
  "details": "Error message"
}

Example Code

JavaScript (Node.js)
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();
Python
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()