Veo 3.1 视频生成 API
使用 Google Veo 3.1 模型生成视频的 API,支持文生视频、参考图片和首尾帧模式。支持多镜头长视频,最长 168 秒。
在线体验: https://nanophoto.ai/veo-3
| 方法 | 路径 | 说明 |
|---|
| POST | /api/veo-3/generate | 生成视频 |
| POST | /api/veo-3/check-status | 查询任务状态 |
Authorization: Bearer YOUR_API_KEY
| 分辨率 | 镜头数 | 积分 |
|---|
| 720p | 每个镜头 | 10 |
| 1080p | 仅限 1 个镜头 | 14 |
| 4K | 仅限 1 个镜头 | 30 |
每个镜头生成 8 秒视频片段,多镜头视频自动拼接。
每次请求最多 21 个镜头(总计 168 秒)。1080p 和 4K 仅支持单镜头生成。
| Header | 值 |
|---|
Content-Type | application/json |
Authorization | Bearer YOUR_API_KEY |
| 参数 | 类型 | 必填 | 说明 |
|---|
shots | object[] | 是 | 镜头对象数组(最多 21 个) |
shots[].id | string | 是 | 镜头唯一标识 |
shots[].prompt | string | 是 | 视频生成提示词 |
shots[].generationType | string | 是 | TEXT_2_VIDEO、FIRST_AND_LAST_FRAMES_2_VIDEO 或 REFERENCE_2_VIDEO |
shots[].aspectRatio | string | 是 | 16:9 或 9:16 |
shots[].imageUrls | string[] | 条件必填 | 公开图片 URL(按生成类型要求) |
resolution | string | 否 | 720p(默认)、1080p 或 4k(仅单镜头) |
| 类型 | 说明 | 图片要求 |
|---|
TEXT_2_VIDEO | 文生视频 | 无(不可传图片) |
FIRST_AND_LAST_FRAMES_2_VIDEO | 首尾帧生成视频 | 1-2 张图片 |
REFERENCE_2_VIDEO | 参考图片生成视频 | 1-3 张图片 |
API 调用仅接受 imageUrls(公开 URL),不支持 Base64 图片上传。
curl -X POST "https://nanophoto.ai/api/veo-3/generate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-raw '{
"shots": [
{
"id": "shot-1",
"prompt": "一只金毛犬在日落时分的海滩上奔跑,电影级光影",
"generationType": "TEXT_2_VIDEO",
"aspectRatio": "16:9"
}
],
"resolution": "720p"
}'
curl -X POST "https://nanophoto.ai/api/veo-3/generate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-raw '{
"shots": [
{
"id": "shot-1",
"prompt": "画中的人物动起来,穿越魔法森林",
"generationType": "REFERENCE_2_VIDEO",
"aspectRatio": "16:9",
"imageUrls": ["https://static.nanophoto.ai/demo/nano-banana-pro.webp"]
}
],
"resolution": "720p"
}'
curl -X POST "https://nanophoto.ai/api/veo-3/generate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-raw '{
"shots": [
{
"id": "shot-1",
"prompt": "城市天际线的黎明全景,金色的阳光",
"generationType": "TEXT_2_VIDEO",
"aspectRatio": "16:9"
},
{
"id": "shot-2",
"prompt": "窗台上的咖啡杯特写,蒸汽升腾",
"generationType": "TEXT_2_VIDEO",
"aspectRatio": "16:9"
},
{
"id": "shot-3",
"prompt": "一个人穿过公园,秋叶飘落",
"generationType": "TEXT_2_VIDEO",
"aspectRatio": "16:9"
}
],
"resolution": "720p"
}'
async function generateVideo() {
// 第一步:提交生成任务
const response = await fetch("https://nanophoto.ai/api/veo-3/generate", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({
shots: [
{
id: "shot-1",
prompt: "一只金毛犬在日落时分的海滩上奔跑",
generationType: "TEXT_2_VIDEO",
aspectRatio: "16:9",
},
],
resolution: "720p",
}),
});
const data = await response.json();
if (data.status === "failed") {
console.error("生成失败:", data.error);
return;
}
// 第二步:轮询任务状态
const taskIds = data.shots.map((shot: any) => ({
shotId: shot.shotId,
taskId: shot.taskId,
}));
while (true) {
await new Promise((resolve) => setTimeout(resolve, 5000)); // 等待 5 秒
const statusRes = await fetch(
"https://nanophoto.ai/api/veo-3/check-status",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({ taskIds, resolution: "720p" }),
}
);
const status = await statusRes.json();
if (status.status === "completed") {
for (const shot of status.shots) {
console.log(`镜头 ${shot.shotId} 视频地址:`, shot.videoUrl);
}
return;
}
if (status.status === "failed") {
console.error("生成失败:", status.shots);
return;
}
console.log("处理中...");
}
}
generateVideo();
{
"status": "processing",
"shots": [
{
"shotId": "shot-1",
"taskId": "task_abc123",
"status": "processing"
}
],
"creditsUsed": 10
}
收到 status: "processing" 时,请每隔 5-10 秒轮询 check-status 接口。
{
"error": "Insufficient credits",
"errorCode": "INSUFFICIENT_CREDITS",
"requiredCredits": 10
}
POST /api/veo-3/check-status
| Header | 值 |
|---|
Content-Type | application/json |
Authorization | Bearer YOUR_API_KEY |
| 参数 | 类型 | 必填 | 说明 |
|---|
taskIds | object[] | 是 | 生成接口返回的任务 ID 数组 |
taskIds[].shotId | string | 是 | 镜头 ID |
taskIds[].taskId | string | 是 | 生成接口返回的任务 ID |
resolution | string | 否 | 720p(默认)、1080p 或 4k |
curl -X POST "https://nanophoto.ai/api/veo-3/check-status" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-raw '{
"taskIds": [
{"shotId": "shot-1", "taskId": "task_abc123"}
],
"resolution": "720p"
}'
{
"status": "processing",
"shots": [
{
"shotId": "shot-1",
"taskId": "task_abc123",
"status": "processing"
}
]
}
{
"status": "completed",
"shots": [
{
"shotId": "shot-1",
"taskId": "task_abc123",
"status": "completed",
"videoUrl": "https://video.nanophoto.ai/veo/...",
"generationTime": 90
}
]
}
{
"status": "failed",
"shots": [
{
"shotId": "shot-1",
"taskId": "task_abc123",
"status": "failed",
"error": "Video generation failed"
}
]
}
- 每 5-10 秒 轮询一次
/api/veo-3/check-status
- 典型生成时间:每个镜头约 2-5 分钟
- 多镜头视频因顺序生成需要更长时间
- 生成失败时积分会自动退还
| errorCode | HTTP 状态码 | 说明 |
|---|
LOGIN_REQUIRED | 401 | 需要认证 |
API_KEY_RATE_LIMIT_EXCEEDED | 429 | 超出频率限制(100 次/小时) |
INSUFFICIENT_CREDITS | 402 | 积分不足 |
SHOTS_REQUIRED | 400 | 缺少镜头数组 |
PROMPT_REQUIRED | 400 | 镜头缺少提示词 |
INVALID_IMAGE_COUNT | 400 | 图片数量不符合生成类型要求 |
IMAGE_URLS_REQUIRED | 400 | API 调用需要 imageUrls(不支持 base64) |
GENERATION_FAILED | 500 | 视频生成失败 |
TASK_IDS_REQUIRED | 400 | 缺少任务 ID |
TASK_NOT_FOUND | 404 | 任务不存在或无权访问 |
INTERNAL_ERROR | 500 | 内部服务器错误 |