// Listing reel from a link: the photos and facts of a public listing page // (Zillow, Realtor.com, Redfin or FurnishedFinder) become the photo reel. The // read is 2 credits, bringing the photos in is free, each small photo // sharpened is 2 credits, and the final is 15 credits for each started 10 // seconds (a 30-second reel: 45). The Preview is free. // The calls of the page https://api.oneupai.com/docs/recipes/listing-from-link, // in its order, as one program. // // export ONEUP_API_KEY="oneup_live_…" # your Builder key // npx tsx run.mts "https://www.zillow.com/homedetails/…" # Node.js 20+ // // ONEUP_BASE_URL changes the host (default https://api.oneupai.com). Every // answer is printed as it arrives. 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 LISTING = process.argv[2]; if (!LISTING) throw new Error("Give the listing page address as the first argument"); // 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; } const retryKey = () => ({ "Idempotency-Key": crypto.randomUUID() }); const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); // Waits for a queued job (every 2 s for 30 s, then every 5 s); its result. async function waitFor(ticket: string) { const started = Date.now(); let status = await call("GET", `/v1/queue/status/${ticket}`); while (status.status !== "COMPLETED" && status.status !== "FAILED") { await sleep(Date.now() - started < 30_000 ? 2000 : 5000); status = await call("GET", `/v1/queue/status/${ticket}`); } return call("GET", `/v1/queue/result/${ticket}`); } 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, }, retryKey() ); const renderId = r.render_id; while (r.status !== "COMPLETED" && r.status !== "FAILED") { await sleep(5000); r = await call("GET", `/v1/renders/${renderId}`); } return r; } // 1. Read the listing (2 credits; the same retry key within 15 minutes // returns the first answer without a charge). const listing = ( await call( "POST", "/v1/run/oneup/web-read-listing", { url: LISTING }, retryKey() ) ).output; const { address, price, beds, baths } = listing.facts; // 2. Bring the photos into your account (free; within an hour of the read). type Photo = { url: string; width?: number; height?: number }; const photosOnPage: Photo[] = listing.photos; const imported = await call("POST", "/v1/uploads/from-extraction", { extraction_id: listing.extraction_id, urls: photosOnPage.slice(0, 40).map((p) => p.url), }); // 3. Sharpen each photo whose shorter side is under 1080 pixels (2 credits // each), and use the sharper copy in its place. const small = new Set( photosOnPage .filter((p) => (p.width ?? 1080) < 1080 || (p.height ?? 1080) < 1080) .map((p) => p.url) ); const photos: string[] = []; for (const item of imported.uploads) { if (!small.has(item.url)) { photos.push(item.upload_id); continue; } const job = await call( "POST", "/v1/queue/submit/oneup/image-upscale", { image_url: item.file_url }, retryKey() ); const sharper = await waitFor(job.ticket); photos.push(sharper.assets[0].asset_id); } if (!photos.length) throw new Error("no photo could be brought in"); // 4. The photo reel: each photo 3 s with a push-in or a pan, 0.4 s // crossfades, a 4-second closing card, the address and price over the // opening. const project = await call("POST", "/v1/projects", { agent_slug: "oneup/render-timeline", }); const projectId = project.project_id; 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[photos.length - 1] }, duration: 4000, effects: [{ op: "fade", from: 1, to: 0, duration: 600 }], }, ], overlays: [ { id: "t1", kind: "text", content: address, style: "lower_third", position: "middle", range: { from: 0, to: 3000 }, enter: { op: "fade", duration: 250 }, exit: { op: "fade", duration: 200 }, }, { id: "t2", kind: "text", content: `${price} · ${beds} bd · ${baths} ba`, style: "lower_third", position: "bottom", range: { from: 0, to: 3000 }, }, ], }; const version = await call("PUT", `/v1/projects/${projectId}/timeline`, { timeline, }); // 5. A free Preview, then the final, then the MP4's link (good for an hour). await render(projectId, version.version_id, "preview"); const final = await render(projectId, version.version_id, "final"); await call("GET", `/v1/queue/result/${final.ticket}`);