import requests
import openai
import time
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.yelinai.com"
# 步骤 1:生成初始视频(异步 API)
print("步骤 1:生成初始视频...")
video_response = requests.post(
f"{BASE_URL}/v1/videos",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
},
json={
"model": "sora-2",
"prompt": "一个可爱的卡通角色在跳舞",
"size": "1280x720",
"seconds": "10"
}
)
task = video_response.json()
task_id = task["id"]
print(f"视频任务 ID: {task_id}")
# 步骤 2:等待视频生成完成
print("步骤 2:等待视频生成...")
while True:
status_response = requests.get(
f"{BASE_URL}/v1/videos/{task_id}",
headers={"Authorization": f"Bearer {API_KEY}"}
)
status = status_response.json()
if status["status"] == "completed":
print("视频生成完成!")
break
elif status["status"] == "failed":
print("视频生成失败")
exit(1)
time.sleep(10)
# 步骤 3:从视频创建角色
print("步骤 3:创建角色...")
character_response = requests.post(
f"{BASE_URL}/sora/v1/characters",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
},
json={
"model": "sora-2-character",
"from_task": task_id,
"timestamps": "1,3"
}
)
character = character_response.json()
username = character["username"]
print(f"角色创建成功!Username: @{username}")
# 步骤 4:使用角色生成新视频
print("步骤 4:使用角色生成新视频...")
new_video_response = requests.post(
f"{BASE_URL}/v1/videos",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
},
json={
"model": "sora-2",
"prompt": f"@{username} 在舞台上表演,观众欢呼",
"size": "1280x720",
"seconds": "10"
}
)
new_task = new_video_response.json()
print(f"新视频任务 ID: {new_task['id']}")