{
  "name": "Route AI queries cost‑efficiently with GPT‑4o‑mini, GPT‑4o and confidence scoring",
  "nodes": [
    {
      "id": "b316dd7b-3d2f-4365-a0f7-3389caaa6263",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1392,
        80
      ]
    },
    {
      "id": "48c43fc1-86dc-4454-a6ce-2cfa581f3e7b",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1120,
        80
      ]
    },
    {
      "id": "fc83230f-9772-4b50-835e-b394760bed2e",
      "name": "Check Confidence Threshold",
      "type": "n8n-nodes-base.if",
      "position": [
        -224,
        80
      ]
    },
    {
      "id": "882dcd8e-b574-4cd3-8ff2-762a2a40533c",
      "name": "Calculate Cost Difference",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        96
      ]
    },
    {
      "id": "095bccdd-3b90-424b-909e-122fe400dce1",
      "name": "Format Final Response",
      "type": "n8n-nodes-base.set",
      "position": [
        672,
        96
      ]
    },
    {
      "id": "35c1daed-bcfb-41f6-9276-4dc6652e9205",
      "name": "Confidence Evaluator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -592,
        80
      ]
    },
    {
      "id": "0338bd7b-58e9-4577-8288-d7bb4fcb03ca",
      "name": "Parse Confidence JSON",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -384,
        320
      ]
    },
    {
      "id": "367f6833-da36-4b37-9b12-6cfb16ee9e93",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -624,
        320
      ]
    },
    {
      "id": "d5329d77-80d1-433d-bfe6-3a13b32db8c0",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -64
      ],
      "parameters": {
        "width": 272,
        "height": 320,
        "content": "## Check Confidence Threshold\nDecision node that determines whether the response quality is sufficient."
      }
    },
    {
      "id": "86941910-a70c-4a2d-a5a2-fc6d5439b4e6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2032,
        -96
      ],
      "parameters": {
        "width": 464,
        "height": 496,
        "content": "## Cost-Optimized AI Model Routing\n\nThis workflow demonstrates a cost-aware AI routing strategy that balances response quality and API cost. Instead of always using an expensive model, the workflow fi"
      }
    },
    {
      "id": "4ccfe423-62d7-4a2f-b079-0cae59970413",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -128
      ],
      "parameters": {
        "width": 288,
        "height": 384,
        "content": "## Expensive Model (GPT-5.4)\n\nHandles queries that require higher quality reasoning.\nTriggered only when the confidence score is below the threshold."
      }
    },
    {
      "id": "9b4e4e10-5251-4cc9-abde-54133883f307",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        336,
        -128
      ],
      "parameters": {
        "width": 224,
        "height": 384,
        "content": "## Calculate Cost Difference\n\nCalculates token usage and estimated cost of the request.\nDetermines which model was used and compares costs between the cheap and expensive models."
      }
    },
    {
      "id": "a3b8794a-523b-4961-bfbb-56b2f373144d",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -624,
        -80
      ],
      "parameters": {
        "width": 272,
        "height": 304,
        "content": "## Confidence Evaluator\nAnalyzes the cheap model’s response to determine its quality.\nEvaluates accuracy, completeness, clarity, and relevance."
      }
    },
    {
      "id": "c3b6e1ff-507e-4b84-b6bf-5053e749ecaa",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        -128
      ],
      "parameters": {
        "width": null,
        "height": 352,
        "content": "## Cheap Model (GPT-5-mini)\n\nProcesses the user query using a low-cost AI model.\nThis step provides an initial response while minimizing token costs."
      }
    },
    {
      "id": "dd2cc699-9b00-4e96-b932-1732e7eea5e4",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        -128
      ],
      "parameters": {
        "width": null,
        "height": 368,
        "content": "## Workflow Configuration\n\nDefines key configuration settings used across the workflow.\nIncludes the confidence threshold and token pricing"
      }
    },
    {
      "id": "a02448ce-02ae-41bf-8e4f-98c983883ff8",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        592,
        -128
      ],
      "parameters": {
        "width": null,
        "height": 384,
        "content": "## Format Final Response\n\nPrepares the final structured output returned by the workflow."
      }
    },
    {
      "id": "53f9248c-0c2e-4481-9617-b0102edae917",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1456,
        -96
      ],
      "parameters": {
        "width": 256,
        "height": 336,
        "content": "## Webhook Trigger\n\nStarts the workflow when an external application sends a request.\n"
      }
    },
    {
      "id": "21d21b1c-5bf3-4ef1-a424-bb89dd282a84",
      "name": "Cheap Model (GPT-5-mini)",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -880,
        80
      ]
    },
    {
      "id": "041cee60-6892-4324-a259-fb528479adf9",
      "name": "Expensive Model (GPT-5.4)",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        0,
        32
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Confidence Evaluator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Confidence Evaluator": {
      "main": [
        [
          {
            "node": "Check Confidence Threshold",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Confidence JSON": {
      "ai_outputParser": [
        [
          {
            "node": "Confidence Evaluator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Cheap Model (GPT-5-mini)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cheap Model (GPT-5-mini)": {
      "main": [
        [
          {
            "node": "Confidence Evaluator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Cost Difference": {
      "main": [
        [
          {
            "node": "Format Final Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Expensive Model (GPT-5.4)": {
      "main": [
        [
          {
            "node": "Calculate Cost Difference",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Confidence Threshold": {
      "main": [
        [
          {
            "node": "Expensive Model (GPT-5.4)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Calculate Cost Difference",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}