{
  "id": "bNCOTEGacnSArXH1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Generate Sora AI videos, save to Google Drive, and update Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "1dde28b1-51ba-4713-ac09-c2647c99e643",
      "name": "Get Video Prompts from Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1008,
        -192
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1347410646,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg/edit#gid=1347410646",
          "cachedResultName": "Video prompts"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg/edit?usp=drivesdk",
          "cachedResultName": "example"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "c37861f9-f22a-4bd5-88d1-e866bc360047",
      "name": "Generate SEO Title with AI",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1008,
        112
      ],
      "parameters": {
        "text": "=Create an engaging, SEO-optimized YouTube title for this video.\n\nVideo prompt: {{ $json.prompt }}\nVideo duration: {{ $json.seconds }} seconds\n\nRequirements:\n- Maximum 60 characters\n- Include relevant keywords\n- Make it click-worthy but honest\n- No clickbait or misleading content\n\nReturn ONLY in JSON the title, prompt and video id, nothing else.\n\n{\n  \"title\": \"String\",\n  \"video_id\": \"{{ $json.id }}\",\n  \"prompt\": \"{{ $json.prompt }}\"\n}",
        "options": {
          "batching": {}
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "ecb76967-d724-4800-a909-9a2f5891cdd2",
      "name": "GPT-4 Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1008,
        256
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "dc2928b7-16f9-4562-8f71-bff509c22129",
      "name": "Create Sora Video Job",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -400,
        -224
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/videos",
        "method": "POST",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 3000
            }
          }
        },
        "jsonBody": "={\n  \"model\": \"sora-2\",\n  \"prompt\": \"{{ $json.PROMPT }}\",\n  \"size\": \"{{ $json['VIDEO RESOLUTION'] || '1280x720' }}\",\n  \"seconds\": \"{{ $json['DURATION (In Seconds)'] || 4 }}\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ebe9d79e-e2f7-41fc-89ed-eb19a96817c7",
      "name": "Wait 60s for Rendering",
      "type": "n8n-nodes-base.wait",
      "position": [
        -176,
        -224
      ],
      "parameters": {
        "amount": 60
      },
      "typeVersion": 1.1
    },
    {
      "id": "079e5dae-283e-4ee2-8e46-ade5f6d1c404",
      "name": "Check Video Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        32,
        -224
      ],
      "parameters": {
        "url": "=https://api.openai.com/v1/videos/{{ $json.id }}",
        "options": {
          "response": {
            "response": {}
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "74c63b08-554a-42ca-a343-24cd9e715e44",
      "name": "Download Completed Video",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -384,
        128
      ],
      "parameters": {
        "url": "=https://api.openai.com/v1/videos/{{ $json.output.video_id }}/content",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 3000
            }
          },
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0db202fa-63ec-4902-b834-15969ae901e2",
      "name": "Upload to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -192,
        128
      ],
      "parameters": {
        "name": "={{ $json.output.title }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "6d1ffdcc-8f77-4845-8d3e-e51e041aed26",
      "name": "Update video status to failed",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        448,
        -448
      ],
      "parameters": {
        "columns": {
          "value": {
            "PROMPT": "={{ $json.prompt }}",
            "STATUS": "={{ $json.status }} - {{ $json.error.message }}"
          },
          "schema": [
            {
              "id": "PROMPT",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "PROMPT",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "DURATION (In Seconds)",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "DURATION (In Seconds)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "VIDEO RESOLUTION",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "VIDEO RESOLUTION",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "VIDEO TITLE",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "VIDEO TITLE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "VIDEO URL",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "VIDEO URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "STATUS",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "STATUS",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "PROMPT"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1347410646,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg/edit#gid=1347410646",
          "cachedResultName": "Video prompts"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg/edit?usp=drivesdk",
          "cachedResultName": "example"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "e421556c-06f7-49b6-8b99-38b3db6dd644",
      "name": "Add video URL and update video status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        0,
        128
      ],
      "parameters": {
        "columns": {
          "value": {
            "PROMPT": "={{ $items('Download Completed Video')[$itemIndex].json.output.prompt }}",
            "STATUS": "Video Created",
            "VIDEO URL": "={{ $json.webViewLink }}",
            "VIDEO TITLE": "={{ $items('Download Completed Video')[$itemIndex].json.output.title }}"
          },
          "schema": [
            {
              "id": "PROMPT",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "PROMPT",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "DURATION (In Seconds)",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "DURATION (In Seconds)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "VIDEO RESOLUTION",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "VIDEO RESOLUTION",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "VIDEO TITLE",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "VIDEO TITLE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "VIDEO URL",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "VIDEO URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "STATUS",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "STATUS",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "PROMPT"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1347410646,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg/edit#gid=1347410646",
          "cachedResultName": "Video prompts"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qUir1c-_ScMnoYVoQ0W41nsv5IpLW6rjK8HUNqvNnAg/edit?usp=drivesdk",
          "cachedResultName": "example"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "d1f622d7-798c-4938-be86-1fee1f5a88c3",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        -496
      ],
      "parameters": {
        "color": 7,
        "width": 1088,
        "height": 496,
        "content": "# Step 2: Video Generation & Status Check\n### What happens\n- Creates a video generation job\n- Checks status\n- Updates a row in the sheet if video generation failed"
      },
      "typeVersion": 1
    },
    {
      "id": "2828a745-e4db-4f23-af75-7af364b1777a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1264,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 784,
        "height": 384,
        "content": "# Step 3: Title Generation\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9df35b7e-ef41-4481-9cff-0af991e92232",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 384,
        "content": "# Step 4: Save Results"
      },
      "typeVersion": 1
    },
    {
      "id": "12774248-cb91-4bfd-abeb-a0df17938e11",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -816,
        256
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"title\": \"String\",\n  \"video_id\": \"String\",\n  \"prompt\": \"String\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "9fa3cbfc-c153-4b7a-a2f4-d707cfb6b556",
      "name": "Filter Unprocessed Videos",
      "type": "n8n-nodes-base.filter",
      "position": [
        -816,
        -192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cdb72590-f2a0-48d2-a03d-c348c2315d13",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json.STATUS }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9f971063-863d-411f-ab97-6709fca2929a",
      "name": "Normalize Video Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        -640,
        -192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e49ca4dc-1d03-4565-b90b-7e6ab37dc49f",
              "name": "PROMPT",
              "type": "string",
              "value": "={{ $json.PROMPT }}"
            },
            {
              "id": "ff40b7b6-8f80-4db7-be76-0dcd05130715",
              "name": "DURATION (In Seconds)",
              "type": "number",
              "value": "={{ $json['DURATION (In Seconds)'] }}"
            },
            {
              "id": "2cb21356-894c-491a-bb88-bd27fb2c8473",
              "name": "VIDEO RESOLUTION",
              "type": "string",
              "value": "={{ $json['VIDEO RESOLUTION'] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2b605889-c159-46e9-946d-d99b9fe224dd",
      "name": "Route by Video Status",
      "type": "n8n-nodes-base.switch",
      "position": [
        256,
        -256
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1f6033f8-24cc-4ea3-91de-1f6e7ac6bc1d",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "failed"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "46623052-a0eb-4db5-8e15-ea5b361fff8c",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "queued"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "ceeb7e09-0859-4175-a9b4-ffe88e607288",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "in_progress"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "51d5c1bd-8194-4d42-915a-983fb227be90",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "completed"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "38735a14-e10d-449b-9502-649423671280",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1200,
        -192
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "7c0a346d-5fa2-4206-95e3-129eaad93a9c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1712,
        -496
      ],
      "parameters": {
        "width": 432,
        "height": 896,
        "content": "# Generate Sora AI videos, save to Google Drive, and update Google Sheets\n\nThis workflow automates video generation using OpenAI's Sora model:\n\n## How it works\n1. Reads video prompts from a Google Sheet\n2. Submits each prompt to Sora API for video generation\n3. Monitors video creation status with automatic retry logic\n4. Generates SEO-optimized titles using GPT-4\n5. Downloads completed videos and uploads to Google Drive\n6. Updates the sheet with video URLs and status\n\n\n## Setup Steps\n1. Create a Google Sheet with columns: PROMPT, DURATION (In Seconds), VIDEO RESOLUTION, VIDEO TITLE, VIDEO URL, STATUS\n2. Add your OpenAI API key (with Sora access) to credentials\n3. Connect your Google Sheets and Google Drive accounts\n4. Update the sheet ID in all Google Sheets nodes\n5. Run the workflow manually to process all unprocessed rows\n\n\n## Requirements\n- OpenAI API key with Sora access\n- Google Sheets OAuth2 credentials\n- Google Drive OAuth2 credentials"
      },
      "typeVersion": 1
    },
    {
      "id": "959325e8-2a51-4859-a206-d1ba891c44f5",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1264,
        -496
      ],
      "parameters": {
        "color": 7,
        "width": 784,
        "height": 496,
        "content": "# Step 1: Data Input & Filtering\n### What happens\n- Reads rows from the sheet\n- Filters eligible prompts\n- Normalizes fields used downstream"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3ee42dd5-b22b-4ca9-ba26-3d97d5b4584a",
  "connections": {
    "GPT-4 Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate SEO Title with AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Get Video Prompts from Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Video Status": {
      "main": [
        [
          {
            "node": "Route by Video Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Sora Video Job": {
      "main": [
        [
          {
            "node": "Wait 60s for Rendering",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Video Status": {
      "main": [
        [
          {
            "node": "Update video status to failed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 60s for Rendering",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 60s for Rendering",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate SEO Title with AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Google Drive": {
      "main": [
        [
          {
            "node": "Add video URL and update video status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 60s for Rendering": {
      "main": [
        [
          {
            "node": "Check Video Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Completed Video": {
      "main": [
        [
          {
            "node": "Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Generate SEO Title with AI",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Filter Unprocessed Videos": {
      "main": [
        [
          {
            "node": "Normalize Video Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate SEO Title with AI": {
      "main": [
        [
          {
            "node": "Download Completed Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Video Parameters": {
      "main": [
        [
          {
            "node": "Create Sora Video Job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video Prompts from Sheet": {
      "main": [
        [
          {
            "node": "Filter Unprocessed Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update video status to failed": {
      "main": [
        []
      ]
    },
    "Add video URL and update video status": {
      "main": [
        []
      ]
    }
  }
}