{
  "name": "Zero-Fluff Ops #008 — 2-Tier AI Model Router (79% Token Cut)",
  "nodes": [
    {
      "parameters": {
        "path": "ai-model-router-intake",
        "httpMethod": "POST",
        "responseMode": "onReceived"
      },
      "id": "node-webhook",
      "name": "1. Inbound Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "conditions": {
          "combinator": "and",
          "conditions": [
            {
              "leftValue": "={{ ($json.sender_email || '').toLowerCase() }}",
              "rightValue": "no-reply",
              "operator": { "type": "string", "operation": "notContains" }
            },
            {
              "leftValue": "={{ ($json.sender_email || '').toLowerCase() }}",
              "rightValue": "mailer-daemon",
              "operator": { "type": "string", "operation": "notContains" }
            },
            {
              "leftValue": "={{ ($json.body || '').length }}",
              "rightValue": 30,
              "operator": { "type": "number", "operation": "gt" }
            }
          ]
        }
      },
      "id": "node-filter",
      "name": "2. Drop 40% Noise ($0 Filter)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [480, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "x-goog-api-key", "value": "={{ $env.GEMINI_API_KEY }}" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ contents: [{ parts: [{ text: 'Return strict JSON {intent, priority, confidence, draft_reply} for: ' + $json.subject + ' - ' + $json.body }] }] }) }}"
      },
      "id": "node-fast-llm",
      "name": "3. Fast-Tier Triage (Flash/Mini)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, 260]
    },
    {
      "parameters": {
        "conditions": {
          "combinator": "or",
          "conditions": [
            {
              "leftValue": "={{ $json.priority }}",
              "rightValue": "high",
              "operator": { "type": "string", "operation": "equals" }
            },
            {
              "leftValue": "={{ Number($json.confidence || 0) }}",
              "rightValue": 85,
              "operator": { "type": "number", "operation": "lt" }
            }
          ]
        }
      },
      "id": "node-router",
      "name": "4. Escalate Top 20%?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [960, 260]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-4-argon:generateContent",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "x-goog-api-key", "value": "={{ $env.GEMINI_API_KEY }}" },
            { "name": "Content-Type", "value": "application/json" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ contents: [{ parts: [{ text: 'Draft a high-precision executive reply with full SOP context for: ' + $('1. Inbound Webhook').item.json.subject + ' - ' + $('1. Inbound Webhook').item.json.body }] }] }) }}"
      },
      "id": "node-frontier-llm",
      "name": "5a. Frontier Reasoning (20% VIP)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1220, 160]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "create",
        "databaseId": "={{ $env.NOTION_APPROVAL_DB_ID }}",
        "title": "={{ $('1. Inbound Webhook').item.json.subject }}",
        "propertiesUi": {
          "propertyValues": [
            { "key": "Status", "selectValue": "Needs Review" },
            { "key": "ModelTier", "selectValue": "={{ $node['5a. Frontier Reasoning (20% VIP)'].isExecuted ? 'Frontier (Gemini 4)' : 'Fast (Flash/Mini)' }}" }
          ]
        }
      },
      "id": "node-notion",
      "name": "5b. Log to Notion Approval Queue",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [1480, 260]
    }
  ],
  "connections": {
    "1. Inbound Webhook": {
      "main": [[{ "node": "2. Drop 40% Noise ($0 Filter)", "type": "main", "index": 0 }]]
    },
    "2. Drop 40% Noise ($0 Filter)": {
      "main": [[{ "node": "3. Fast-Tier Triage (Flash/Mini)", "type": "main", "index": 0 }], []]
    },
    "3. Fast-Tier Triage (Flash/Mini)": {
      "main": [[{ "node": "4. Escalate Top 20%?", "type": "main", "index": 0 }]]
    },
    "4. Escalate Top 20%?": {
      "main": [
        [{ "node": "5a. Frontier Reasoning (20% VIP)", "type": "main", "index": 0 }],
        [{ "node": "5b. Log to Notion Approval Queue", "type": "main", "index": 0 }]
      ]
    },
    "5a. Frontier Reasoning (20% VIP)": {
      "main": [[{ "node": "5b. Log to Notion Approval Queue", "type": "main", "index": 0 }]]
    }
  },
  "settings": { "executionOrder": "v1" }
}
