Skip to content
中文

Make your first video

Create a project, two PNG preview files, and an exported media reference. The example keeps the first four seconds and does not depend on transcription or analysis.

1. Prepare media and credentials

Use an API key and an existing LIBRARY_ID from the same organization and environment. The organization must have read and write access to the library. Set CUT_SOURCE_URL to a publicly fetchable HTTPS video at least four seconds long. Save the program as cut-quickstart.mjs; Node.js is sufficient, with no SDK installation.

终端窗口
# Set PRAXIS_API_KEY, LIBRARY_ID, and CUT_SOURCE_URL in your environment.
node cut-quickstart.mjs

2. Create, bind, and import

This complete program binds the library at project creation, imports footage into its default upload library, and passes the resulting reference to the script. For a File source, replace source: { url: sourceUrl } with source: { file_id: "<file_id>" }.

import { writeFile } from "node:fs/promises";
const base = process.env.PRAXIS_API_BASE ?? "https://api.deepraxis.com";
const key = process.env.PRAXIS_API_KEY;
const libraryId = process.env.LIBRARY_ID;
const sourceUrl = process.env.CUT_SOURCE_URL;
if (!key || !libraryId || !sourceUrl) throw new Error("Set PRAXIS_API_KEY, LIBRARY_ID, CUT_SOURCE_URL");
async function call(path, body) {
const response = await fetch(base + "/cut/v1" + path, {
method: body === undefined ? "GET" : "POST",
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
...(body === undefined ? {} : { body: JSON.stringify(body) })
});
const result = await response.json();
if (!response.ok) throw new Error(JSON.stringify(result));
return result;
}
const project = await call("/projects", {
name: "First Cut", settings: { width: 1920, height: 1080, fps: 30 },
bindings: [{ name: "main", library_id: libraryId, access: "read_write", default_upload: true }]
});
const path = `/projects/${project.id}`;
const asset = await call(path + "/media:import", { source: { url: sourceUrl } });
const media = { libraryId: asset.library_id, assetId: asset.asset_id };
const edited = await call(path + ":execute", { script: `
const track = AddTrack("video", { name: "Speed" });
const id = Insert(track, {
type: "video", media: ${JSON.stringify(media)}, start: 0, length: 4
});
Print(GetItem(id));
Preview([0, 1]);
` });
for (const [at, frame] of Object.entries(edited.frames ?? {})) {
await writeFile(`preview-${at}.png`, Buffer.from(frame.url.split(",")[1], "base64"));
}
console.log({ project_id: project.id, summary: edited.summary });
const job = await call(path + "/exports", { folder: "cut", name: "First Cut", output: { format: "mp4", quality: "draft" } });
console.log({ export_id: job.id });
let current = job;
while (!["done", "failed", "canceled"].includes(current.status)) {
await new Promise(resolve => setTimeout(resolve, 3000));
current = await call(`/exports/${job.id}`);
}
if (current.status !== "done") throw new Error(JSON.stringify(current.error ?? current));
const output = await fetch(base + `/media/v1/libraries/${current.asset.library_id}/assets/${current.asset.asset_id}`, {
headers: { Authorization: `Bearer ${key}` }
});
if (!output.ok) throw new Error(`Media HTTP ${output.status}`);
console.log({ asset: current.asset, media: await output.json() });

3. Inspect the edit and previews

The execute uses AddTrack, Insert, GetItem, and Preview (see the script reference) to keep four seconds. Check that summary reports the new track and clip. Open preview-0.png and preview-1.png and confirm neither is black or an offline tile. Preview URLs contain inline data, rather than hosted HTTP images.

4. Retrieve the finished video

The program polls the export until a terminal state. Only done means success. It then retrieves the Media resource using the output reference; use its secure_url to read the video. Verify the export matches the previews. The project and exported asset remain in your organization.

Recover from failures

If import fails, check that the URL is publicly fetchable. OUT_OF_SOURCE means the input is too short: choose a longer video or reduce length. For LIBRARY_NOT_FOUND, check organization access and bindings. A FRAME_UNAVAILABLE preview warning can follow a committed edit; retry frame retrieval and inspect the media. On export failure, inspect error.cause and error.request_id, fix the cause, and create a new export.

Next steps