{
  "name": "Product photo to video ad with Nano Banana Pro and Kling 3 (MegaBrain)",
  "nodes": [
    {
      "parameters": {
        "content": "# Product photo → video ad\nUpload-free UGC ad pipeline: paste a product photo URL and one line about the product.\n1. A free text model writes the scene.\n2. **Nano Banana Pro Edit** puts the product into a lifestyle shot (keeps the label).\n3. **Kling 3** animates that shot into a vertical 5-second clip.\n\nCost: about $0.17 for the image + $0.48 for 5 s of video.\n\n## Setup (2 minutes)\n1. Get a key at [getmegabrain.com/keys](https://getmegabrain.com/keys).\n2. In n8n create a **Header Auth** credential named `MegaBrain API key`:\n   - Name: `Authorization`\n   - Value: `Bearer YOUR_KEY`\n3. Pick it in every HTTP Request node with the 🔑 mark.\n\nFailed jobs are refunded automatically. Prices: [getmegabrain.com/docs/media](https://getmegabrain.com/docs/media).",
        "height": 620,
        "width": 440
      },
      "id": "30c73f84-6de8-5c70-a823-15690b0094ee",
      "name": "About",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        -300
      ]
    },
    {
      "parameters": {
        "formTitle": "Product photo → video ad",
        "formDescription": "Paste a public link to a product photo. The video link appears here in 2–4 minutes.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Product photo URL",
              "requiredField": true,
              "placeholder": "https://…/bottle.png"
            },
            {
              "fieldLabel": "Product",
              "requiredField": true,
              "placeholder": "cold brew coffee in a glass bottle"
            },
            {
              "fieldLabel": "Audience",
              "placeholder": "busy students"
            }
          ]
        },
        "options": {}
      },
      "id": "dade61fb-aff4-535d-9165-bb44b99a41eb",
      "name": "Product form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "261c71a1-4009-5b3c-86c2-56c857418645"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://getmegabrain.com/api/gateway/v1/chat/completions",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'mb-auto/free', response_format: { type: 'json_object' }, messages: [ { role: 'system', content: 'You direct short UGC-style product ads. Reply with JSON only: {\"image_prompt\": how to place the product from the photo in a realistic lifestyle scene, keep the product and its label unchanged, \"video_prompt\": what happens in 5 seconds, natural handheld phone camera, one simple action}' }, { role: 'user', content: `Product: ${$json.Product}. Audience: ${$json.Audience || 'everyone'}` } ] }) }}",
        "options": {
          "timeout": 120000
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "id": "7f4eae98-2761-5de1-be2c-078f5cd511fa",
      "name": "Write the scene (free model)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ],
      "retryOnFail": true,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "jsCode": "const raw = $input.first().json.choices[0].message.content;\nconst text = raw.replace(/^```(?:json)?\\s*/i, '').replace(/```\\s*$/, '').trim();\nreturn [{ json: JSON.parse(text) }];"
      },
      "id": "ad40323b-8b46-5219-9df0-6e1777721d3d",
      "name": "Parse the scene",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://getmegabrain.com/api/gateway/v1/images/generations",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'nano-banana-pro/edit', prompt: $json.image_prompt, image_urls: [ $('Product form').item.json['Product photo URL'] ], aspect_ratio: '9:16', resolution: '1K' }) }}",
        "options": {
          "timeout": 120000
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "id": "3e472ac4-66d3-5973-82c5-1124e0819b15",
      "name": "Lifestyle shot (Nano Banana Pro Edit)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://getmegabrain.com/api/gateway/v1/queue/kling-video/v3/standard/image-to-video",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ prompt: $('Parse the scene').item.json.video_prompt, start_image_url: $json.image_url, duration: '5', generate_audio: false }) }}",
        "options": {
          "timeout": 120000
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "id": "642c5d04-21e0-5123-a914-784c84311e1e",
      "name": "Submit Kling 3 image-to-video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        -100
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6fdc204d-3ecb-544e-a937-ad02a505b491",
              "name": "video_url",
              "value": "={{ $json.video.url }}",
              "type": "string"
            },
            {
              "id": "b941d3d0-0da1-5331-b381-b0e0323bb422",
              "name": "image_url",
              "value": "={{ $('Shot URL').item.json.image_url }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "ff9350d7-a30b-5030-b079-b12ff49f10f0",
      "name": "Ad links",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2460,
        -220
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "9ae1d9fd-6c22-51e2-975d-0c8d82f7a1aa",
              "leftValue": "={{ $json.data?.[0]?.url ?? $json.images?.[0]?.url ?? '' }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "db4ab9a2-7bdf-5b09-850e-aab94376ec66",
      "name": "Shot ready?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5b80f4e9-66e5-5892-b040-dc92b412ef1b",
              "name": "image_url",
              "value": "={{ $json.data?.[0]?.url ?? $json.images?.[0]?.url ?? '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "31f3ccde-af5a-5e4d-832a-faf76c038da9",
      "name": "Shot URL",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1100,
        -100
      ]
    },
    {
      "parameters": {
        "amount": 10
      },
      "id": "ca40ceda-1fb4-5bf1-aecb-e9b907d01f7b",
      "name": "Queued: wait 10s (Shot)",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1100,
        120
      ],
      "webhookId": "31caa5c6-1fea-5f5f-b75b-f18af39c4e87"
    },
    {
      "parameters": {
        "url": "={{ $json.response_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000
        }
      },
      "id": "78a37de4-9a8e-5823-9ecc-3d7313dbf9e1",
      "name": "Fetch queued shot",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        120
      ]
    },
    {
      "parameters": {
        "amount": 15
      },
      "id": "8ebfacd8-205d-57d2-90fd-d4245878ed2b",
      "name": "Wait 15s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1540,
        -100
      ],
      "webhookId": "4e7d4fe9-a220-5602-84a0-4ef5a4bb7196"
    },
    {
      "parameters": {
        "url": "={{ $('Submit Kling 3 image-to-video').item.json.status_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000
        }
      },
      "id": "948c043f-02ca-5bde-b64a-9c48a1952c6e",
      "name": "Get video status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1760,
        -100
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "COMPLETED",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Completed"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "FAILED",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Failed"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Running"
        }
      },
      "id": "9c3d6e5f-a952-562e-b415-161e71e59c60",
      "name": "Done yet?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1980,
        -100
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Submit Kling 3 image-to-video').item.json.response_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000
        }
      },
      "id": "80851bab-2a7c-5a23-af11-184dd7964b74",
      "name": "Get video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2240,
        -220
      ]
    },
    {
      "parameters": {
        "errorMessage": "=The video job failed. MegaBrain returned the price to your balance. Request: {{ $('Submit Kling 3 image-to-video').item.json.request_id }}"
      },
      "id": "09912ad2-0801-5a19-ab74-635813a5e1c4",
      "name": "Job failed (refunded)",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        2240,
        -40
      ]
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "=<div style=\"font-family:system-ui,-apple-system,sans-serif;max-width:640px;margin:48px auto;padding:24px;line-height:1.5\"><h2>Your ad is ready</h2><p><a href=\"{{ $json.video_url }}\" target=\"_blank\">Open the video</a> · <a href=\"{{ $json.image_url }}\" target=\"_blank\">Open the image</a></p><p><video src=\"{{ $json.video_url }}\" controls style=\"max-width:100%\"></video></p></div>"
      },
      "id": "a2b5d1f4-9155-5233-b043-17d524197737",
      "name": "Show the ad",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.3,
      "position": [
        2680,
        -220
      ],
      "webhookId": "04e2eba3-66b8-5d1b-af9a-049c1dce56b6"
    },
    {
      "parameters": {
        "content": "## 1. Scene\nThe free model writes two prompts as JSON: the lifestyle shot and a 5-second action. The photo URL must be public (no login, no Google Drive preview links).",
        "height": 220,
        "width": 420,
        "color": 5
      },
      "id": "0a763695-2414-56cd-98c0-2211c8e0e267",
      "name": "Note: scene",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        160,
        -300
      ]
    },
    {
      "parameters": {
        "content": "## 2. Shot, then video\n**Nano Banana Pro Edit** keeps the product and label from the photo. The shot feeds **Kling 3 image-to-video**; the loop polls the job every 15 s and the form shows both links.",
        "height": 200,
        "width": 560,
        "color": 5
      },
      "id": "23a775d4-b762-5117-9b46-6deb67ebf5f3",
      "name": "Note: shot and video",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        840,
        -420
      ]
    }
  ],
  "connections": {
    "Product form": {
      "main": [
        [
          {
            "node": "Write the scene (free model)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the scene (free model)": {
      "main": [
        [
          {
            "node": "Parse the scene",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse the scene": {
      "main": [
        [
          {
            "node": "Lifestyle shot (Nano Banana Pro Edit)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lifestyle shot (Nano Banana Pro Edit)": {
      "main": [
        [
          {
            "node": "Shot ready?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shot ready?": {
      "main": [
        [
          {
            "node": "Shot URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Queued: wait 10s (Shot)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Queued: wait 10s (Shot)": {
      "main": [
        [
          {
            "node": "Fetch queued shot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch queued shot": {
      "main": [
        [
          {
            "node": "Shot ready?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shot URL": {
      "main": [
        [
          {
            "node": "Submit Kling 3 image-to-video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit Kling 3 image-to-video": {
      "main": [
        [
          {
            "node": "Wait 15s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 15s": {
      "main": [
        [
          {
            "node": "Get video status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get video status": {
      "main": [
        [
          {
            "node": "Done yet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Done yet?": {
      "main": [
        [
          {
            "node": "Get video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Job failed (refunded)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 15s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get video": {
      "main": [
        [
          {
            "node": "Ad links",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ad links": {
      "main": [
        [
          {
            "node": "Show the ad",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
