视频模型
Veo 视频生成
通过统一视频任务接口调用 Veo 模型;说明当前项目中的可用模型、请求字段和查询方式。
- 提交路由:
POST /v1/videos - 任务查询:
GET /v1/videos/{task_id} - 内容下载:
GET /v1/videos/{task_id}/content
旧版兼容路由 POST /v1/video/generations 和 GET /v1/video/generations/{task_id} 仍存在;新接入建议使用体验中心和模型端点中展示的 /v1/videos。
提交请求示例
cURL
curl --request POST \
--url https://api.magickapi.com/v1/videos \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "veo-3.1-fast-generate-preview",
"prompt": "海豚在碧蓝海洋中跳跃",
"duration": 8,
"size": "1280x720",
"images": [
"https://example.com/first-frame.png"
],
"metadata": {
"generateAudio": true,
"seed": 7
}
}'提交成功响应示例
提交路由返回的是公开 task_id 对应的 OpenAI 风格视频对象:
{
"id": "task_01KXYZ1234567890ABCDE",
"task_id": "task_01KXYZ1234567890ABCDE",
"object": "video",
"model": "veo-3.1-fast-generate-preview",
"status": "queued",
"progress": 0,
"created_at": 1712345678
}查询与下载
cURL 查询任务状态
curl https://api.magickapi.com/v1/videos/task_01KXYZ1234567890ABCDE \
-H 'Authorization: Bearer YOUR_API_KEY'cURL 下载视频文件
curl -L https://api.magickapi.com/v1/videos/task_01KXYZ1234567890ABCDE/content \
-H 'Authorization: Bearer YOUR_API_KEY' \
--output veo-output.mp4Python 轮询并下载
import time
import requests
base_url = "https://api.magickapi.com"
api_key = "YOUR_API_KEY"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
submit_payload = {
"model": "veo-3.1-fast-generate-preview",
"prompt": "海豚在碧蓝海洋中跳跃",
"duration": 8,
"size": "1280x720",
"images": [
"https://example.com/first-frame.png"
],
"metadata": {
"generateAudio": True,
"seed": 7,
},
}
submit_resp = requests.post(
f"{base_url}/v1/videos",
headers=headers,
json=submit_payload,
timeout=300,
)
submit_resp.raise_for_status()
task = submit_resp.json()
task_id = task.get("id") or task.get("task_id")
print("task_id:", task_id)
while True:
query_resp = requests.get(
f"{base_url}/v1/videos/{task_id}",
headers={"Authorization": f"Bearer {api_key}"},
timeout=300,
)
query_resp.raise_for_status()
status = query_resp.json()
print(status)
if status["status"] == "completed":
download_resp = requests.get(
f"{base_url}/v1/videos/{task_id}/content",
headers={"Authorization": f"Bearer {api_key}"},
timeout=600,
)
download_resp.raise_for_status()
with open("veo-output.mp4", "wb") as f:
f.write(download_resp.content)
print("saved: veo-output.mp4")
break
if status["status"] == "failed":
message = (status.get("error") or {}).get("message", "video generation failed")
raise RuntimeError(message)
time.sleep(10)Node.js 轮询并下载
import { writeFile } from "node:fs/promises";
const baseUrl = "https://api.magickapi.com";
const apiKey = "YOUR_API_KEY";
const submitPayload = {
model: "veo-3.1-fast-generate-preview",
prompt: "海豚在碧蓝海洋中跳跃",
duration: 8,
size: "1280x720",
images: ["https://example.com/first-frame.png"],
metadata: {
generateAudio: true,
seed: 7,
},
};
const submitResp = await fetch(`${baseUrl}/v1/videos`, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify(submitPayload),
});
if (!submitResp.ok) {
throw new Error(await submitResp.text());
}
const task = await submitResp.json();
const taskId = task.id || task.task_id;
console.log("task_id:", taskId);
while (true) {
const queryResp = await fetch(`${baseUrl}/v1/videos/${taskId}`, {
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
if (!queryResp.ok) {
throw new Error(await queryResp.text());
}
const status = await queryResp.json();
console.log(status);
if (status.status === "completed") {
const downloadResp = await fetch(`${baseUrl}/v1/videos/${taskId}/content`, {
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
if (!downloadResp.ok) {
throw new Error(await downloadResp.text());
}
const buffer = Buffer.from(await downloadResp.arrayBuffer());
await writeFile("veo-output.mp4", buffer);
console.log("saved: veo-output.mp4");
break;
}
if (status.status === "failed") {
throw new Error(status.error?.message || "video generation failed");
}
await new Promise((resolve) => setTimeout(resolve, 10000));
}当前项目真正解析的公共顶层字段
modelpromptmodeimageimagesinput_referencesizedurationsecondsmetadata
Veo 相关参数写法
size
对于 Veo,建议直接传像素尺寸,例如:
1280x720720x12803840x2160
项目会根据 size 自动推导默认 resolution 和 aspectRatio。
metadata
Veo 扩展参数应放进 metadata,例如:
aspectRatioresolutionnegativePromptseedgenerateAudio
旧版兼容查询
旧版任务查询路由仍可使用:
curl https://api.magickapi.com/v1/video/generations/task_01KXYZ1234567890ABCDE \
-H 'Authorization: Bearer YOUR_API_KEY'最后更新于