Before and after video

On this page

Two photos become an 8-second vertical video: the before, a spin, the after. By the end of this page you will have made one from your own two photos. There is no generation step: your uploads go straight into a Timeline.

What it costs #

Only the final is charged: 15 credits for each started 10 seconds of video, so this 8-second video is 15 credits, about $0.15. The Preview is free.

The calls, in order #

POST /v1/uploads/initiate  {"content_type": "image/jpeg", "file_name": "before.jpg", "size_bytes": …}  → PUT the bytes to upload_url
POST /v1/uploads/initiate  {… "file_name": "after.jpg" …}                                           → PUT the bytes to upload_url
POST /v1/projects                         {"agent_slug": "oneup/render-timeline"}     → {"project_id"}
PUT  /v1/projects/{project_id}/timeline   {"timeline": <the Timeline below>}      → {"version_id"}
POST /v1/renders  (Idempotency-Key)       {"alias": "oneup/render-timeline", "project_id", "version_id", "kind": "preview"}
POST /v1/renders  (Idempotency-Key)       {"alias": "oneup/render-timeline", "project_id", "version_id", "kind": "final"}
GET  /v1/renders/{render_id}              → {"status": "COMPLETED", "ticket", "asset_id", …}
GET  /v1/queue/result/{ticket}            → {"assets": [the MP4]}

The Timeline #

Each photo is a segment with a gentle zoom. The first ends in a spin into the second. v is the version of the Timeline language: the spin needs version 1.2 or newer, and a Timeline that uses something newer than its v is refused when you save it, with a detail that names the version it needs.

JSON
{
  "v": "1.2",
  "output": {
    "aspect": "9:16",
    "resolution": 1080,
    "fps": 30,
    "container": "mp4"
  },
  "segments": [
    {
      "id": "before",
      "source": { "$asset": "<before upload id>" },
      "duration": 3000,
      "effects": [{ "op": "zoom", "level": 1.08 }],
      "transition_out": { "op": "seamless_spin", "duration": 900 }
    },
    {
      "id": "after",
      "source": { "$asset": "<after upload id>" },
      "duration": 5000,
      "effects": [{ "op": "zoom", "level": 1.08 }],
      "transition_out": { "op": "cut", "duration": 0 }
    }
  ]
}

Run it #

Save two JPEG photos as before.jpg and after.jpg, open a terminal in that folder, and set ONEUP_API_KEY as in the quickstart. Then run one of the three programs below: paste the curl into the terminal, save the TypeScript as before-after.mts and run npx tsx before-after.mts, or save the Python as before-after.py and run python3 before-after.py. Each one uploads both photos, saves the Timeline in a new Project, makes a Preview and then the final, and prints the result.

curl
API=${ONEUP_BASE_URL:-https://api.oneupai.com}
AUTH="Authorization: Bearer $ONEUP_API_KEY"
JSON="Content-Type: application/json"

api() {
  OUT=$(curl -s -X "$1" "$API$2" -H "$AUTH" -H "$JSON" "${@:3}")
  case "$OUT" in *'"error"'*) echo "$OUT" >&2; exit 1 ;; esac
}
field() { echo "$OUT" | grep -o "\"$1\":\"[^\"]*\"" | head -1 | cut -d'"' -f4; }

upload() {
  api POST /v1/uploads/initiate -d "{\"content_type\": \"image/jpeg\", \"file_name\": \"$1\", \"size_bytes\": $(wc -c < "$1" | tr -d ' ')}"
  curl -s -X PUT "$(field upload_url)" -H "Content-Type: image/jpeg" --data-binary @"$1" > /dev/null
}

render() {
  api POST /v1/renders -H "Idempotency-Key: $(uuidgen)" \
    -d "{\"alias\": \"oneup/render-timeline\", \"project_id\": \"$PROJECT\", \"version_id\": \"$VERSION\", \"kind\": \"$1\"}"
  RENDER=$(field render_id)
  until echo "$OUT" | grep -qE '"status":"(COMPLETED|FAILED)"'; do
    sleep 5
    api GET "/v1/renders/$RENDER"
  done
  echo "$OUT"
}

upload before.jpg
BEFORE=$(field upload_id)
upload after.jpg
AFTER=$(field upload_id)

api POST /v1/projects -d '{"agent_slug": "oneup/render-timeline"}'
PROJECT=$(field project_id)

