{ "name": "Check a MiniMax H3 shot list against a video budget before rendering", "nodes": [ { "id": "aad408b0-b5ec-4e32-ab2d-d23d2327d64c", "name": "Start budget review", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ 0, 220 ], "parameters": {} }, { "id": "41a999df-5515-47fc-8ba7-a86985e834e7", "name": "Enter shot list, rates and cap", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 220, 220 ], "parameters": { "mode": "raw", "jsonOutput": "{\n \"project\": \"Harbour trailer\",\n \"budgetUsd\": 3,\n \"usdPerSecond\": {\n \"768P\": 0.078,\n \"2K\": 0.1268\n },\n \"shots\": [\n {\n \"shotId\": \"S010\",\n \"preset\": \"768P\",\n \"seconds\": 5,\n \"maxTakes\": 2\n },\n {\n \"shotId\": \"S020\",\n \"preset\": \"2K\",\n \"seconds\": 6,\n \"maxTakes\": 2\n },\n {\n \"shotId\": \"S030\",\n \"preset\": \"768P\",\n \"seconds\": 4,\n \"maxTakes\": 1\n }\n ]\n}", "options": {} } }, { "id": "b2343c5f-1056-4f2c-916b-26c269f8b612", "name": "Price first takes and retakes", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 470, 220 ], "parameters": { "mode": "runOnceForEachItem", "jsCode": "// n8n Code node in \"Run Once for Each Item\" mode. Monetary math uses integer microdollars.\nconst { project, budgetUsd, usdPerSecond, shots } = $json;\nconst issues = [];\nconst rows = [];\nconst seen = new Set();\n\nfunction microdollars(value) {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return null;\n const match = /^(\\d+)(?:\\.(\\d{1,6}))?$/.exec(String(value));\n if (!match) return null;\n const units = Number(match[1]) * 1000000 + Number((match[2] || '').padEnd(6, '0'));\n return Number.isSafeInteger(units) ? units : null;\n}\n\nconst cap = microdollars(budgetUsd);\nif (typeof project !== 'string' || !project.trim()) issues.push('Enter a project or batch name.');\nif (cap === null) issues.push('Enter a non-negative numeric USD budget with at most six decimal places.');\nif (!Array.isArray(shots) || !shots.length) issues.push('Add at least one shot.');\nconst rates = new Map();\nfor (const preset of ['768P', '2K']) {\n const rate = microdollars(usdPerSecond?.[preset]);\n if (rate !== null && rate > 0) rates.set(preset, rate);\n}\n\nlet firstPass = 0;\nlet fullBatch = 0;\nfor (const [i, shot] of (Array.isArray(shots) ? shots : []).entries()) {\n const label = 'Row ' + (i + 1);\n const id = typeof shot?.shotId === 'string' ? shot.shotId.trim() : '';\n const preset = typeof shot?.preset === 'string' ? shot.preset.trim().toUpperCase() : '';\n const rate = rates.get(preset);\n const seconds = shot?.seconds;\n const takes = shot?.maxTakes;\n const before = issues.length;\n if (!id) issues.push(label + ': enter a shot ID.');\n else if (seen.has(id.toUpperCase())) issues.push(label + ': duplicate shot ID ' + id + '.');\n if (id) seen.add(id.toUpperCase());\n if (!rate) issues.push(label + ': use 768P or 2K and set a positive USD rate for it.');\n if (!Number.isInteger(seconds) || seconds < 4 || seconds > 15) issues.push(label + ': seconds must be an integer from 4 to 15.');\n if (!Number.isSafeInteger(takes) || takes < 1) issues.push(label + ': maxTakes must count the first take and be a positive integer.');\n if (issues.length !== before) continue;\n const one = rate * seconds;\n const all = one * takes;\n if (!Number.isSafeInteger(firstPass + one) || !Number.isSafeInteger(fullBatch + all)) {\n issues.push(label + ': the amount is too large to calculate precisely.');\n continue;\n }\n firstPass += one;\n fullBatch += all;\n rows.push({project, shotId:id, preset, seconds, maxTakes:takes, firstTakeUsd:one/1000000, estimatedMaxUsd:all/1000000});\n}\nif (issues.length) return {json:{project, status:'invalid_input', issues}};\nreturn {json:{\n project, status: fullBatch <= cap ? 'within_budget' : 'over_budget',\n shotCount:rows.length, budgetUsd, firstPassUsd:firstPass/1000000,\n retakeAllowanceUsd:(fullBatch-firstPass)/1000000, estimatedMaxUsd:fullBatch/1000000,\n remainingUsd:(cap-fullBatch)/1000000, shots:rows\n}};\n" } }, { "id": "a91c4d10-b434-4d56-b929-b632f5bd11f8", "name": "Is the full batch within budget?", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [ 720, 220 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 }, "conditions": [ { "id": "b028ea4b-3d12-4d13-8744-eedefcde654e", "leftValue": "={{ $json.status }}", "rightValue": "within_budget", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "id": "bf8c16ac-ff8e-431e-b517-328d7bd23090", "name": "Release one budgeted item per shot", "type": "n8n-nodes-base.splitOut", "typeVersion": 1, "position": [ 1000, 140 ], "parameters": { "fieldToSplitOut": "shots", "options": {} } }, { "id": "853fc658-9bd1-4104-b355-e5731edf6f36", "name": "Hold batch for review", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 1000, 360 ], "parameters": {} }, { "id": "0dfc02ca-a2c1-4c37-87f3-b52134a68c81", "name": "Producer setup", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -70, -195 ], "parameters": { "width": 540, "height": 350, "color": 5, "content": "## Before you schedule any renders\n1. In **Enter shot list, rates and cap**, replace the sample with your project, USD spending limit, USD-per-output-second prices and shots. No credentials or services are required.\n2. Give each shot a unique ID, a preset (768P or 2K), a length from 4–15 seconds and the maximum number of billed takes **including the first take**.\n3. Execute the workflow. The sample budgets three shots at $2.6136 under a $3 cap. To test the hold branch, lower the cap to $2.60." } }, { "id": "b926210f-bc64-4c46-8f87-5e8d06bdffd4", "name": "Scope and price source", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 490, -195 ], "parameters": { "width": 655, "height": 335, "color": 7, "content": "## Reading the estimate\nThe pricing node lists first-pass cost, retake allowance, total and remaining budget. The true branch emits one item per shot. An invalid row or an over-budget batch goes to **Hold** as one item. Fix the input and run again. Re-running calculates the same plan and creates no render jobs.\n\nSample rates are from [Qianliu’s MiniMax-H3 price table](https://www.plusapi.cn/pricing?keyword=MiniMax-H3), Hailuo-2 group, checked 26 Nov 2026. The maintainer operates Qianliu. Use your own current prices. This estimate covers text-only video billed by output seconds. References, taxes, duration differences and unplanned retries can change the invoice." } } ], "connections": { "Start budget review": { "main": [ [ { "node": "Enter shot list, rates and cap", "type": "main", "index": 0 } ] ] }, "Enter shot list, rates and cap": { "main": [ [ { "node": "Price first takes and retakes", "type": "main", "index": 0 } ] ] }, "Price first takes and retakes": { "main": [ [ { "node": "Is the full batch within budget?", "type": "main", "index": 0 } ] ] }, "Is the full batch within budget?": { "main": [ [ { "node": "Release one budgeted item per shot", "type": "main", "index": 0 } ], [ { "node": "Hold batch for review", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" } }