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

# Tạo video Sora 2

> Sử dụng POST /v1/videos để tạo tác vụ tạo video Sora 2 từ prompt văn bản hoặc hình ảnh tham chiếu, sau đó thăm dò trạng thái bằng task ID để lấy kết quả.

Sử dụng endpoint này để bắt đầu một tác vụ render Sora từ văn bản, hoặc từ văn bản cộng với một hình ảnh tham chiếu. API trả về một video id ngay lập tức và không chờ quá trình render hoàn tất.

## Bắt đầu với tác vụ nhỏ nhất hữu ích

* Dùng `sora-2` để lặp nhanh hơn hoặc `sora-2-pro` khi chất lượng đầu ra quan trọng hơn tốc độ
* Giữ `seconds` ở `4` cho yêu cầu đầu tiên của bạn
* Bắt đầu với `size: 1280x720` trừ khi bạn thực sự cần đầu ra dọc
* Tải lên nhiều nhất một hình ảnh tham chiếu

## Thời lượng và kích thước

| Thiết lập               | Giá trị được hỗ trợ                                               | Điểm khởi đầu mặc định           | Hành vi ở giới hạn                                             |
| ----------------------- | ----------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------------- |
| `seconds`               | `4`, `8`, `12`, `16`, `20`                                        | `4`                              | Các giá trị khác không nằm trong định dạng yêu cầu video Sora. |
| `size` cho `sora-2`     | `1280x720`, `720x1280`                                            | `1280x720`                       | Dùng hướng ngang hoặc hướng dọc.                               |
| `size` cho `sora-2-pro` | `1792x1024`, `1024x1792`, cộng với các kích thước Sora tiêu chuẩn | `1792x1024` cho đầu ra Pro ngang | Chỉ dùng các kích thước Pro lớn hơn với model Pro.             |

Sora yêu cầu trường `size` ở đúng định dạng `WxH`. Các token độ phân giải như `720p` và nhãn tỷ lệ như `16:9` không phải là giá trị `size` hợp lệ của Sora trên endpoint này.

## Quy trình end-to-end

<Steps>
  <Step title="Tạo tác vụ render">
    Gửi `model`, `prompt`, `seconds`, và `size`, sau đó lưu `id` được trả về.
  </Step>

  <Step title="Thăm dò cho đến khi tác vụ hoàn tất">
    Gọi [Retrieve Video](./retrieve) cho đến khi trạng thái trở thành `completed` hoặc `failed`.
  </Step>

  <Step title="Tải xuống kết quả">
    Khi quá trình render hoàn tất, lấy tệp bằng [Retrieve Video Content](./retrieve-content).
  </Step>
</Steps>

## Hành vi của Sora vẫn áp dụng

OpenAI mô tả cùng một quy trình create -> retrieve -> download trong Videos API. Trên CometAPI, bạn giữ nguyên định dạng yêu cầu của Sora, nhưng sử dụng base URL và key của CometAPI. Các URL tải xuống đã hoàn tất là tạm thời, vì vậy hãy sao chép các tài nguyên đã hoàn tất vào bộ nhớ lưu trữ của riêng bạn nếu bạn cần lưu giữ lâu dài.


## OpenAPI