api PUT "/v1/projects/$PROJECT/timeline" -d '{
  "timeline": {
    "v": "1.2",
    "output": { "aspect": "9:16", "resolution": 1080, "fps": 30, "container": "mp4" },
    "segments": [
      { "id": "before", "source": { "$asset": "'"$BEFORE"'" }, "duration": 3000,
        "effects": [{ "op": "zoom", "level": 1.08 }],
        "transition_out": { "op": "seamless_spin", "duration": 900 } },
      { "id": "after", "source": { "$asset": "'"$AFTER"'" }, "duration": 5000,
        "effects": [{ "op": "zoom", "level": 1.08 }],
        "transition_out": { "op": "cut", "duration": 0 } }
    ]
  }
}'
VERSION=$(field version_id)

render preview
render final
api GET "/v1/queue/result/$(field ticket)"
echo "$OUT"
TypeScript
import { readFile } from "node:fs/promises";

const API = process.env.ONEUP_BASE_URL ?? "https://api.oneupai.com";
const KEY = process.env.ONEUP_API_KEY;

async function call(
  method: string,
  path: string,
  body?: object,
  headers?: Record<string, string>
) {
  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();
  if (!res.ok) throw new Error(`${res.status} ${json.error}: ${json.message}`);
  return json;
}

async function upload(file: string) {
  const bytes = await readFile(file);
  const target = await call("POST", "/v1/uploads/initiate", {
    content_type: "image/jpeg",
    file_name: file,
    size_bytes: bytes.length,
  });
  const put = await fetch(target.upload_url, {
    signal: AbortSignal.timeout(300_000),
    method: "PUT",
    headers: { "Content-Type": "image/jpeg" },
    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}`);
  }
  console.log(JSON.stringify(r, null, 2));
  return r;
}

const before = await upload("before.jpg");
const after = await upload("after.jpg");

const project = await call("POST", "/v1/projects", {
  agent_slug: "oneup/render-timeline",
});
const projectId = project.project_id;

const timeline = {
  v: "1.2",
  output: { aspect: "9:16", resolution: 1080, fps: 30, container: "mp4" },
  segments: [
    {
      id: "before",
      source: { $asset: before },
      duration: 3000,
      effects: [{ op: "zoom", level: 1.08 }],
      transition_out: { op: "seamless_spin", duration: 900 },
    },
    {
      id: "after",
      source: { $asset: after },
      duration: 5000,
      effects: [{ op: "zoom", level: 1.08 }],
      transition_out: { op: "cut", duration: 0 },
    },
  ],
};
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");
const result = await call("GET", `/v1/queue/result/${final.ticket}`);
console.log(JSON.stringify(result, null, 2));
Python
import json, os, time, urllib.error, urllib.request, uuid

API = os.environ.get("ONEUP_BASE_URL", "https://api.oneupai.com")
KEY = os.environ["ONEUP_API_KEY"]

def call(method, path, body=None, headers=None):
    request = urllib.request.Request(
        API + path,
        method=method,
        data=None if body is None else json.dumps(body).encode(),
        headers={
            "Authorization": f"Bearer {KEY}",
            "Content-Type": "application/json",
            "User-Agent": "my-app/1.0",
            **(headers or {}),
        },
    )
    try:
        with urllib.request.urlopen(request, timeout=60) as response:
            return json.load(response)
    except urllib.error.HTTPError as error:
        problem = json.load(error)
        raise SystemExit(f"{error.code} {problem['error']}: {problem['message']}")

def upload(name):
    with open(name, "rb") as file:
        data = file.read()
    target = call(
        "POST",
        "/v1/uploads/initiate",
        {"content_type": "image/jpeg", "file_name": name, "size_bytes": len(data)},
    )
    put = urllib.request.Request(
        target["upload_url"],
        method="PUT",
        data=data,
        headers={"Content-Type": "image/jpeg", "User-Agent": "my-app/1.0"},
    )
    urllib.request.urlopen(put, timeout=300).close()
    return target["upload_id"]

def render(project_id, version_id, kind):
    r = call(
        "POST",
        "/v1/renders",
        {
            "alias": "oneup/render-timeline",
            "project_id": project_id,
            "version_id": version_id,
            "kind": kind,
        },
        {"Idempotency-Key": str(uuid.uuid4())},
    )
    render_id = r["render_id"]
    while r["status"] not in ("COMPLETED", "FAILED"):
        time.sleep(5)
        r = call("GET", f"/v1/renders/{render_id}")
    print(json.dumps(r, indent=2))
    return r

before = upload("before.jpg")
after = upload("after.jpg")

project = call("POST", "/v1/projects", {"agent_slug": "oneup/render-timeline"})

timeline = {
    "v": "1.2",
    "output": {"aspect": "9:16", "resolution": 1080, "fps": 30, "container": "mp4"},
    "segments": [
        {
            "id": "before",
            "source": {"$asset": before},
            "duration": 3000,
            "effects": [{"op": "zoom", "level": 1.08}],
            "transition_out": {"op": "seamless_spin", "duration": 900},
        },
        {
            "id": "after",
            "source": {"$asset": after},
            "duration": 5000,
            "effects": [{"op": "zoom", "level": 1.08}],
            "transition_out": {"op": "cut", "duration": 0},
        },
    ],
}
version = call(
    "PUT", f"/v1/projects/{project['project_id']}/timeline", {"timeline": timeline}
)

render(project["project_id"], version["version_id"], "preview")
final = render(project["project_id"], version["version_id"], "final")
result = call("GET", f"/v1/queue/result/{final['ticket']}")
print(json.dumps(result, indent=2))

If any step is refused, the program prints the error and stops. Otherwise it prints three answers. First the finished Preview: open its preview_url to watch it, and its poster_url for a still from it.

JSON
{
  "render_id": "8e2631f2-3e17-457f-8fa5-05d4c8b93f00",
  "ticket": "oneup_req_7nyDXaO5sbLwWruJ2PshDL2i6D",
  "kind": "preview",
  "status": "COMPLETED",
  "progress": {},
  "preview_url": "https://media.oneupai.com/a/8e2631f2-3e17-457f-8fa5-05d4c8b93f00/1791436038/iwgjiszz4iQ3OnV80DRlDUFXDF1uSI85gX1_ur_R4QB",
  "poster_url": "https://media.oneupai.com/a/oneup_asset_y0op220JNBkosCpcg2iWhyvV4A/1791436038/17zdKisHybmrIIc7hQgu6KtIlbC9_BoPh7eAufFd-6T",
  "preview_expires_at": "2026-10-11T04:07:01.846Z",
  "created_at": "2026-10-08T04:07:01.858Z",
  "completed_at": "2026-10-08T04:07:15.275Z"
}

Then the finished final, with the asset_id of the video in your account:

JSON
{
  "render_id": "68d46bc5-8aec-452d-9cc6-e02c953705cd",
  "ticket": "oneup_req_SeGKfj9MtZBDnuujfWeatmFPit",
  "kind": "final",
  "status": "COMPLETED",
  "progress": {},
  "poster_url": "https://media.oneupai.com/a/oneup_asset_A06obVi1TFUVNsSuvw9qWDso2M/1791436086/WkCbUhkBLfms3A9XE37emS1oYI1O66NM2DwSXgqbtKt",
  "asset_id": "oneup_asset_wVb59L9t3920xfZw397HeG4mnU",
  "created_at": "2026-10-08T04:07:18.992Z",
  "completed_at": "2026-10-08T04:08:03.414Z"
}

Then the result, with a link to the MP4 that works for one hour:

JSON
{
  "ticket": "oneup_req_SeGKfj9MtZBDnuujfWeatmFPit",
  "status": "COMPLETED",
  "alias": "oneup/render-timeline",
  "assets": [
    {
      "asset_id": "oneup_asset_wVb59L9t3920xfZw397HeG4mnU",
      "content_type": "video/mp4",
      "size_bytes": 183996,
      "url": "https://media.oneupai.com/a/oneup_asset_wVb59L9t3920xfZw397HeG4mnU/1791436087/5Ci1Y4cLEQj5GHg5j0_6ltq4kBwlmG6dNY9fgSjedXw"
    }
  ]
}

A still from a segment #

To get one frame of a segment as a picture, for example to start a generated clip from it, ask for a render with "kind": "frame", a segment_id and "at": "first" or "last". It is free and uses one second of your Preview allowance. The picture matches the crop and zoom the video uses at that moment. When the render is COMPLETED, GET /v1/renders/{render_id} carries its asset_id, and GET /v1/assets/{asset_id}/url gives the PNG's link, which you can send as the start_image_url or end_image_url of a video model.

POST /v1/renders  (Idempotency-Key)  {"alias": "oneup/render-timeline", "project_id", "version_id", "kind": "frame", "segment_id": "after", "at": "first"}