Sora 2 TVC 广告 API
使用 AI 驱动的分镜图生成和 Sora 2 视频合成来制作 TVC(电视广告)视频的 API。
在线体验: https://nanophoto.ai/sora-2-tvc-ad
接口
| 方法 | 路径 | 说明 |
|---|---|---|
| POST | /api/sora-2-tvc/generate | 生成 TVC 广告视频 |
| POST | /api/sora-2-tvc/check-status | 查询任务状态 |
认证
Authorization: Bearer YOUR_API_KEY积分
| 时长 | 积分 |
|---|---|
| 10s | 8 |
| 15s | 8 |
工作原理
TVC 广告 API 使用三步 AI 流水线生成专业电视广告视频:
- 分镜脚本 — AI 根据广告主题生成 9 个场景(SC1-SC9)的分镜描述
- 分镜图片 — AI 生成 3×3 九宫格黑白线稿分镜图
- 视频生成 — Sora 2 基于分镜图生成最终广告视频
生成接口在启动流水线后立即返回。请使用状态查询接口轮询进度和结果。
生成 TVC 广告
POST /api/sora-2-tvc/generate请求头
| Header | 值 |
|---|---|
Content-Type | application/json |
Authorization | Bearer YOUR_API_KEY |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
adTheme | string | 是 | 广告主题(如"耐克跑鞋") |
referenceImageUrl | string | 否 | 参考图片的公开 URL,用于风格引导 |
voiceoverScript | string | 否 | 广告配音脚本 |
videoDuration | string | 否 | 10 或 15(秒,默认 10) |
aspectRatio | string | 否 | portrait(竖屏,默认)或 landscape(横屏) |
API 调用仅接受 referenceImageUrl(公开 URL),不支持 Base64 图片上传。
请求示例
基本 TVC 广告
curl -X POST "https://nanophoto.ai/api/sora-2-tvc/generate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-raw '{
"adTheme": "耐克跑鞋 - 感受速度",
"videoDuration": "15",
"aspectRatio": "landscape"
}'带参考图和配音
curl -X POST "https://nanophoto.ai/api/sora-2-tvc/generate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-raw '{
"adTheme": "奢华香水 - 每一滴都是优雅",
"referenceImageUrl": "https://example.com/perfume-reference.jpg",
"voiceoverScript": "发现优雅的本质,一款与灵魂对话的香氛。",
"videoDuration": "15",
"aspectRatio": "portrait"
}'TypeScript
async function generateTVCAd() {
// 第一步:提交 TVC 广告生成任务
const response = await fetch("https://nanophoto.ai/api/sora-2-tvc/generate", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({
adTheme: "耐克跑鞋 - 感受速度",
voiceoverScript: "跑得更快,跑得更强。耐克。",
videoDuration: "15",
aspectRatio: "landscape",
}),
});
const data = await response.json();
if (!data.success) {
console.error("生成失败:", data.error);
return;
}
console.log("分镜脚本:", data.storyboardPrompt);
console.log("分镜图片:", data.storyboardImageUrl);
// 第二步:使用 recordId 轮询状态
const recordId = data.recordId;
while (true) {
await new Promise((resolve) => setTimeout(resolve, 5000)); // 等待 5 秒
const statusRes = await fetch(
"https://nanophoto.ai/api/sora-2-tvc/check-status",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({ recordId }),
}
);
const status = await statusRes.json();
if (status.status === "completed") {
console.log("视频地址:", status.videoUrl);
console.log("生成耗时:", status.generationTime, "秒");
return;
}
if (status.status === "failed") {
console.error("生成失败:", status.error);
return;
}
console.log(`步骤 ${status.currentStep}/3: ${status.stepName}`);
}
}
generateTVCAd();响应
处理中
{
"success": true,
"status": "processing",
"taskId": "video_task_id",
"recordId": "tvc_record_id",
"storyboardPrompt": "生成的 9 场景分镜描述...",
"storyboardImageUrl": "https://static.nanophoto.ai/images/sora-tvc/storyboard-xxx.png"
}收到 status: "processing" 时,请每隔 5-10 秒轮询 check-status 接口。
错误
{
"error": "Insufficient credits",
"errorCode": "INSUFFICIENT_CREDITS",
"requiredCredits": 8
}查询任务状态
POST /api/sora-2-tvc/check-status请求头
| Header | 值 |
|---|---|
Content-Type | application/json |
Authorization | Bearer YOUR_API_KEY |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
recordId | string | 条件必填 | 生成接口返回的 TVC 记录 ID |
taskId | string | 条件必填 | 生成接口返回的视频任务 ID |
提供 recordId 或 taskId 之一即可,推荐使用 recordId。
请求示例
curl -X POST "https://nanophoto.ai/api/sora-2-tvc/check-status" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
--data-raw '{"recordId": "tvc_record_id"}'响应
步骤 1:生成分镜脚本
{
"success": true,
"status": "processing",
"recordId": "tvc_record_id",
"currentStep": 1,
"stepName": "Generating Storyboard Prompt"
}步骤 2:生成分镜图片
{
"success": true,
"status": "processing",
"recordId": "tvc_record_id",
"currentStep": 2,
"stepName": "Generating Storyboard",
"storyboardPrompt": "..."
}步骤 3:生成视频
{
"success": true,
"status": "processing",
"recordId": "tvc_record_id",
"currentStep": 3,
"stepName": "Generating Ad Video",
"storyboardPrompt": "...",
"storyboardImageUrl": "https://static.nanophoto.ai/images/sora-tvc/storyboard-xxx.png",
"videoTaskProgress": "generating"
}已完成
{
"success": true,
"status": "completed",
"recordId": "tvc_record_id",
"currentStep": 3,
"stepName": "Completed",
"storyboardPrompt": "...",
"storyboardImageUrl": "https://static.nanophoto.ai/images/sora-tvc/storyboard-xxx.png",
"videoUrl": "https://video.nanophoto.ai/sora/...",
"generationTime": 180
}失败
{
"success": false,
"status": "failed",
"error": "Video generation failed",
"errorCode": "GENERATION_FAILED",
"recordId": "tvc_record_id"
}轮询策略
- 每 5-10 秒 轮询一次
/api/sora-2-tvc/check-status - 典型生成时间:2-5 分钟(三步流水线:脚本 → 分镜图 → 视频)
- 生成失败时积分会自动退还
错误码
| errorCode | HTTP 状态码 | 说明 |
|---|---|---|
LOGIN_REQUIRED | 401 | 需要认证 |
API_KEY_RATE_LIMIT_EXCEEDED | 429 | 超出频率限制(100 次/小时) |
INSUFFICIENT_CREDITS | 402 | 积分不足 |
INVALID_INPUT | 400 | 缺少广告主题 |
REFERENCE_IMAGE_URL_REQUIRED | 400 | API 调用需要 referenceImageUrl(不支持 base64) |
GENERATION_FAILED | 500 | TVC 广告生成失败 |
RECORD_NOT_FOUND | 404 | TVC 记录不存在 |
UNAUTHORIZED | 403 | 无权访问该记录 |
INTERNAL_ERROR | 500 | 内部服务器错误 |
NanoPhoto.AI文档