📚 API DOCUMENTATION! 🚀

Everything you need to integrate VisualizeAnything into your applications! ⚡

QUICK START ⚡

🎯 Base URL

http://localhost:3000/api

🚀 Basic Example

// Generate an awesome diagram!
const response = await fetch('http://localhost:3000/api/generate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    text: 'Netflix streaming architecture with CDN and user devices',
    format: 'png',
    visualType: 'auto',
    theme: 'vibrant'
  })
});

const imageBlob = await response.blob();
// 💥 BAM! Your visual is ready!

API ENDPOINTS 🎯

POST/api/generate

Generate Visual

Create amazing visuals from text descriptions!

📤 Request:

{
  "text": "User authentication flow for web app",
  "format": "gif",
  "visualType": "flowchart",
  "theme": "vibrant",
  "background": "white",
  "padding": 50,
  "gifOptions": {
    "frameDuration": 100,
    "loop": true,
    "frameRate": 10
  }
}

📥 Response:

// Returns binary image data
// Headers:
X-Generated-HTML: diagram_v1_1234567890.html
X-Screenshot-File: diagram_v1_1234567890.png
X-Base-Filename: diagram
X-Version: 1
POST/api/edit

Edit Visual

Modify existing visuals with AI-powered editing!

📤 Request:

{
  "htmlFileName": "diagram_v1_1234567890.html",
  "editPrompt": "Make the boxes bigger and add more colors",
  "format": "png"
}

📥 Response:

// Returns updated binary image data
// Headers:
X-Generated-HTML: diagram_v2_1234567891.html
X-Screenshot-File: diagram_v2_1234567891.png
X-Version: 2
POST/api/upload-v2

Upload File

Upload images, PDFs, CSVs, and more for enhanced visuals!

📤 Request:

// Form data with file
const formData = new FormData();
formData.append('file', file);

fetch('/api/upload-v2', {
  method: 'POST',
  body: formData
})

📥 Response:

{
  "url": "/uploads/file-1234567890.csv",
  "content": "name,age,city\nJohn,25,NYC\nJane,30,LA"
}
GET/api/files

List Files

Get all generated HTML files and screenshots!

📤 Request:

// No body required

📥 Response:

{
  "html_files": [
    "diagram_v1_1234567890.html",
    "flowchart_v2_1234567891.html"
  ],
  "screenshots": [
    "diagram_v1_1234567890.png",
    "flowchart_v2_1234567891.gif"
  ]
}
GET/api/health

Health Check

Check if the API is running and configured properly!

📤 Request:

// No body required

📥 Response:

{
  "status": "healthy",
  "timestamp": "2024-01-01T12:00:00.000Z",
  "openai_configured": true
}

PARAMETERS GUIDE 📋

Generate Request Parameters

ParameterTypeRequiredDescriptionDefault
textstringYESDescription of the visual you want to create-
formatstringNOOutput format: "png", "jpg", "jpeg", or "gif"png
visualTypestringNOType of visual: "auto", "flowchart", "timeline", "mindmap", "chart", "system", "infographic"auto
themestringNOVisual theme: "vibrant", "modern", "minimal", "dark"vibrant
backgroundstringNOBackground style: "white", "transparent", "gradient"white
paddingnumberNOPadding around the visual in pixels50
qualitynumberNOImage quality (10-100)95
uploadedFilesarrayNOArray of uploaded file objects for context-
gifOptionsobjectNOGIF-specific options (frameDuration, loop, frameRate, etc.)-

GIF Options

ParameterTypeRequiredDescriptionDefault
frameDurationnumberNODuration between frames in milliseconds100
totalDurationnumberNOTotal GIF duration in milliseconds3000
frameRatenumberNOFrames per second10
loopbooleanNOWhether to loop the GIFtrue
detectAnimationsbooleanNOAuto-detect and enhance animationstrue

CODE EXAMPLES 💻

🐍 Python

import requests

def generate_diagram(text, format='png'):
    response = requests.post('http://localhost:3000/api/generate', 
                           json={
                               'text': text,
                               'format': format,
                               'visualType': 'auto',
                               'theme': 'vibrant'
                           })
    
    if response.status_code == 200:
        return response.content
    else:
        raise Exception(f"Error: {response.status_code}")

# Usage
diagram_data = generate_diagram("Database schema for e-commerce app")
with open('schema.png', 'wb') as f:
    f.write(diagram_data)

🚀 Node.js

const fs = require('fs');

async function generateDiagram(text, format = 'png') {
  try {
    const response = await fetch('http://localhost:3000/api/generate', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        text: text,
        format: format,
        visualType: 'auto',
        theme: 'vibrant',
        gifOptions: format === 'gif' ? { loop: true, frameRate: 10 } : undefined
      }),
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const buffer = await response.arrayBuffer();
    return Buffer.from(buffer);
  } catch (error) {
    console.error('Error generating diagram:', error);
    throw error;
  }
}

// Usage
generateDiagram('Microservices architecture diagram', 'gif')
  .then(buffer => {
    fs.writeFileSync('architecture.gif', buffer);
    console.log('✅ Diagram saved!');
  })
  .catch(console.error);

🌐 React/Next.js

import { useState } from 'react';

function DiagramGenerator() {
  const [loading, setLoading] = useState(false);
  const [imageUrl, setImageUrl] = useState(null);

  const generateDiagram = async (text) => {
    setLoading(true);
    try {
      const response = await fetch('/api/generate', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          text: text,
          format: 'png',
          visualType: 'auto',
          theme: 'vibrant'
        }),
      });

      if (!response.ok) throw new Error('Generation failed');

      const blob = await response.blob();
      const url = URL.createObjectURL(blob);
      setImageUrl(url);
    } catch (error) {
      console.error('Error:', error);
    } finally {
      setLoading(false);
    }
  };

  return (
    <div>
      <button 
        onClick={() => generateDiagram('User onboarding flow')}
        disabled={loading}
      >
        {loading ? 'Generating...' : 'Generate Diagram'}
      </button>
      {imageUrl && <img src={imageUrl} alt="Generated diagram" />}
    </div>
  );
}

🚨 ERROR HANDLING

Common Error Codes

  • 400 Bad Request: Missing or invalid parameters
  • 404 Not Found: File or endpoint not found
  • 500 Internal Server Error: AI generation or screenshot failed
  • 413 Payload Too Large: File upload too big (max 10MB)
// Always handle errors gracefully
try {
  const response = await fetch('/api/generate', { /* ... */ });
  
  if (!response.ok) {
    const errorData = await response.json();
    throw new Error(errorData.error || 'Generation failed');
  }
  
  const imageBlob = await response.blob();
  // Success! 🎉
} catch (error) {
  console.error('Generation error:', error.message);
  // Show user-friendly error message
}

SUPPORT & FEEDBACK 💖

Having issues? Want to contribute? We're here to help! 🤗

🐛 Report Issues

Found a bug? Let us know!

GitHub Issues

💬 Get Help

Need assistance? Reach out!

Contact Us