````yaml api/openapi/video/sora-2/post-create.openapi.json POST /v1/videos
openapi: 3.1.0
info:
  title: Create Video API
  version: 1.0.0
  description: >-
    Create an asynchronous Sora video job through CometAPI. Poll GET
    /v1/videos/{video_id} for status and GET /v1/videos/{video_id}/content for
    the final file.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /v1/videos:
    post:
      summary: Create a Sora video job
      description: >-
        Start a Sora render job from a prompt and, optionally, one reference
        image. Save the returned video id and poll the retrieve endpoint until
        the job completes.
      operationId: create_video
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - prompt
              properties:
                prompt:
                  type: string
                  description: Text prompt that describes the video you want to create.
                  example: A paper airplane glides across a desk.
                model:
                  type: string
                  description: >-
                    Sora model ID. Choose an available model from the [Models
                    page](/overview/models).
                  default: sora-2
                  example: sora-2
                seconds:
                  type: string
                  enum:
                    - '4'
                    - '8'
                    - '12'
                    - '16'
                    - '20'
                  description: Clip duration in seconds. Use 4, 8, 12, 16, or 20.
                  default: '4'
                  example: '4'
                size:
                  type: string
                  enum:
                    - 720x1280
                    - 1280x720
                    - 1024x1792
                    - 1792x1024
                  description: >-
                    Output resolution formatted as width x height. Use 1280x720
                    or 720x1280 for standard Sora output. Use 1792x1024 or
                    1024x1792 with a Pro model when you need larger Pro output.
                  default: 1280x720
                  example: 1280x720
                input_reference:
                  type: string
                  format: binary
                  description: >-
                    Optional reference image uploaded as a file. The image
                    should match the target size you request.
              default:
                prompt: A paper airplane glides across a desk.
                model: sora-2
                seconds: '4'
                size: 1280x720
            examples:
              Text to video:
                summary: Text to video
                value:
                  model: sora-2
                  prompt: A paper boat drifts across a calm pond at sunrise
                  seconds: '4'
                  size: 1280x720
              With reference image:
                summary: >-
                  First-frame reference image. Replace input_reference with your
                  image file.
                value:
                  model: sora-2
                  prompt: Animate gentle ripples across the water
                  seconds: '4'
                  size: 1280x720
                  input_reference: '@reference.png'
      responses:
        '200':
          description: Video job accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - created_at
                  - id
                  - model
                  - object
                  - progress
                  - seconds
                  - size
                  - status
                properties:
                  created_at:
                    type: integer
                  id:
                    type: string
                  model:
                    type: string
                  object:
                    type: string
                  progress:
                    type: integer
                  seconds:
                    type: string
                  size:
                    type: string
                  status:
                    type: string
                example:
                  created_at: 1773296991
                  id: video_69b25d5f467c81908733a56bc236b4df
                  model: sora-2
                  object: video
                  progress: 0
                  seconds: '4'
                  size: 1280x720
                  status: queued
              example:
                id: <video_id>
                task_id: <video_id>
                object: video
                model: sora-2
                status: queued
                progress: 0
                created_at: 1781079478
                seconds: '4'
                size: 1280x720
      x-codeSamples:
        - lang: Shell
          label: Text to video
          source: |
            curl https://api.cometapi.com/v1/videos \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -F model=sora-2 \
              -F prompt="A paper boat drifts across a calm pond at sunrise" \
              -F seconds=4 \
              -F size=1280x720
        - lang: Shell
          label: With reference image
          source: |
            curl https://api.cometapi.com/v1/videos \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -F model=sora-2 \
              -F prompt="Animate gentle ripples across the water" \
              -F seconds=4 \
              -F size=1280x720 \
              -F input_reference=@reference.png
        - lang: Python
          label: Text to video
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/v1/videos",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                data={
                    "model": "sora-2",
                    "prompt": "A paper boat drifts across a calm pond at sunrise",
                    "seconds": "4",
                    "size": "1280x720",
                },
            )


            video = response.json()

            print(video["id"], video["status"])  # poll GET /v1/videos/{id}
            until completed
        - lang: Python
          label: With reference image
          source: |
            import os
            import requests

            with open("reference.png", "rb") as image:
                response = requests.post(
                    "https://api.cometapi.com/v1/videos",
                    headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                    data={
                        "model": "sora-2",
                        "prompt": "Animate gentle ripples across the water",
                        "seconds": "4",
                        "size": "1280x720",
                    },
                    files={"input_reference": image},
                )

            video = response.json()
            print(video["id"], video["status"])
        - lang: JavaScript
          label: Text to video
          source: >
            const form = new FormData();

            form.append("model", "sora-2");

            form.append("prompt", "A paper boat drifts across a calm pond at
            sunrise");

            form.append("seconds", "4");

            form.append("size", "1280x720");


            const response = await fetch("https://api.cometapi.com/v1/videos", {
                method: "POST",
                headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
                body: form,
            });


            const video = await response.json();

            console.log(video.id, video.status); // poll GET /v1/videos/{id}
            until completed
        - lang: JavaScript
          label: With reference image
          source: >
            import { readFile } from "node:fs/promises";


            const form = new FormData();

            form.append("model", "sora-2");

            form.append("prompt", "Animate gentle ripples across the water");

            form.append("seconds", "4");

            form.append("size", "1280x720");

            form.append("input_reference", new Blob([await
            readFile("reference.png")], { type: "image/png" }),
            "reference.png");


            const response = await fetch("https://api.cometapi.com/v1/videos", {
                method: "POST",
                headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
                body: form,
            });


            const video = await response.json();

            console.log(video.id, video.status);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````