// Event recap: photos from an event become a vertical recap with a headline, // the date and venue, your logo, sponsor logos shown together at the end, and // a music bed. A 50-second recap is 75 credits; the Preview is free. // The calls of the page https://api.oneupai.com/docs/recipes/event-recap, in // its order, as one program (the photo-reel Timeline of the listing reel, with // the page's headline and sponsor wall). // // In the folder you run it from: the photos as photo-1.jpg, photo-2.jpg, … (in // the order they should play; up to 40), your logo as logo.png, each sponsor's // logo as sponsor-1.png, sponsor-2.png, … and the music as music.mp3. Change // HEADLINE and WHEN below. // // export ONEUP_API_KEY="oneup_live_…" # your Builder key // npx tsx run.mts # Node.js 20 or newer // // ONEUP_BASE_URL changes the host (default https://api.oneupai.com). Every // answer is printed as it arrives. import { readFile, readdir } from "node:fs/promises"; const API = process.env.ONEUP_BASE_URL ?? "https://api.oneupai.com"; const KEY = process.env.ONEUP_API_KEY; if (!KEY) throw new Error("Set ONEUP_API_KEY to your API key first"); const HEADLINE = "Oakridge Founders Summit 2026"; const WHEN = "Sept 12, 2026 · The Granary, Oakridge"; // One API call: the answer is printed and returned; a refusal stops here. async function call( method: string, path: string, body?: object, headers?: Record ) { const res = await fetch(API + path, { signal: AbortSignal.timeout(60_000), method, headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json", ...headers, }, body: body && JSON.stringify(body), }); const json = await res.json(); console.log(JSON.stringify(json)); if (!res.ok) throw new Error(`${res.status} ${json.error}: ${json.message}`); return json; } async function upload(file: string, type: string): Promise { const bytes = await readFile(file); const target = await call("POST", "/v1/uploads/initiate", { content_type: type, file_name: file, size_bytes: bytes.length, }); const put = await fetch(target.upload_url, { signal: AbortSignal.timeout(300_000), method: "PUT", headers: { "Content-Type": type }, body: bytes, }); if (!put.ok) throw new Error(`${file}: the upload answered ${put.status}`); return target.upload_id; } async function render(projectId: string, versionId: string, kind: string) { let r = await call( "POST", "/v1/renders", { alias: "oneup/render-timeline", project_id: projectId, version_id: versionId, kind, }, { "Idempotency-Key": crypto.randomUUID() } ); const renderId = r.render_id; while (r.status !== "COMPLETED" && r.status !== "FAILED") { await new Promise((resolve) => setTimeout(resolve, 5000)); r = await call("GET", `/v1/renders/${renderId}`); } return r; } // photo-1.jpg, photo-2.jpg, … in number order. const numbered = async (prefix: string, ext: string) => (await readdir(".")) .filter((f) => new RegExp(`^${prefix}-\\d+\\.${ext}$`).test(f)) .sort((a, b) => parseInt(a.split("-")[1]!) - parseInt(b.split("-")[1]!)); const files = await numbered("photo", "jpg"); if (!files.length) throw new Error("no photo-*.jpg in this folder"); const photos: string[] = []; for (const file of files) photos.push(await upload(file, "image/jpeg")); const logo = await upload("logo.png", "image/png"); const sponsors: string[] = []; for (const file of await numbered("sponsor", "png")) sponsors.push(await upload(file, "image/png")); const music = await upload("music.mp3", "audio/mpeg"); const project = await call("POST", "/v1/projects", { agent_slug: "oneup/render-timeline", }); const projectId = project.project_id; // Each photo is 3 s, joined by 0.4 s crossfades; the closing card is 4 s and // carries the sponsor wall. The recap's length is the durations added up, // minus each crossfade. const n = photos.length; const total = n * 3000 + 4000 - n * 400; const pushIn = { op: "kenburns", from: { x: 0.5, y: 0.5, zoom: 1 }, to: { x: 0.5, y: 0.5, zoom: 1.18 }, ease: "ease_in_out", }; const pan = { op: "kenburns", from: { x: 0.58, y: 0.5, zoom: 1.18 }, to: { x: 0.42, y: 0.5, zoom: 1.18 }, ease: "ease_in_out", }; const timeline = { v: "1.1", output: { aspect: "9:16", resolution: 1080, fps: 30, container: "mp4" }, segments: [ ...photos.map((id, i) => ({ id: `p${i + 1}`, source: { $asset: id }, duration: 3000, effects: [i % 2 === 0 ? pushIn : pan], transition_out: { op: "crossfade", duration: 400 }, })), { id: "card", source: { $asset: photos[n - 1] }, duration: 4000, effects: [{ op: "fade", from: 1, to: 0, duration: 600 }], }, ], overlays: [ { id: "logo", kind: "image", source: { $asset: logo }, position: { x: 0.05, y: 0.028 }, scale: 0.12, range: { from: 0, to: total }, }, { id: "t1", kind: "text", content: HEADLINE, style: "headline", position: "middle", range: { from: 0, to: 4000 }, }, { id: "t2", kind: "text", content: WHEN, style: "lower_third", position: "bottom", range: { from: 0, to: 4000 }, }, ...sponsors.map((id, i) => ({ id: `sp${i + 1}`, kind: "image", source: { $asset: id }, position: { x: 0.1 + (i % 3) * 0.3, y: 0.7 + Math.floor(i / 3) * 0.12 }, scale: 0.2, range: { from: total - 4000, to: total }, })), ], audio: [ { id: "bed", role: "music", source: { $asset: music }, range: { from: 0, to: total }, loop: true, gain: -14, fade_in: 600, fade_out: 600, }, ], }; const version = await call("PUT", `/v1/projects/${projectId}/timeline`, { timeline, }); await render(projectId, version.version_id, "preview"); const final = await render(projectId, version.version_id, "final"); await call("GET", `/v1/queue/result/${final.ticket}`);