视频
生成视频需要几分钟,所以它以任务的方式进行:先发起任务,再查询进度,完成后下载文件。
发起视频任务
Section titled “发起视频任务”POST https://api.exoticrouter.com/v1/videos
curl https://api.exoticrouter.com/v1/videos \ -H "Authorization: Bearer $EXOTIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "minimax/hailuo-2.3-fast", "prompt": "A glass ribbon turning slowly in violet light" }'请求会立即返回,内容是任务的信息:
{ "id": "video_8sKq…", "object": "video", "model": "minimax/hailuo-2.3-fast", "status": "queued", "progress": 0, "created_at": 1796169600}model必须是视频模型,也就是模型列表里formats包含videos的模型。请求体的其余部分(比如视频时长)会传给模型;模型是否支持这些参数,取决于模型本身。- 请完整保存返回的
id。它很长,而且是找回这个视频的唯一凭证。
GET https://api.exoticrouter.com/v1/videos/{id}
返回同一个对象,其中是任务当前的状态。
status |
含义 |
|---|---|
queued |
已接受,尚未开始 |
in_progress |
生成中;如果模型提供进度,progress 会从 0 到 100 |
completed |
已完成:可以下载文件 |
failed |
生成失败。对象里会有一个 error,代码为 generation_failed |
GET https://api.exoticrouter.com/v1/videos/{id}/content
返回视频文件本身,类型是 video/mp4 或文件的实际类型。在状态变为 completed 之前,它会返回 409,代码为 not_ready。失败的视频会一直返回同样的 409,所以请根据状态来判断,而不是根据下载结果。
ID="video_8sKq…"
until [ "$(curl -s https://api.exoticrouter.com/v1/videos/$ID \ -H "Authorization: Bearer $EXOTIC_API_KEY" | jq -r .status)" = "completed" ]; do sleep 10done
curl https://api.exoticrouter.com/v1/videos/$ID/content \ -H "Authorization: Bearer $EXOTIC_API_KEY" -o video.mp4import os, time, requests
BASE = "https://api.exoticrouter.com/v1"auth = {"Authorization": f"Bearer {os.environ['EXOTIC_API_KEY']}"}
job = requests.post(f"{BASE}/videos", headers=auth, json={ "model": "minimax/hailuo-2.3-fast", "prompt": "A glass ribbon turning slowly in violet light",}).json()
while job["status"] in ("queued", "in_progress"): time.sleep(10) job = requests.get(f"{BASE}/videos/{job['id']}", headers=auth).json()
if job["status"] == "completed": video = requests.get(f"{BASE}/videos/{job['id']}/content", headers=auth) open("video.mp4", "wb").write(video.content)else: print(job.get("error"))import fs from "node:fs";
const BASE = "https://api.exoticrouter.com/v1";const auth = { Authorization: `Bearer ${process.env.EXOTIC_API_KEY}` };
let job = await fetch(`${BASE}/videos`, { method: "POST", headers: { ...auth, "Content-Type": "application/json" }, body: JSON.stringify({ model: "minimax/hailuo-2.3-fast", prompt: "A glass ribbon turning slowly in violet light" }),}).then((r) => r.json());
while (job.status === "queued" || job.status === "in_progress") { await new Promise((r) => setTimeout(r, 10_000)); job = await fetch(`${BASE}/videos/${job.id}`, { headers: auth }).then((r) => r.json());}
if (job.status === "completed") { const video = await fetch(`${BASE}/videos/${job.id}/content`, { headers: auth }); fs.writeFileSync("video.mp4", Buffer.from(await video.arrayBuffer()));}- 查询视频状态或下载文件时,需要用发起任务的那个账号的密钥,并放在请求头里。其他账号的密钥,或者不完整的 id,都会返回 404。
- 每次查询状态都会计入密钥的速率限制。大约每十秒查询一次就足够了。
- 生成好的视频会保留几天,不会永久保存。完成后请及时下载。
- 没有列出、取消或删除视频的接口。
发起视频任务时不扣费。只有在完成时扣费一次;失败的视频,或者 30 分钟内没有完成的视频,不收费。