知识库 · AI 视频
n8n导入Sora2工作流指南
本指南详细介绍如何在n8n中导入并使用Sora2工作流。支持V1/V2版本,一键输入提示词自动生成视频链接。包含n8n.cloud及本地Docker安装方法、工作流导入、302.ai账号注册、节点配置及执行全流程。
n8n导入Sora2工作流指南
2025年12月16日修改
1.N8N Sora2工作流
1.1
工作流全景:
N8N工作流下载:
{
"name": "Sora2参考图生成视频V2",
"nodes": [
{
"parameters": {
"method": "POST",
"url": "https://api.302.ai/sora/v2/video",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "={{ $('302APIkey').item.json.key }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ $json.result }}",
"options": {}
},
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
-912,
80
],
"id": "ee1d0f9b-d32f-4aa9-b36b-4be2af084361",
"retryOnFail": true,
"waitBetweenTries": 5000
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n\n\nreturn {\"data\":$input.first().json.data.id};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-688,
80
],
"id": "e19317d7-791e-402d-8de9-41eb0d801b35",
"name": "Code"
},
{
"parameters": {
"url": "=https://api.302.ai/sora/v2/video/{{ $('Code').item.json.data }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "={{ $('302APIkey').item.json.key }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-464,
80
],
"id": "3c3f3ffc-122a-404b-a34f-c0b16e8ab7e2",
"name": "HTTP Request1",
"retryOnFail": true,
"waitBetweenTries": 5000
},
{
"parameters": {
"jsCode": "\n\nconst loopCount = 10000;\nconst result = [];\nvar soraId=$input.first().json.data.id;\nfor (let i = 0; i < loopCount; i++) {\n result.push({\n json: {\n loopIndex: i, // 当前循环索引(0 开始)\n data: soraId\n }\n });\n}\nreturn result;"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-240,
80
],
"id": "8c823a43-4279-4701-860f-67a38bd7befa",
"name": "Code1"
},
{
"parameters": {
"options": {}
},
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 3,
"position": [
-16,
64
],
"id": "4f5dbcac-abaa-40b7-a7c1-58f01acfad24",
"name": "Loop Over Items",
"alwaysOutputData": true,
"notesInFlow": true,
"retryOnFail": true,
"onError": "continueErrorOutput"
},
{
"parameters": {
"url": "=https://api.302.ai/sora/v2/video/{{ $json.data }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "={{ $('302APIkey').item.json.key }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
432,
0
],
"id": "f6fe2031-b4b5-4639-8868-96ef49e3eaef",
"name": "HTTP Request3",
"retryOnFail": true,
"waitBetweenTries": 5000
},
{
"parameters": {
"jsCode": "var result=$input.first().json.data.status;\nvar output=$input.first().json.data.outputs;\n\nvar flag=false;\nif(result=='completed'){\n if (output !== null && output !== undefined && output !== \"\") {\n flag=true;\n }\n}\nreturn {\"result\":flag};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
656,
0
],
"id": "66f67fd2-eca8-461e-bad5-e487af83b46f",
"name": "Code2",
"retryOnFail": true,
"waitBetweenTries": 5000
},
{
"parameters": {
"amount": 30
},
"type": "n8n-nodes-base.wait",
"typeVersion": 1.1,
"position": [
208,
0
],
"id": "8d1e2e66-d409-4e48-afc6-c22136c4b216",
"name": "Wait",
"webhookId": "39900841-0731-4a2c-8b1d-de6a402dbe67"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "2c62f6e3-4f42-4df9-8d2e-0974ef836822",
"leftValue": "={{ $json.result }}",
"rightValue": "",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
880,
80
],
"id": "7a406fc4-7285-4030-855e-322984fb88de",
"name": "If"
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n\nvar reuslt=$('HTTP Request3').first().json.data.outputs[0];\nreturn {\"reuslt\":reuslt};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1104,
80
],
"id": "64693211-797e-424f-845b-bcb9fd369b60",
"name": "Code3"
},
{
"parameters": {
"formTitle": "Sora2视频生成",
"formFields": {
"values": [
{
"fieldLabel": "prompt",
"placeholder": "输入需要生成视频的提示词",
"requiredField": true
},
{
"fieldLabel": "orientation",
"fieldType": "dropdown",
"fieldOptions": {
"values": [
{
"option": "9比16"
},
{
"option": "16比9"
}
]
}
},
{
"fieldLabel": "image",
"fieldType": "textarea",
"placeholder": "填写图片url链接"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.formTrigger",
"typeVersion": 2.2,
"position": [
-1552,
80
],
"id": "3e9acacf-a5c1-416a-a96c-62ca2248ddcd",
"name": "On form submission",
"webhookId": "ca43cdbd-55a5-4f36-b384-07585d5cad4a"
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nvar key=\"Bearer sk-xxxx\";\n\nreturn {\"key\":key};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-1344,
80
],
"id": "663bb6b7-213c-4c90-9868-e5cf9e9fed24",
"name": "302APIkey"
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n// 声明各个字段\nconst model = \"sora-2\";\nvar orientation = \"portrait\";\nconst prompt = $('On form submission').first().json.prompt;\nconst images = [];\n\nvar orientationTmp=$('On form submission').first().json.orientation;\nif(orientationTmp !== null && orientationTmp !== undefined && orientationTmp !== \"\"){\n if(orientationTmp=='9比16'){\n orientation = \"portrait\";\n }else{\n orientation = \"landscape\";\n }\n}\n\nvar imageTmp=$('On form submission').first().json.image;\nif(imageTmp !== null && imageTmp !== undefined && imageTmp !== \"\"){\n images.push(imageTmp);\n}\n\nconst result = {\n model: model,\n orientation: orientation,\n prompt: prompt,\n images: images\n};\n\nreturn {\"result\":result};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-1136,
80
],
"id": "75f3bf92-8bf4-4df1-b6da-cd244c68e206",
"name": "Code4"
}
],
"pinData": {},
"connections": {
"HTTP Request": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "HTTP Request1",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request1": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Code1": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Wait",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request3": {
"main": [
[
{
"node": "Code2",
"type": "main",
"index": 0
}
]
]
},
"Code2": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Wait": {
"main": [
[
{
"node": "HTTP Request3",
"type": "main",
"index": 0
}
]
]
},
"If": {
"main": [
[
{
"node": "Code3",
"type": "main",
"index": 0
}
],
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"On form submission": {
"main": [
[
{
"node": "302APIkey",
"type": "main",
"index": 0
}
]
]
},
"302APIkey": {
"main": [
[
{
"node": "Code4",
"type": "main",
"index": 0
}
]
]
},
"Code4": {
"main": [
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "12bdfbba-dfea-4cda-8ef5-27b3d19a0d08",
"meta": {
"instanceId": "b5a4cc62f1c7b11a7fc3395cfaa2e5485e75605819fe7473fb8e327a64b971fc"
},
"id": "3XrzfcXsNHa6UcCz",
"tags": [
{
"createdAt": "2025-10-02T22:09:59.087Z",
"updatedAt": "2025-10-02T22:09:59.087Z",
"id": "hYrrSlouttMg1Bk4",
"name": "Sora2"
}
]
}
更新说明:
只需要输入提示词程序自动生成视频链接,无需人工干预。
1.2
工作流全景:
N8N工作流下载:
{
"name": "Sora2参考图生成视频V5自动下载视频-By The Question",
"nodes": [
{
"parameters": {
"formTitle": "Sora2视频生成",
"formFields": {
"values": [
{
"fieldLabel": "prompt",
"placeholder": "输入需要生成视频的提示词",
"requiredField": true
},
{
"fieldLabel": "orientation",
"fieldType": "dropdown",
"fieldOptions": {
"values": [
{
"option": "9比16"
},
{
"option": "16比9"
}
]
}
},
{
"fieldLabel": "image",
"fieldType": "textarea",
"placeholder": "填写图片url链接"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.formTrigger",
"typeVersion": 2.2,
"position": [
-1808,
96
],
"id": "f2950d14-eaa5-4f5d-b1d6-40ffd8ee8ec5",
"name": "On form submission",
"webhookId": "ca43cdbd-55a5-4f36-b384-07585d5cad4a"
},
{
"parameters": {
"jsCode": "// 声明API Key,建议将此字段改为Environment Variable\nvar key=\"Bearer sk-XX\";\n\nreturn {\"key\":key};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-1600,
96
],
"id": "408416b1-82c0-45e1-98ac-b0a4c9cc143e",
"name": "302APIkey"
},
{
"parameters": {
"jsCode": "// 构造视频生成请求体\nconst model = \"sora-2\";\nvar orientation = \"portrait\";\nconst prompt = $('On form submission').first().json.prompt;\nconst images = [];\n\nvar orientationTmp=$('On form submission').first().json.orientation;\nif(orientationTmp !== null && orientationTmp !== undefined && orientationTmp !== \"\"){\n if(orientationTmp=='9比16'){\n orientation = \"portrait\";\n }else{\n orientation = \"landscape\";\n }\n}\n\nvar imageTmp=$('On form submission').first().json.image;\nif(imageTmp !== null && imageTmp !== undefined && imageTmp !== \"\"){\n images.push(imageTmp);\n}\n\nconst result = {\n model: model,\n orientation: orientation,\n prompt: prompt,\n images: images\n};\n\nreturn {\"result\":result};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-1392,
96
],
"id": "e041c66f-e190-4cb9-9f57-b67e834ddcf4",
"name": "Code4 - Prepare Body"
},
{
"parameters": {
"method": "POST",
"url": "https://api.302.ai/sora/v2/video",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "={{ $('302APIkey').item.json.key }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ $('Code4 - Prepare Body').item.json.result }}",
"options": {}
},
"name": "HTTP Request - Submit Job",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
-1168,
96
],
"id": "32ae3351-a2c0-4adb-9e26-58e67fc52168",
"retryOnFail": true,
"waitBetweenTries": 5000
},
{
"parameters": {
"jsCode": "return {\"data\":$input.first().json.data.id};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-944,
96
],
"id": "102c5b84-f094-45da-aef9-b8fbda52036e",
"name": "Code - Extract Job ID"
},
{
"parameters": {
"url": "=https://api.302.ai/sora/v2/video/{{ $('Code - Extract Job ID').item.json.data }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "={{ $('302APIkey').item.json.key }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-720,
96
],
"id": "7ca37011-ae23-43bd-968d-444aacab2081",
"name": "HTTP Request - Get Status (Initial)"
},
{
"parameters": {
"jsCode": "const loopCount = 10000;\nconst result = [];\nvar soraId=$input.first().json.data.id;\nfor (let i = 0; i < loopCount; i++) {\n result.push({\n json: {\n loopIndex: i,\n data: soraId\n }\n });\n}\nreturn result;"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-496,
96
],
"id": "d76a64d2-d8fe-4520-bbf1-a6b1d03a601b",
"name": "Code1 - Loop Prep"
},
{
"parameters": {
"options": {}
},
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 3,
"position": [
-272,
80
],
"id": "8976cc2f-cb50-4484-b615-bc94f1265b7b",
"name": "Loop Over Items",
"alwaysOutputData": true,
"notesInFlow": true,
"retryOnFail": true,
"onError": "continueErrorOutput"
},
{
"parameters": {
"url": "=https://api.302.ai/sora/v2/video/{{ $json.data }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "={{ $('302APIkey').item.json.key }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
176,
16
],
"id": "347a2b1b-02b6-475f-bced-0b8bfc6c84be",
"name": "HTTP Request - Check Status"
},
{
"parameters": {
"jsCode": "var status=$input.first().json.data.status;\nvar output=$input.first().json.data.outputs;\n\nvar isCompleted=false;\nif(status=='completed'){\n // 检查outputs字段是否存在且非空\n if (Array.isArray(output) && output.length > 0) {\n isCompleted=true;\n }\n}\nreturn {\"isCompleted\":isCompleted};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
400,
16
],
"id": "82d841bc-0584-47ac-bdaa-501dcfb37c08",
"name": "Code2 - Check Output"
},
{
"parameters": {
"amount": 30
},
"type": "n8n-nodes-base.wait",
"typeVersion": 1.1,
"position": [
-48,
16
],
"id": "4d03663a-09a4-46b1-8a82-c62eb90df507",
"name": "Wait 30s",
"webhookId": "39900841-0731-4a2c-8b1d-de6a402dbe67"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "2c62f6e3-4f42-4df9-8d2e-0974ef836822",
"leftValue": "={{ $json.isCompleted }}",
"rightValue": "",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
624,
96
],
"id": "b1262b8d-67b4-4d10-bb46-44623e861ff0",
"name": "If - Completed"
},
{
"parameters": {
"jsCode": "const outputs = $('HTTP Request - Check Status').first().json.data.outputs;\nconst videoUrl = outputs && outputs.length > 0 ? outputs[0] : null;\n\n// 获取当前北京时间\nconst nowInShanghai = $now.setZone('Asia/Shanghai');\n\n// 格式化时间戳作为文件名:YYYYLLdd_HHmmss\nconst timeStamp = nowInShanghai.toFormat('yyyyLLdd_HHmmss');\n\n// 生成唯一文件名\nconst fileName = `Sora2_${timeStamp}.mp4`;\n\n// 基目录路径,直接保存到 downloads 根目录\nconst baseDir = '/data/downloads';\n\n// 完整的保存路径和文件名\nconst fullFilePath = `${baseDir}/${fileName}`;\n\nreturn [{\n json: {\n videoUrl: videoUrl,\n fullFilePath: fullFilePath\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
848,
96
],
"id": "bb8fee20-a849-4637-863f-a0215d87e864",
"name": "Code - Prepare Path"
},
{
"parameters": {
"url": "={{ $json.videoUrl }}",
"options": {
"response": {
"response": {
"responseFormat": "file"
}
}
}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1056,
16
],
"id": "65da7f25-e3e5-47b1-a481-5f9c4d6f0a60",
"name": "HTTP Download"
},
{
"parameters": {
"operation": "write",
"fileName": "={{ $binary.data.fileName }}",
"options": {
"append": false
}
},
"type": "n8n-nodes-base.readWriteFile",
"typeVersion": 1,
"position": [
1424,
32
],
"id": "9848581d-b813-46f1-a5fe-c9960b03c1f2",
"name": "Read/Write Files from Disk"
},
{
"parameters": {
"jsCode": "// 确保输入项存在\nconst item = $input.first();\n\n// 检查上一个 HTTP 节点是否正确输出了名为 'data' 的二进制数据\nconst binaryData = item.binary?.data;\n\nif (!binaryData) {\n throw new Error('HTTP Download 节点未输出二进制文件数据 (binary.data)。请检查该节点设置的 Response Format 是否为 \"File\"');\n}\n\n// *** 关键步骤:将完整路径赋值给二进制数据的 fileName 属性 ***\nbinaryData.fileName = item.json.fullFilePath; \n\n// 返回一个包含原始JSON和处理后的二进制数据的Item\nreturn [{ json: item.json, binary: { data: binaryData } }];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1232,
32
],
"id": "7878e676-8afb-48ec-8308-d75434c2e533",
"name": "Code - Binary Fix"
}
],
"pinData": {},
"connections": {
"HTTP Request - Submit Job": {
"main": [
[
{
"node": "Code - Extract Job ID",
"type": "main",
"index": 0
}
]
]
},
"Code - Extract Job ID": {
"main": [
[
{
"node": "HTTP Request - Get Status (Initial)",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request - Get Status (Initial)": {
"main": [
[
{
"node": "Code1 - Loop Prep",
"type": "main",
"index": 0
}
]
]
},
"Code1 - Loop Prep": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Wait 30s",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request - Check Status": {
"main": [
[
{
"node": "Code2 - Check Output",
"type": "main",
"index": 0
}
]
]
},
"Code2 - Check Output": {
"main": [
[
{
"node": "If - Completed",
"type": "main",
"index": 0
}
]
]
},
"Wait 30s": {
"main": [
[
{
"node": "HTTP Request - Check Status",
"type": "main",
"index": 0
}
]
]
},
"If - Completed": {
"main": [
[
{
"node": "Code - Prepare Path",
"type": "main",
"index": 0
}
],
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"On form submission": {
"main": [
[
{
"node": "302APIkey",
"type": "main",
"index": 0
}
]
]
},
"302APIkey": {
"main": [
[
{
"node": "Code4 - Prepare Body",
"type": "main",
"index": 0
}
]
]
},
"Code4 - Prepare Body": {
"main": [
[
{
"node": "HTTP Request - Submit Job",
"type": "main",
"index": 0
}
]
]
},
"Code - Prepare Path": {
"main": [
[
{
"node": "HTTP Download",
"type": "main",
"index": 0
}
]
]
},
"HTTP Download": {
"main": [
[
{
"node": "Code - Binary Fix",
"type": "main",
"index": 0
}
]
]
},
"Code - Binary Fix": {
"main": [
[
{
"node": "Read/Write Files from Disk",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "0c5f715b-c1d5-4474-b00f-74adb79a501b",
"meta": {
"instanceId": "e6ac06855c8649c5dbf73b8eca0c0591ef2aa9c16740eba8311ff902d986b5b5"
},
"id": "1LEMQkhkrqusroF3",
"tags": []
}
更新说明:
2.n8n安装
目前n8n安装方式主流分2种,一种是使用n8n.cloud在线版本,可以免费使用15天,适合没有接触过n8n的新手玩家。对于资深玩家,建议使用docker方式,一劳永逸。下面会分别讲解n8n.cloud和docker运行的两种方式。
2.1N8N.cloud方式安装
2.2N8N本地docker安装(涉及The Question的可自动下载的模板配置),可选
2.2.1windows版docker desktop
Windows版Docker下载地址
2.2.2windows进入powershell输入如下命令:
注意(非常重要,关系到你如何自动下载到本地):
-v "D:\n8n:/home/node/.n8n" ` 中的“D:\n8n”改为你自己的文件夹路径。用于映射n8n配置文件
-v "D:\n8n\videos:/data/downloads" ` 中的“D:\n8n\videos”改为你自己存放下载视频的路径。用于存放后续要下载的视频文件
Docker容器创建命令
docker run -d `
--name n8n1 `
--restart unless-stopped `
-p 5678:5678 `
-e GENERIC_TIMEZONE="Asia/Shanghai" `
-e TZ="Asia/Shanghai" `
-e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true `
-e N8N_RUNNERS_ENABLED=true `
-e N8N_LOG_LEVEL=info `
-e N8N_SECURE_COOKIE=false `
-v "D:\n8n:/home/node/.n8n" `
-v "D:\n8n\videos:/data/downloads" `
docker.n8n.io/n8nio/n8n:latest2.2.3
注意:docker安装中网络问题等可自行网络搜索
具体教程可取搜索n8n的docker安装