搜索结果

×

搜索结果将在这里显示。

⏭️ Sora2调用 /v1/videos 接口(Python示例)

Sora2官方 /v1/videos 接口(异步任务)

  • 官方文档:https://platform.openai.com/docs/api-reference/videos/create

Python 示例

import requests

# --- 1. 填入你在UIUIAPI获取的 API Key ---
API_KEY = "sk-JKzyxxxxxxxxxxxxxxxxxxxxxxxxxx" 

# --- 2. 在这里写入你的【创意提示词】 ---
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
my_prompt = "A lone protagonist standing on a skyscraper rooftop at sunset, wide shot, cinematic, 2.39:1, 24fps, anamorphic lens, film grain, teal & orange color grading, dramatic rim light, slow dolly in, slight handheld grit"  # <--- 创意内容,不要包含"15s"或"竖屏"
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

# --- 3. 在这里设置你的【技术参数】 ---
video_seconds = "15"      # 视频时长 (s),对应你的 "15s"

# 视频尺寸/方向,对应 "竖屏"、"横屏"、"高清"
# "1080x1920" = 竖屏, 高清 (HD Vertical)
# "1920x1080" = 横屏, 高清 (HD Horizontal)
# "" (空字符串) = 让 API 自动决定 (默认)
video_size = ""   # <--- 这里设置为了 "竖屏、高清"

# 你的 API 终结点
API_URL = "https://sg.uiuiapi.com/v1/videos"

# 准备请求头
headers = {
    'Authorization': f'Bearer {API_KEY}'
}

# 准备要发送的表单数据
# 我们将把上面的技术参数填入这里
form_data = {
    'model': (None, 'sora-2'),
    'prompt': (None, my_prompt),        # 使用创意提示词
    'seconds': (None, video_seconds),   # 使用 '15'
    'input_reference': (None, ''), 
    'size': (None, video_size)          # 使用 '1080x1920'
}

print(f"正在发送请求到: {API_URL}")
print(f"使用提示词: {my_prompt}")
print(f"设置时长: {video_seconds}s")
print(f"设置尺寸: {video_size}")

try:
    # 发送 POST 请求
    response = requests.post(API_URL, headers=headers, files=form_data)

    # 检查 HTTP 状态码
    response.raise_for_status()

    # 打印成功的响应内容
    print("请求成功,响应内容:")
    print(response.text)

except requests.exceptions.HTTPError as http_err:
    # 捕获 HTTP 错误
    print(f"HTTP 错误: {http_err}")
    print(f"响应内容: {response.text}")
except requests.exceptions.RequestException as err:
    # 捕获其他请求错误
    print(f"请求发生错误: {err}")