import openai
import time
client = openai.OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.weelinking.com/v1"
)
# 1. 提交异步任务
response = client.post(
"/videos/generations",
body={
"model": "sora_video2",
"prompt": "一只猫在草地上奔跑,阳光明媚,慢动作",
"duration": 10,
"async": True
}
)
task_id = response["id"]
print(f"任务已提交: {task_id}")
# 2. 轮询状态
while True:
status = client.get(f"/videos/generations/{task_id}")
if status["status"] == "completed":
print(f"视频已生成: {status['video_url']}")
break
elif status["status"] == "failed":
print("生成失败")
break
else:
print(f"状态: {status['status']}")
time.sleep(10)