> ## Documentation Index
> Fetch the complete documentation index at: https://doc.geekapis.com/llms.txt
> Use this file to discover all available pages before exploring further.

#  Sora 2 视频生成

> 通过  OpenAI 官方端点直连 Sora 2，支持文生视频和图生视频，时长 4/8/12 秒，分辨率 1280×720 或 720×1280。

通过 即刻API 直连  OpenAI Sora 2 官方端点（`sora-2-official`），支持文本生成视频和图生视频，所有任务均为异步处理。

## 请求参数

<ParamField body="model" type="string" required>
  视频生成模型名称。支持的模型：

  * `sora-2`— Sora 2 官方模型\
    sora2-pro—Sora 2 pro官方模型

  示例：`"sora-2"`
</ParamField>

<ParamField body="prompt" type="string" required>
  视频生成的自然语言描述。建议包含镜头类型、主体、动作、场景、光线和相机运动，以减少歧义。保持描述单一目的以获得最佳效果。

  示例：`"一只金毛犬在草地上奔跑，阳光明媚"`
</ParamField>

<ParamField body="duration" default="4" type="integer">
  视频时长（秒）。支持的值：

  * `4` — 4 秒（默认）
  * `8` — 8 秒
  * `12` — 12 秒

  示例：`12`

  <ParamField body="size" type="string" required>
    视频分辨率。支持的值：

    * `1280x720` — 横屏（16:9）
    * `720x1280` — 竖屏（9:16）

    示例：`"1280x720"`
  </ParamField>

  <ParamField body="input_reference" type="string">
    用于图生视频的参考图像。支持以下格式：

    * `http/https` 图片 URL
    * `data:` URL
    * Base64 编码图片数据

    建议使用可公开访问的图片 URL，且图片尺寸与 `size` 保持一致。

    示例：`"https://placehold.co/1280x720.png"`
  </ParamField>
</ParamField>

## 请求示例

<CodeGroup>
  ```bash cURL（文生视频） theme={null}
  curl --request POST \
    --url https://geekapis.com/v1/video/generations \
    --header "Authorization: Bearer <YOUR_API_KEY>" \
    --header "Content-Type: application/json" \
    --data '{
      "model": "sora2",
      "prompt": "一只金毛犬在草地上奔跑，阳光明媚",
      "duration": 12,
      "size": "1280x720"
    }'
  ```

  ```bash cURL（图生视频） theme={null}
  curl --request POST \
    --url https://geekapis.com/v1/video/generations \
    --header "Authorization: Bearer <YOUR_API_KEY>" \
    --header "Content-Type: application/json" \
    --data '{
      "model": "sora2",
      "prompt": "让参考图中的元素轻微运动，保持原有构图和文字不变",
      "duration": 4,
      "size": "1280x720",
      "input_reference": "https://placehold.co/1280x720.png"
    }'
  ```

  ```python Python theme={null}
  import time
  import requests

  API_KEY = "<YOUR_API_KEY>"
  BASE_URL = "https://geekapis.com/v1"
  HEADERS = {
      "Authorization": f"Bearer {API_KEY}",
      "Content-Type": "application/json",
  }

  def submit_and_poll(payload: dict):
      create_resp = requests.post(
          f"{BASE_URL}/video/generations",
          headers=HEADERS,
          json=payload,
          timeout=60,
      )
      create_resp.raise_for_status()
      task = create_resp.json()
      print("create:")
      print(task)

      task_id = task["task_id"]

      while True:
          status_resp = requests.get(
              f"{BASE_URL}/video/generations/{task_id}",
              headers={"Authorization": f"Bearer {API_KEY}"},
              timeout=60,
          )
          status_resp.raise_for_status()
          result = status_resp.json()
          print("status:")
          print(result)

          status = result["data"]["status"]
          if status == "SUCCESS":
              print("video_url:", result["data"]["result_url"])
              break
          if status == "FAILURE":
              print("failed:", result["data"]["fail_reason"])
              break

          time.sleep(5)

  # 文生视频
  submit_and_poll({
      "model": "sora2",
      "prompt": "一只金毛犬在草地上奔跑，阳光明媚",
      "duration": 12,
      "size": "1280x720",
  })

  # 图生视频
  # submit_and_poll({
  #     "model": "sora2",
  #     "prompt": "让参考图中的元素轻微运动，保持原有构图和文字不变",
  #     "duration": 4,
  #     "size": "1280x720",
  #     "input_reference": "https://placehold.co/1280x720.png",
  # })
  ```

  ```javascript JavaScript theme={null}
  const API_KEY = "<YOUR_API_KEY>";
  const BASE_URL = "https://geekapis.com/v1";

  function sleep(ms) {
    return new Promise((resolve) => setTimeout(resolve, ms));
  }

  async function submitAndPoll(payload) {
    const createResp = await fetch(`${BASE_URL}/video/generations`, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(payload),
    });

    if (!createResp.ok) {
      throw new Error(await createResp.text());
    }

    const task = await createResp.json();
    console.log("create:");
    console.log(task);

    const taskId = task.task_id;

    while (true) {
      const statusResp = await fetch(`${BASE_URL}/video/generations/${taskId}`, {
        headers: {
          Authorization: `Bearer ${API_KEY}`,
        },
      });

      if (!statusResp.ok) {
        throw new Error(await statusResp.text());
      }

      const result = await statusResp.json();
      console.log("status:");
      console.log(result);

      const status = result.data.status;
      if (status === "SUCCESS") {
        console.log("video_url:", result.data.result_url);
        break;
      }
      if (status === "FAILURE") {
        console.log("failed:", result.data.fail_reason);
        break;
      }

      await sleep(5000);
    }
  }

  // 文生视频
  submitAndPoll({
    model: "sora2",
    prompt: "一只金毛犬在草地上奔跑，阳光明媚",
    duration: 12,
    size: "1280x720",
  });

  // 图生视频
  // submitAndPoll({
  //   model: "sora2",
  //   prompt: "让参考图中的元素轻微运动，保持原有构图和文字不变",
  //   duration: 4,
  //   size: "1280x720",
  //   input_reference: "https://placehold.co/1280x720.png",
  // }).catch(console.error);
  ```
</CodeGroup>

## 返回示例

```json 200 theme={null}
{
  "id": "task_IYxJo9z0S7tQ1al8o2KcG9Nkn7Mwf3Mz",
  "task_id": "task_IYxJo9z0S7tQ1al8o2KcG9Nkn7Mwf3Mz",
  "object": "video",
  "model": "sora2-12s-16x9",
  "status": "queued",
  "progress": 0,
  "created_at": 1782454942,
  "seconds": "12",
  "size": "1280x720"
}
```

## 查询任务状态

提交后，使用以下接口轮询任务进度：

```text theme={null}
GET https://geekapis.com/v1/video/generations/{task_id}
```
