const URL = "https://api.dreamto.ai/api/v3/contents/generations/tasks";
const headers = {
Authorization: `Bearer ${process.env.DREAMTO_API_KEY}`,
"Content-Type": "application/json",
};
const payload = {
"model": "seedance-2.5-flash",
"content": [
{
"type": "text",
"text": "雨后的城市街头,霓虹灯倒映在积水中,镜头低角度跟随一辆自行车缓缓驶过"
}
],
"ratio": "16:9",
"duration": 5,
"resolution": "720p"
};
const created = await fetch(URL, { method: "POST", headers, body: JSON.stringify(payload) });
if (!created.ok) throw new Error(JSON.stringify(await created.json()));
const { id } = await created.json();
for (;;) {
const task = await (await fetch(`${URL}/${id}`, { headers })).json();
if (task.status === "succeeded") {
console.log(task.content.video_url);
break;
}
if (task.status === "failed") throw new Error(task.error.message);
await new Promise((r) => setTimeout(r, 5000));
}