{
  "name": "UGC Automation - Model Bake-off (Veo3 Fast vs Kling 3.0)",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        600
      ],
      "id": "bo-trigger-0001",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/getFile?file_id={{ $('Telegram Trigger').first().json.message.photo.last().file_id }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        600
      ],
      "id": "bo-getimgpath-0001",
      "name": "Get Img Path"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "text": "Got it! Running A/B bake-off: kie veo3_fast vs fal Kling 3.0...",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        440,
        600
      ],
      "id": "bo-progress-0001",
      "name": "In Progress",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "modelId": {
          "__rl": true,
          "value": "gpt-5-mini",
          "mode": "list",
          "cachedResultName": "gpt-5-mini"
        },
        "text": "=# Scene Writer -- single-scene UGC video prompt (bake-off tool)\n\nYou will write ONE ~8 second UGC-style video scene prompt for an A/B test. The same prompt and the\nsame reference image will be sent to two different video generators, so the prompt must NOT reference\na model or provider by name.\n\nUGC style rules:\n- Natural, candid, unpolished -- amateur iPhone selfie/video quality, slightly uneven framing, authentic,\n  slightly blurry.\n- Character just shows and talks about the product/its benefits based on what's visible in the reference\n  image (taste for a drink, design for a bag, features for tech, etc). Do not have them open, eat, or use\n  the product -- they are just showing it to camera.\n- Dialogue under 150 characters, casual and conversational, using ... for pauses, no em dashes.\n- Preserve all visible product text/packaging claims accurately; never invent extra claims or numbers.\n\nUser's instructions (caption):\n{{ $('Telegram Trigger').first().json.message.caption }}\n\nReturn ONLY this JSON object, no markdown fences, no commentary:\n{\n  \"video_prompt\": \"stringified YAML: dialogue, emotion, voice_type, action, character, setting, camera\",\n  \"aspect_ratio_video\": \"9:16 or 16:9, default 9:16\"\n}\n",
        "imageUrls": "=https://api.telegram.org/file/bot{{ $env.TELEGRAM_BOT_TOKEN }}/{{ $('Get Img Path').first().json.result.file_path }}",
        "simplify": false,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        660,
        600
      ],
      "id": "bo-scenewriter-0001",
      "name": "Scene Writer",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.kie.ai/api/v1/veo/generate",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={\n  \"prompt\": \"{{ JSON.parse($('Scene Writer').first().json.choices[0].message.content).video_prompt.replace(/\\n/g, '\\\\n').replace(/\"/g, '\\\\\"') }}\",\n  \"model\": \"veo3_fast\",\n  \"aspectRatio\": \"{{ JSON.parse($('Scene Writer').first().json.choices[0].message.content).aspect_ratio_video }}\",\n  \"imageUrls\": \"https://api.telegram.org/file/bot{{ $env.TELEGRAM_BOT_TOKEN }}/{{ $('Get Img Path').first().json.result.file_path }}\"\n}\n",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 3000
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        400
      ],
      "id": "bo-createvideoA-0001",
      "name": "Create Video A (kie veo3_fast)",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 20
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1120,
        400
      ],
      "id": "bo-waitA-0001",
      "name": "Wait Video A"
    },
    {
      "parameters": {
        "url": "https://api.kie.ai/api/v1/veo/record-info",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "taskId",
              "value": "={{ $('Create Video A (kie veo3_fast)').item.json.data.taskId }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1340,
        400
      ],
      "id": "bo-getvideoA-0001",
      "name": "Get Video A",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "bo-vidA-success-1",
              "leftValue": "={{ $json.data.successFlag }}",
              "rightValue": 1,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            },
            {
              "id": "bo-vidA-success-2",
              "leftValue": "={{ $json.data.response.resultUrls[0] }}",
              "rightValue": 1,
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1560,
        400
      ],
      "id": "bo-ifAsuccess-0001",
      "name": "If A Success"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "bo-vidA-failed-1",
              "leftValue": "={{ $json.data.successFlag }}",
              "rightValue": 2,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            },
            {
              "id": "bo-vidA-failed-2",
              "leftValue": "={{ $json.data.successFlag }}",
              "rightValue": 3,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1780,
        300
      ],
      "id": "bo-ifAfailed-0001",
      "name": "If A Failed"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "text": "=A (kie veo3_fast) generation failed for task {{ $('Create Video A (kie veo3_fast)').item.json.data.taskId }}. Status code: {{ $json.data.successFlag }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2000,
        200
      ],
      "id": "bo-failAfailed-0001",
      "name": "Fail A Failed",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "bo-vidA-attempts-1",
              "leftValue": "={{ $runIndex }}",
              "rightValue": 30,
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1780,
        500
      ],
      "id": "bo-ifAattempts-0001",
      "name": "If A Attempts Left"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "text": "=A (kie veo3_fast) generation timed out for task {{ $('Create Video A (kie veo3_fast)').item.json.data.taskId }}.",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2000,
        600
      ],
      "id": "bo-failAtimeout-0001",
      "name": "Fail A Timeout",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "sendVideo",
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "file": "={{ $json.data.response.resultUrls[0] }}",
        "additionalFields": {
          "caption": "A: veo3_fast"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2220,
        300
      ],
      "id": "bo-sendvideoA-0001",
      "name": "Send Video A",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://queue.fal.run/fal-ai/kling-video/v3/standard/image-to-video",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"prompt\": \"{{ JSON.parse($('Scene Writer').first().json.choices[0].message.content).video_prompt.replace(/\\\"/g, '\\\\\\\"').replace(/\\n/g, '\\\\n') }}\",\n  \"image_url\": \"https://api.telegram.org/file/bot{{ $env.TELEGRAM_BOT_TOKEN }}/{{ $('Get Img Path').first().json.result.file_path }}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        800
      ],
      "id": "bo-createvideoB-0001",
      "name": "Create Video B (fal kling-3.0)",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 20
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1120,
        800
      ],
      "id": "bo-waitB-0001",
      "name": "Wait Video B"
    },
    {
      "parameters": {
        "url": "={{ $('Create Video B (fal kling-3.0)').item.json.response_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1340,
        800
      ],
      "id": "bo-getvideoB-0001",
      "name": "Get Video B",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "bo-vidB-ready-1",
              "leftValue": "={{ $json.video.url }}",
              "rightValue": 1,
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1560,
        800
      ],
      "id": "bo-ifBready-0001",
      "name": "If B Ready"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "bo-vidB-attempts-1",
              "leftValue": "={{ $runIndex }}",
              "rightValue": 30,
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1780,
        900
      ],
      "id": "bo-ifBattempts-0001",
      "name": "If B Attempts Left"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "text": "=B (fal kling-3.0) generation failed or timed out. fal request: {{ $('Create Video B (fal kling-3.0)').first().json.response_url }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2000,
        1000
      ],
      "id": "bo-failBtimeout-0001",
      "name": "Fail B Timeout",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "sendVideo",
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "file": "={{ $json.video.url }}",
        "additionalFields": {
          "caption": "B: kling-3.0"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2220,
        800
      ],
      "id": "bo-sendvideoB-0001",
      "name": "Send Video B",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Get Img Path",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Img Path": {
      "main": [
        [
          {
            "node": "In Progress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "In Progress": {
      "main": [
        [
          {
            "node": "Scene Writer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scene Writer": {
      "main": [
        [
          {
            "node": "Create Video A (kie veo3_fast)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Video B (fal kling-3.0)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Video A (kie veo3_fast)": {
      "main": [
        [
          {
            "node": "Wait Video A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait Video A": {
      "main": [
        [
          {
            "node": "Get Video A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video A": {
      "main": [
        [
          {
            "node": "If A Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If A Success": {
      "main": [
        [
          {
            "node": "Send Video A",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If A Failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If A Failed": {
      "main": [
        [
          {
            "node": "Fail A Failed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If A Attempts Left",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If A Attempts Left": {
      "main": [
        [
          {
            "node": "Wait Video A",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail A Timeout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Video B (fal kling-3.0)": {
      "main": [
        [
          {
            "node": "Wait Video B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait Video B": {
      "main": [
        [
          {
            "node": "Get Video B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video B": {
      "main": [
        [
          {
            "node": "If B Ready",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If B Ready": {
      "main": [
        [
          {
            "node": "Send Video B",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If B Attempts Left",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If B Attempts Left": {
      "main": [
        [
          {
            "node": "Wait Video B",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail B Timeout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "00000000-0000-4000-8000-000000000001",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodeGroups": [],
  "id": "ugcModelBakeoff01",
  "tags": []
}