const BASE = "https://api.cloudsome-inc.ai/v1";
const headers = {
Authorization: "Bearer sk_live_your_key_here",
"Content-Type": "application/json",
};
async function request(path, options = {}) {
const response = await fetch(BASE + path, {
...options, headers, signal: AbortSignal.timeout(60_000),
});
if (!response.ok) throw new Error(await response.text());
return response.json();
}
const batch = await request("/videos", {
method: "POST",
body: JSON.stringify({
model: "dreamina-seedance-2.5",
prompt: "A golden retriever running on the beach at sunset",
duration: 5,
resolution: "720p",
}),
});
const taskId = batch.tasks[0].id;
console.log("Task ID:", taskId);
for (let attempt = 0; ; attempt++) {
if (attempt === 120) throw new Error("Keep querying task " + taskId + "; do not create it again.");
const task = await request("/videos/" + taskId);
if (task.status === "completed") {
const url = task.download_url || task.url;
if (!url) throw new Error("Video URL unavailable; query task " + taskId + " again.");
console.log(url);
break;
}
if (["failed", "cancelled", "expired"].includes(task.status)) {
throw new Error(JSON.stringify(task.error || task.status));
}
await new Promise((resolve) => setTimeout(resolve, 5000));
}