Google教程
如何使用 Veo 3.1 Lite API
分步学习 Veo 3.1 Lite API,支持 Node.js、Python 和 cURL:提交 文生视频 任务、轮询状态或接收 Webhook,然后下载 video。下方示例费用为 $0.30。
- 端点
- 2
- 文生视频 · 图生视频
- 请求示例
- $0.30
- 文生视频
- 编程语言
- 3
- Node.js · Python · cURL
- 失败任务
- $0
- 自动退款
获取 API 密钥
创建账户、充值额度,然后前往“控制台”→“API 密钥”创建密钥。将其保存为 CHEAPERGEN_API_KEY 服务器上的环境变量。每个请求都要将其作为 Bearer 令牌发送。
提交 文生视频 任务
此程序会提交任务,每 3 秒轮询一次直到任务完成,然后打印 video URL。你可以替换提示词和设置以满足自己的需求。
const API = "https://cheapergen.com/api/v1";
const headers = {
Authorization: `Bearer ${process.env.CHEAPERGEN_API_KEY}`,
"Content-Type": "application/json",
};
// 1. Submit the job
let job = await fetch(`${API}/run/google/veo-3.1-lite/text-to-video`, {
method: "POST",
headers,
body: JSON.stringify({
"prompt": "猫把桌上的笔推落后盯着镜头,办公室环境音柔和",
"aspect_ratio": "16:9",
"resolution": "720p",
"duration": 8
}),
}).then((r) => r.json());
// 2. Poll until it finishes (or pass webhook_url and skip polling)
while (job.status === "queued" || job.status === "running") {
await new Promise((r) => setTimeout(r, 3000));
job = await fetch(`${API}/generations/${job.id}`, { headers }).then((r) => r.json());
}
console.log(job.status === "succeeded" ? job.output.video.url : job.error);设置关键参数
google/veo-3.1-lite/text-to-video 的设置及其对价格的影响。
| 参数 | 类型 · 默认值 | 功能说明 | 对价格的影响 |
|---|---|---|---|
| aspect_ratio | string (enum) · 16:9 | 横屏或竖屏。 16:9 · 9:16 | 是 |
| resolution | string (enum) · 720p | 720p(暂不支持 1080p)。 720p | 720p: $0.0375 每秒 |
| duration | integer (enum) · 8 | 视频片段时长:4、6 或 8 秒。 4 · 6 · 8 | 8s: $0.0375 每秒 |
其他 Veo 3.1 Lite 端点的请求结构相同,但各自的输入字段有所不同:
POST /api/v1/run/google/veo-3.1-lite/image-to-video
{
"prompt": "场景动了起来:树叶沙沙作响,鸟儿开始歌唱",
"image_url": "https://cdn.cheapergen.com/samples/portrait.jpg",
"aspect_ratio": "16:9",
"resolution": "720p",
"duration": 8
}获取结果
任务状态会从 queued 变为 running,然后进入 succeeded、failed 或 canceled。请轮询 GET /api/v1/generations/{id},或传入 webhook_url,我们会通过 POST 将结果发送给你。请下载输出并自行保存。
200 — 已成功
{
"id": "gen_8c2QmX1nq0k4",
"object": "generation",
"model": "google/veo-3.1-lite",
"endpoint": "google/veo-3.1-lite/text-to-video",
"mode": "text-to-video",
"status": "succeeded",
"input": {
"prompt": "猫把桌上的笔推落后盯着镜头,办公室环境音柔和",
"aspect_ratio": "16:9",
"resolution": "720p",
"duration": 8
},
"output": {
"video": {
"url": "https://cdn.cheapergen.com/outputs/gen_8c2Q.mp4",
"content_type": "video/mp4",
"duration": 5,
"width": 1280,
"height": 720
}
},
"error": null,
"cost": {
"amount_usd": 0.2255,
"currency": "usd",
"estimated": false,
"official_usd": 0.264,
"list_price_source": "official",
"list_price_label": "Official",
"saved_usd": 0.0385
},
"source": "api",
"created_at": "2026-10-15T09:21:04Z",
"started_at": "2026-10-15T09:21:06Z",
"completed_at": "2026-10-15T09:22:31Z"
}运行前查询价格
报价端点免费且无需密钥。它会根据你提交的确切输入,返回价格、官方价格 和折扣。
curl -X POST https://cheapergen.com/api/v1/quote/google/veo-3.1-lite/text-to-video \
-H "Content-Type: application/json" \
-d '{"prompt":"猫把桌上的笔推落后盯着镜头,办公室环境音柔和","aspect_ratio":"16:9","resolution":"720p","duration":8}'| 状态 | 代码 | 说明 |
|---|---|---|
| 400 | invalid_request | 缺少参数或参数超出范围,错误信息会指出具体字段。 |
| 401 | unauthorized | API 密钥缺失、格式错误或已撤销。 |
| 402 | insufficient_balance | 余额不足,无法支付报价金额;请充值或启用自动充值。 |
| 429 | rate_limited | 请求过多或进行中的生成任务过多;请稍后重试。 |
| 502 | upstream_error | 模型服务提供商发生错误;冻结金额已退还,你可以重试。 |
| 503 | model_unavailable | 当前没有运行正常的路由,请稍后重试或选择其他模型。 |
常见问题
Veo 3.1 Lite API 常见问题
不需要。API 使用标准 HTTPS 和 JSON,因此本页的 Node.js(fetch)和 Python(requests)示例都是完整程序。任何能够发送 HTTP 请求的语言都可以调用。
可以。在请求正文中添加 "webhook_url",生成任务完成后我们会向该地址 POST 结果,并使用 CheaperGen-Signature 标头进行签名(对时间戳和原始请求正文计算 HMAC-SHA256)。也可以轮询 GET /api/v1/generations/{id}。
将公开 URL 传入 "image_url", "end_image_url"。没有公开 URL 的文件可以先通过 POST /api/v1/uploads 上传,然后在请求中使用返回的 URL。
文生视频 起价为 $0.0375 每秒;本页的请求示例费用为 $0.30,比 官方价格 低 25%。生成失败会自动退款。
