#!/usr/bin/env node // Builds the exact model requests for one stage of the reel from reel.json and prints them // (or writes one JSON file per request with --out). It calls no API. // Each request is { id, model, input, approx_cost_usd }: POST `input` to fal model `model` with your // own FAL_KEY (scripts/fal-run.mjs does this), or paste the prompt and images into any // Nano-Banana-class image editor / Veo-class image-to-video tool with sound. // // Stages: // estimate no requests: the expected total for the whole reel, to quote to the user and get one // yes on before the first paid call // keyframe shot 1 first (the object remade in the material, whole), then shots 2-3 // with the approved shot 1 still (and the product photo) as references // poised the start frame for shot 1's video: the shot 1 still plus the shot 2 knife, its edge // just above the cut line (needs approved shot 1 and 2 keyframes; put the result in // shot 1's poised_keyframe). It is also the loop frame. // draft the sound test: one 4 s Veo 3.1 fast clip with audio (default shot 1), to hear the // material and check the frame is accepted before paying for finals // final one 6 s Veo 3.1 fast clip with audio per shot // // Usage: // node scripts/build-requests.mjs --reel reel.json --stage estimate|keyframe|poised|draft|final // [--shot 1|2|3|all] [--out requests/] [--inline] [--resolution 720p|1080p] // // --inline embeds local images as data URIs (needs --out), so no photo goes on a public URL. // Node 18 or newer. No npm packages. import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs' import { dirname, extname, isAbsolute, join, resolve } from 'node:path' const FLAGS = new Set(['reel', 'stage', 'shot', 'out', 'inline', 'resolution']) const SWITCHES = new Set(['inline']) const MODELS = { image: 'openai/gpt-image-2', edit: 'fal-ai/nano-banana-pro/edit', video: 'fal-ai/veo3.1/fast/image-to-video', } // fal list prices, checked 2026-11-09 (fal.ai/models//llms.txt). Veo 3.1 fast: $0.15/s with audio // at 720p or 1080p ($0.10/s silent). Nano Banana Pro edit: $0.15 per 1K or 2K image. GPT Image 2 is // token-billed: medium is about $0.05 per 1024 x 1024, so about $0.07 at 864 x 1536 and $0.12 at 1152 x 2048. const PRICE = { edit: 0.15, image: { '720p': 0.07, '1080p': 0.12 }, videoPerSecond: 0.15, } const VEO_DURATIONS = [4, 6, 8] const TEST_SECONDS = 4 const NEGATIVE = 'music, singing, voices, speech, whispering, breathing, people, faces, bare hands, bare skin, fingers near the blade, blood, animals, text, captions, subtitles, letters, logos, watermark, cuts, scene change' const MIME = { '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.webp': 'image/webp' } function fail(message) { console.error(message) process.exit(1) } const opts = {} const argv = process.argv.slice(2) for (let i = 0; i < argv.length; i++) { const a = argv[i] if (!a.startsWith('--')) fail(`Unexpected argument "${a}". Flags look like --name value.`) const key = a.slice(2) if (!FLAGS.has(key)) fail(`Unknown flag --${key}. Allowed: ${[...FLAGS].map((f) => `--${f}`).join(', ')}`) if (SWITCHES.has(key)) { opts[key] = true; continue } const value = argv[i + 1] if (value === undefined || value.startsWith('--')) fail(`--${key} needs a value.`) opts[key] = value i++ } if (!opts.reel || !opts.stage) fail('Usage: node scripts/build-requests.mjs --reel reel.json --stage estimate|keyframe|poised|draft|final [--shot N|all] [--out dir] [--inline]') if (!['estimate', 'keyframe', 'poised', 'draft', 'final'].includes(opts.stage)) fail(`--stage must be estimate, keyframe, poised, draft or final, not "${opts.stage}".`) if (opts.inline && !opts.out) fail('--inline writes large data URIs; use it with --out .') if (!existsSync(opts.reel)) fail(`Shot list not found: ${opts.reel}. Create it with scripts/build-shot-list.mjs.`) let reel try { reel = JSON.parse(readFileSync(opts.reel, 'utf8')) } catch { fail(`${opts.reel} is not valid JSON.`) } const base = dirname(resolve(opts.reel)) const rel = (p) => (isAbsolute(p) ? p : join(base, p)) const brief = reel.brief ?? {} const locks = reel.locks ?? {} const res = opts.resolution ?? brief.final_resolution ?? '720p' if (!['720p', '1080p'].includes(res)) fail(`--resolution must be 720p or 1080p, not "${res}".`) const hasPhoto = Boolean(reel.references?.photo) // GPT Image 2 sizes: multiples of 16, at or above the video size (Veo wants 720p or more, 9:16). const GPT_SIZE = res === '1080p' ? { width: 1152, height: 2048 } : { width: 864, height: 1536 } const unfilled = (text) => typeof text === 'string' && text.includes('FILL:') function fillTokens(text, where) { if (typeof text !== 'string' || !text.trim()) fail(`${where} is empty. Write it in reel.json first.`) if (unfilled(text)) fail(`${where} still contains "FILL:". Write it in reel.json first.`) const tokens = { OBJECT: locks.object, MATERIAL: locks.material, MATERIAL_NAME: locks.material_name, INSIDE: locks.inside, SET: locks.set } return text.replace(/\{\{(OBJECT|MATERIAL_NAME|MATERIAL|INSIDE|SET)\}\}/g, (_, name) => { const value = tokens[name] if (!value || unfilled(value)) fail(`${where} uses {{${name}}} but locks.${name.toLowerCase()} is not written yet.`) return value.trim().replace(/[.]$/, '') }) } function imageRef(path, what) { const abs = rel(path) if (!existsSync(abs)) fail(`${what} not found: ${abs}`) const ext = extname(abs).toLowerCase() if (!MIME[ext]) fail(`${what} must be a .jpg, .png or .webp image, not ${ext || 'a file without extension'}.`) if (!opts.inline) return `file:${abs}` if (statSync(abs).size > 8 * 1024 * 1024) fail(`${what} is over 8 MB. Save it as a JPEG under 8 MB first.`) return `data:${MIME[ext]};base64,${readFileSync(abs).toString('base64')}` } const shots = (reel.shots ?? []).filter((s) => !s.skip) if (!shots.length) fail('The shot list has no shots.') const money = (n) => `$${n.toFixed(2)}` if (opts.stage === 'estimate') { for (const s of shots) if (!VEO_DURATIONS.includes(Number(s.duration))) fail(`shot ${s.n} duration must be 4, 6 or 8 (Veo 3.1 fast lengths), not "${s.duration}".`) const first = hasPhoto ? PRICE.edit : PRICE.image[res] const poised = shots.some((s) => s.poised_prompt) ? PRICE.edit : 0 const keyframes = first + (shots.length - 1) * PRICE.edit + poised const test = TEST_SECONDS * PRICE.videoPerSecond const seconds = shots.reduce((a, s) => a + Number(s.duration), 0) const finals = seconds * PRICE.videoPerSecond const lines = [ [`Keyframes: ${shots.length + (poised ? 1 : 0)} stills${poised ? ' (incl. the poised knife frame for shot 1)' : ''} (${hasPhoto ? 'Nano Banana Pro edit' : 'GPT Image 2 medium, then Nano Banana Pro edit'})`, keyframes], [`Sound test: ${TEST_SECONDS} s on Veo 3.1 fast ${res} with audio`, test], [`Finals: ${seconds} s on Veo 3.1 fast ${res} with audio`, finals], ] const total = keyframes + test + finals // One re-rolled final and one re-rolled keyframe. const reroll = Number(shots[0].duration) * PRICE.videoPerSecond + PRICE.edit for (const [label, v] of lines) console.log(` ${label.padEnd(66)} ${money(v)}`) console.log(` ${'Without re-rolls'.padEnd(66)} ${money(total)}`) console.log(` ${'With one re-rolled final and one re-rolled keyframe'.padEnd(66)} ${money(total + reroll)}`) console.log(`\nQuote to the user: about $${Math.round(total)}-${Math.ceil(total + reroll)} including a re-roll (the finals are ${money(finals)} of it).`) console.log('Get one explicit yes on this total before the first paid call, and ask again if it will be exceeded.') process.exit(0) } let picked = shots if (opts.stage === 'poised') { const first = shots[0] const second = shots[1] if (!first.poised_prompt) fail('Shot 1 has no poised_prompt: the poised stage is for cut reels made with a recent build-shot-list.mjs.') if (!first.keyframe || !second?.keyframe) fail('The poised frame needs approved shot 1 and shot 2 keyframes. Make and approve those first.') const refs = [imageRef(first.keyframe, 'Shot 1 keyframe'), imageRef(second.keyframe, 'Shot 2 keyframe')] const looks = `${locks.look ?? ''} Photorealistic material and true-to-life scale. No people, no faces, no animals. No text, no letters, no logos, no watermark.` const prompt = `A vertical 9:16 macro still frame from a satisfying ASMR cutting video. ${fillTokens(first.poised_prompt, 'shot 1 poised_prompt')} ${looks}`.replace(/\s+/g, ' ').trim() const r = { id: `${first.id}-poised`, model: MODELS.edit, input: { prompt, image_urls: refs, aspect_ratio: '9:16', resolution: '2K', num_images: 1, output_format: 'jpeg' }, approx_cost_usd: PRICE.edit } if (opts.out) { mkdirSync(opts.out, { recursive: true }) writeFileSync(join(opts.out, `${r.id}.json`), JSON.stringify(r, null, 2)) console.log(`Wrote 1 request(s) to ${opts.out}. Approximate cost: ${money(r.approx_cost_usd)}.`) } else console.log(JSON.stringify([r], null, 2)) process.exit(0) } if (opts.stage === 'draft' && !opts.shot) picked = shots.slice(0, 1) if (opts.shot && opts.shot !== 'all') { const n = Number(opts.shot) if (!Number.isInteger(n)) fail(`--shot takes a shot number or "all", not "${opts.shot}".`) picked = shots.filter((s) => s.n === n) if (!picked.length) fail(`There is no shot ${n} in the shot list.`) } const lookLine = `${locks.look ?? ''} Photorealistic material and true-to-life scale. No people, no faces, no animals. No text, no letters, no logos, no watermark.` const logoLine = brief.keep_logo ? 'Keep the product\'s own logo from the product photo exactly, letter for letter, in the same place; no other text anywhere.' : 'Leave any label or logo area plain, with no letters.' const requests = [] for (const s of picked) { const where = `shot ${s.n}` if (opts.stage === 'keyframe') { const refs = [] const lines = [] if (s.use_first_frame_ref) { const first = shots[0] if (first === s) fail(`${where} cannot use itself as the first-frame reference. Set use_first_frame_ref to false on shot 1.`) if (!first.keyframe) fail(`${where} uses the shot 1 still as its reference, but shot 1 has no approved keyframe yet. Generate shot 1 first, look at it, and put its path in "keyframe".`) refs.push(imageRef(first.keyframe, 'Shot 1 keyframe')) lines.push(`Reference image ${refs.length} is the approved first frame: the same object, the same material, the same board, backdrop and light.`) } if (hasPhoto) { refs.push(imageRef(reel.references.photo, 'Product photo')) lines.push(`Reference image ${refs.length} is the real product: keep its exact shape, proportions, parts and colours, but remade entirely in the material. ${logoLine}`) } else { lines.push('No label and no lettering anywhere on the object.') } const prompt = `A vertical 9:16 macro still frame from a satisfying ASMR cutting video. ${fillTokens(s.keyframe_prompt, `${where} keyframe_prompt`)} ${lines.join(' ')} ${lookLine}`.replace(/\s+/g, ' ').trim() if (refs.length) { const input = { prompt, image_urls: refs, aspect_ratio: '9:16', resolution: '2K', num_images: 1, output_format: 'jpeg' } requests.push({ id: `${s.id}-keyframe`, model: MODELS.edit, input, approx_cost_usd: PRICE.edit }) } else { const input = { prompt, image_size: GPT_SIZE, quality: 'medium', num_images: 1, output_format: 'jpeg' } requests.push({ id: `${s.id}-keyframe`, model: MODELS.image, input, approx_cost_usd: PRICE.image[res] }) } } else { if (!s.keyframe) fail(`${where} has no approved keyframe yet. Generate it, look at it, and put its path in "keyframe".`) if (s.poised_prompt && !s.poised_keyframe) fail(`${where} starts from the poised knife frame: run --stage poised after shots 1 and 2 are approved, and put its path in "poised_keyframe".`) const startFrame = s.poised_keyframe || s.keyframe const motion = fillTokens(s.motion_prompt, `${where} motion_prompt`).trim() const sound = fillTokens(s.sound, `${where} sound`).trim().replace(/[.]$/, '') // Only name a hand when the shot has one, so the guard never invites a hand into an empty frame. const handLine = /glove/i.test(motion) ? 'The gloved hand stays at the top edge of the frame, well away from the cutting edge; no other hand appears.' : 'No hands in frame.' const prompt = [ 'Satisfying ASMR macro video, vertical 9:16, one continuous shot, no cuts, slow and smooth, real-time speed.', /[.!?]$/.test(motion) ? motion : `${motion}.`, `Sound: close-miked, studio quiet, ${sound}; nothing else. No music, no voices.`, `${handLine} No text, no people, no faces.`, ].join(' ') const seconds = opts.stage === 'draft' ? TEST_SECONDS : Number(s.duration) if (!VEO_DURATIONS.includes(seconds)) fail(`${where} duration must be 4, 6 or 8 (Veo 3.1 fast lengths), not "${s.duration}".`) const input = { prompt, image_url: imageRef(startFrame, `${where} ${s.poised_keyframe ? 'poised keyframe' : 'keyframe'}`), aspect_ratio: '9:16', duration: `${seconds}s`, resolution: res, generate_audio: true, negative_prompt: NEGATIVE, } requests.push({ id: `${s.id}-${opts.stage === 'draft' ? 'test' : 'final'}`, model: MODELS.video, input, approx_cost_usd: Number((seconds * PRICE.videoPerSecond).toFixed(3)) }) } } const total = requests.reduce((a, r) => a + r.approx_cost_usd, 0) if (opts.out) { mkdirSync(opts.out, { recursive: true }) for (const r of requests) writeFileSync(join(opts.out, `${r.id}.json`), JSON.stringify(r, null, 2)) console.log(`Wrote ${requests.length} request(s) to ${opts.out}. Approximate cost: ${money(total)}.`) } else { console.log(JSON.stringify(requests, null, 2)) console.error(`${requests.length} request(s), approximate cost ${money(total)}. Local images are shown as file: paths; use --out with --inline to embed them, or fal-run.mjs (which embeds them).`) }