{
  "name": "Optimize n8n workflow JSON using Azure OpenAI GPT-4o-mini",
  "nodes": [
    {
      "id": "5f23ac9b-98ba-4612-a1ec-c5765aaad242",
      "name": "Receive Workflow JSON",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -96,
        512
      ]
    },
    {
      "id": "251e2698-77a5-4f72-813e-56873c405adc",
      "name": "Extract & Validate Workflow Body",
      "type": "n8n-nodes-base.code",
      "position": [
        112,
        512
      ]
    },
    {
      "id": "2c9de695-4eb8-40e3-b2b8-56f09f856c90",
      "name": "Optimize Workflow via AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        320,
        512
      ]
    },
    {
      "id": "851875ca-2e10-47c2-abcd-55510d1826b0",
      "name": "Parse, Strip & Validate Optimized JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        672,
        512
      ]
    },
    {
      "id": "6b5043b7-d442-486e-a67b-1ec941e8c3c8",
      "name": "Convert Optimized Workflow to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        880,
        512
      ]
    },
    {
      "id": "e95135fd-5b86-4ab8-9022-7c40e03b15bc",
      "name": "Return Optimized File to Caller",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1088,
        512
      ]
    },
    {
      "id": "f76804b3-61b0-4d60-ae0b-dea1cacc1cbc",
      "name": "📋 Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -720,
        256
      ],
      "parameters": {
        "width": 520,
        "height": 930,
        "content": "## ⚡ AI JSON Optimiser\n\n### How it works\nThis workflow accepts an existing n8n workflow JSON via a POST webhook and uses an Azure OpenAI-powered AI Agent to analyze and return a fully optimized, impor"
      }
    },
    {
      "id": "474343c6-94c4-4d26-983e-3912e5949def",
      "name": "📥 Section: Input & Extraction",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -176,
        336
      ],
      "parameters": {
        "width": 440,
        "height": 200,
        "content": "## 📥 Input & Extraction\nReceives the POST request containing the workflow JSON inside `body.workflow`. Validates the payload structure and extracts the workflow object, rejecting malformed or empty re"
      }
    },
    {
      "id": "846a9c9c-84c3-409f-bc0f-0c63b635f178",
      "name": "🤖 Section: AI Optimization",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        336
      ],
      "parameters": {
        "width": 440,
        "height": 200,
        "content": "## 🤖 AI Optimization Engine\nThe AI Agent sends the full workflow JSON to Azure OpenAI GPT-4o-mini with a strict system prompt focused on performance, structural clarity, and efficiency. Output must be"
      }
    },
    {
      "id": "415a6dab-46c6-49a1-81dc-625e83b77e67",
      "name": "📤 Section: Output Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        320
      ],
      "parameters": {
        "width": 580,
        "height": 200,
        "content": "## 📤 Output Processing & Delivery\nStrips any accidental markdown from the AI response, parses the JSON, validates the n8n structure, converts it to a downloadable file, and returns it as a binary HTTP"
      }
    },
    {
      "id": "5d712314-6e28-4862-86bf-c5472fde6e34",
      "name": "⚠️ Warning: Azure OpenAI Credentials",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        864
      ],
      "parameters": {
        "width": 320,
        "height": null,
        "content": "⚠️ **Azure OpenAI Credentials Required**\nThis node requires a valid `azureOpenAiApi` credential linked to an active Azure deployment named `gpt-4o-mini`. An incorrect deployment name or missing API ke"
      }
    },
    {
      "id": "b558c606-faa7-4dc8-938a-d2e699faded8",
      "name": "Azure OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        176,
        720
      ]
    }
  ],
  "connections": {
    "Receive Workflow JSON": {
      "main": [
        [
          {
            "node": "Extract & Validate Workflow Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Azure OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Optimize Workflow via AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Optimize Workflow via AI Agent": {
      "main": [
        [
          {
            "node": "Parse, Strip & Validate Optimized JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract & Validate Workflow Body": {
      "main": [
        [
          {
            "node": "Optimize Workflow via AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Optimized Workflow to File": {
      "main": [
        [
          {
            "node": "Return Optimized File to Caller",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse, Strip & Validate Optimized JSON": {
      "main": [
        [
          {
            "node": "Convert Optimized Workflow to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}