const apiKey = process.env.PROTOFACE_API_KEY;
const headers = {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
};
const created = await fetch("https://api.protoface.com/v1/run/minimax/minimax-h3", {
method: "POST",
headers: { ...headers, "Idempotency-Key": "first-video-001" },
body: JSON.stringify({
prompt: "A wide shot of a sailboat crossing a quiet bay at sunrise.",
duration_seconds: 8,
quality: "768p",
aspect_ratio: "16:9",
}),
});
if (!created.ok) {
throw new Error(await created.text());
}
const { id: runId } = await created.json();
let status;
do {
await new Promise((resolve) => setTimeout(resolve, 1000));
const response = await fetch(
`https://api.protoface.com/v1/runs/${runId}/status`,
{ headers: { Authorization: `Bearer ${apiKey}` } },
);
if (!response.ok) {
throw new Error(await response.text());
}
status = (await response.json()).status;
} while (status === "queued" || status === "running");
const run = await fetch(`https://api.protoface.com/v1/runs/${runId}`, {
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await run.json();
if (body.status !== "completed") {
throw new Error(JSON.stringify(body.error ?? body.status));
}
console.log(body.video.url);