🎨 ChatGPT 最新生图 gpt-image-2-all 已上线 | Now Live:$0.03/张图,对话式端点提示词遵循最佳!详情 Details
curl --request POST \
--url https://api.apiyi.com/v1/videos \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "sora-2",
"prompt": "A golden retriever running on the beach at sunset, cinematic, golden hour, slow motion"
}
'{
"id": "video_abc123def456",
"object": "video",
"model": "sora-2",
"status": "queued",
"progress": 0,
"created_at": 1712697600,
"completed_at": 1712697900,
"size": "1280x720",
"seconds": "8",
"quality": "standard"
}Sora 2 文生视频 API 参考与在线调试 — JSON 请求体、异步任务三步流程、4/8/12 秒灵活时长。
curl --request POST \
--url https://api.apiyi.com/v1/videos \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "sora-2",
"prompt": "A golden retriever running on the beach at sunset, cinematic, golden hour, slow motion"
}
'{
"id": "video_abc123def456",
"object": "video",
"model": "sora-2",
"status": "queued",
"progress": 0,
"created_at": 1712697600,
"completed_at": 1712697900,
"size": "1280x720",
"seconds": "8",
"quality": "standard"
}Documentation Index
Fetch the complete documentation index at: https://docs.apiyi.com/llms.txt
Use this file to discover all available pages before exploring further.
Bearer sk-xxx),输入 prompt、选择 model / size / seconds 后一键发送即可。input_reference、走 application/json 请求体。如需基于一张参考图生成视频(图生视频),请使用 图生视频接口(同一端点 + input_reference 文件上传)。POST /v1/videos → 返回 video_id + status: "queued"GET /v1/videos/{video_id} 轮询,直到 status: "completed"GET /v1/videos/{video_id}/content 下载 MP4 文件from openai import OpenAI
import time
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apiyi.com/v1"
)
# 第 1 步:提交生成任务
video = client.videos.create(
model="sora-2",
prompt="A golden retriever running on the beach at sunset, cinematic, golden hour, slow motion",
seconds="8",
size="1280x720"
)
print(f"Video ID: {video.id}, status: {video.status}")
# 第 2 步:轮询状态
while True:
video = client.videos.retrieve(video.id)
print(f"Status: {video.status}, progress: {getattr(video, 'progress', 0)}%")
if video.status == "completed":
break
if video.status == "failed":
raise RuntimeError(f"Generation failed: {video}")
time.sleep(15)
# 第 3 步:下载视频
content = client.videos.download_content(video.id)
content.write_to_file("output.mp4")
print("Saved: output.mp4")
import requests
import time
API_KEY = "sk-your-api-key"
BASE_URL = "https://api.apiyi.com/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
# 第 1 步:提交(JSON 请求体)
resp = requests.post(
f"{BASE_URL}/videos",
headers={**HEADERS, "Content-Type": "application/json"},
json={
"model": "sora-2",
"prompt": "A serene Japanese garden with cherry blossoms, koi pond, traditional bridge, golden hour, ultra detailed",
"seconds": "8",
"size": "1280x720"
},
timeout=30 # POST 提交本身只是入队,30 秒足够
).json()
video_id = resp["id"]
print(f"Video ID: {video_id}, status: {resp['status']}")
# 第 2 步:轮询(最长等 15 分钟)
deadline = time.time() + 900
while time.time() < deadline:
status_resp = requests.get(f"{BASE_URL}/videos/{video_id}", headers=HEADERS).json()
print(f"Status: {status_resp['status']}, progress: {status_resp.get('progress', 0)}%")
if status_resp["status"] == "completed":
break
if status_resp["status"] == "failed":
raise RuntimeError(f"Generation failed: {status_resp}")
time.sleep(15)
# 第 3 步:下载
with requests.get(f"{BASE_URL}/videos/{video_id}/content", headers=HEADERS, stream=True) as r:
r.raise_for_status()
with open("output.mp4", "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
print("Saved: output.mp4")
{/* 第 1 步:提交任务 */}
curl -X POST "https://api.apiyi.com/v1/videos" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "sora-2",
"prompt": "A futuristic cityscape at night with neon lights and flying vehicles, cyberpunk style, cinematic",
"seconds": "8",
"size": "1280x720"
}'
{/* 第 2 步:轮询状态(替换 video_id)*/}
curl -X GET "https://api.apiyi.com/v1/videos/video_abc123" \
-H "Authorization: Bearer sk-your-api-key"
{/* 第 3 步:下载视频文件 */}
curl -X GET "https://api.apiyi.com/v1/videos/video_abc123/content" \
-H "Authorization: Bearer sk-your-api-key" \
-o output.mp4
import fs from 'node:fs';
const API_KEY = 'sk-your-api-key';
const BASE_URL = 'https://api.apiyi.com/v1';
// 第 1 步:提交
const submitResp = await fetch(`${BASE_URL}/videos`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: 'sora-2',
prompt: 'Aerial drone shot over snowy mountain range at sunrise, cinematic, ultra wide',
seconds: '8',
size: '1280x720'
})
});
const { id: videoId } = await submitResp.json();
console.log(`Video ID: ${videoId}`);
// 第 2 步:轮询
let status = 'queued';
while (status !== 'completed' && status !== 'failed') {
await new Promise(r => setTimeout(r, 15000));
const statusResp = await fetch(`${BASE_URL}/videos/${videoId}`, {
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const data = await statusResp.json();
status = data.status;
console.log(`Status: ${status}, progress: ${data.progress ?? 0}%`);
}
if (status === 'failed') throw new Error('Generation failed');
// 第 3 步:下载
const contentResp = await fetch(`${BASE_URL}/videos/${videoId}/content`, {
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const buffer = Buffer.from(await contentResp.arrayBuffer());
fs.writeFileSync('output.mp4', buffer);
console.log('Saved: output.mp4');
{/* 仅作演示,生产请走后端代理避免 Key 泄露;视频文件较大也不适合直接在浏览器下载 */}
const submitResp = await fetch('https://api.apiyi.com/v1/videos', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key'
},
body: JSON.stringify({
model: 'sora-2',
prompt: 'Watercolor northern lights over snowy mountains, gentle motion',
seconds: '4',
size: '720x1280'
})
});
const { id } = await submitResp.json();
console.log('Video ID:', id);
{/* 轮询状态后,把视频 URL 交给后端代理下载,再回流给前端展示 */}
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
model | string | 是 | — | sora-2(720p 标准)或 sora-2-pro(720p / 1024p / 1080p 多档) |
prompt | string | 是 | — | 视频描述提示词,建议详细描述场景、镜头运动、风格、光线 |
seconds | string | 否 | "4" | 视频时长,字符串枚举:"4" / "8" / "12"(不是数字) |
size | string | 否 | 720x1280 | 输出分辨率,需匹配模型支持档位(见 概览页技术规格) |
input_reference 文件上传)见 图生视频接口。{
"id": "video_abc123def456",
"object": "video",
"model": "sora-2",
"status": "queued",
"progress": 0,
"created_at": 1712697600,
"size": "1280x720",
"seconds": "8",
"quality": "standard"
}
{
"id": "video_abc123def456",
"object": "video",
"model": "sora-2",
"status": "in_progress",
"progress": 45,
"created_at": 1712697600,
"size": "1280x720",
"seconds": "8"
}
{
"id": "video_abc123def456",
"object": "video",
"model": "sora-2",
"status": "completed",
"progress": 100,
"created_at": 1712697600,
"completed_at": 1712697900,
"size": "1280x720",
"seconds": "8"
}
video_url 字段 —— 视频文件需要通过 GET /v1/videos/{id}/content 端点单独下载(返回 video/mp4 二进制流),不要期待响应里直接出现一个 CDN 链接progress 字段在不同生成阶段会跳变(如 0 → 45 → 80 → 100),不是严格线性的status: "failed" 时不一定带详细 error 字段,多见于内容审核或服务过载,直接重试或调整 prompt 即可/content 返回 404seconds 单价结算(见 概览页定价表)。POST 提交、轮询查询、视频下载本身不计费,失败任务也不计费。在 API易控制台获取的 API Key(必须配置 Sora2官转 分组 + 按量计费)
模型 ID。sora-2 仅支持 720p;sora-2-pro 支持 720p / 1024p / 1080p 三档分辨率
sora-2, sora-2-pro 视频生成提示词,建议详细描述场景、镜头运动、风格、光线、人物动作
"A serene Japanese garden with cherry blossoms, koi pond, traditional bridge, golden hour, ultra detailed"
视频时长,字符串枚举(不是数字):
"4" —— 4 秒(默认),适合短演示、单镜头、快速试错"8" —— 8 秒,标准短视频,最常用"12" —— 12 秒,长镜头、连续动作传 "10" / "15" 或数字 4 会返回 400
4, 8, 12 输出分辨率,sora-2 与 sora-2-pro 支持档位不同:
sora-2(仅 720p):720x1280(竖屏,默认)/ 1280x720(横屏)sora-2-pro 额外支持:
1024x1792 / 1792x1024(1024p,$0.50/秒)1080x1920 / 1920x1080(1080p,$0.70/秒)给 sora-2 传 1024p / 1080p 会返回 400
720x1280, 1280x720, 1024x1792, 1792x1024, 1080x1920, 1920x1080 任务已提交,返回 video_id 与 queued 状态
任务 ID,用于后续轮询和下载
"video_abc123def456"
对象类型,固定 video
"video"
本次任务使用的模型 ID
"sora-2"
任务状态:
queued —— 已提交,排队等待in_progress —— 正在生成completed —— 完成,可下载(/v1/videos/{id}/content)failed —— 失败(不计费),可重试queued, in_progress, completed, failed "queued"
生成进度百分比(0–100),不严格线性
0
任务创建 Unix 时间戳(秒)
1712697600
任务完成 Unix 时间戳(秒),仅 completed 状态返回
1712697900
实际输出分辨率(与请求的 size 一致)
"1280x720"
实际生成时长(与请求的 seconds 一致)
"8"
画质档位(standard 对应 sora-2,high 对应 sora-2-pro)
"standard"
此页面对您有帮助吗?