> ## 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.

# Truy xuất một video Sora 2

> Sử dụng CometAPI GET /v1/videos/{video_id} để truy xuất trạng thái, tiến độ và metadata của video Sora 2 như thời lượng, kích thước, dấu thời gian và thời điểm hết hạn.

Sử dụng endpoint này sau khi bạn bắt đầu một job Sora. Endpoint này báo cáo trạng thái hiện tại của job, kích thước và thời lượng đã cấu hình, cùng với mọi lỗi do nhà cung cấp trả về.

## Theo dõi các trường này

* `status` cho trạng thái vòng đời
* `progress` cho tín hiệu tiến độ ở mức tổng quát
* `error` khi nhà cung cấp từ chối hoặc job bị lỗi
* `expires_at` sau khi hoàn tất nếu bạn cần biết khi nào các tài nguyên tạm thời hết hạn

## Poll cho đến khi hoàn tất

<Steps>
  <Step title="Tạo video trước">
    Bắt đầu với [Create Video](./create).
  </Step>

  <Step title="Poll theo id">
    Truyền `id` được trả về vào đây và tiếp tục kiểm tra cho đến khi job đạt trạng thái `completed` hoặc `failed`.
  </Step>

  <Step title="Tải xuống tệp">
    Khi job ở trạng thái `completed`, chuyển sang [Retrieve Video Content](./retrieve-content).
  </Step>
</Steps>

## Hình dạng phản hồi trên CometAPI

Bước này bám sát quy trình polling của Sora. CometAPI giữ nguyên hình dạng object kiểu OpenAI để bạn có thể kết nối các bước kiểm tra trạng thái với mức chuyển đổi tối thiểu.


## OpenAPI

````yaml api/openapi/video/sora-2/get-retrieve.openapi.json GET /v1/videos/{video_id}
openapi: 3.1.0
info:
  title: Retrieve Video API
  version: 1.0.0
  description: Retrieve the current status of a Sora video job created through CometAPI.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /v1/videos/{video_id}:
    get:
      summary: Retrieve a Sora video job
      description: >-
        Poll a previously created Sora video job until it is completed or
        failed.
      operationId: retrieve_video
      parameters:
        - name: video_id
          in: path
          required: true
          description: Video id returned by the create or remix endpoint.
          schema:
            type: string
      responses:
        '200':
          description: Current job state.
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                  - size
                  - model
                  - object
                  - status
                  - seconds
                  - progress
                  - created_at
                properties:
                  id:
                    type: string
                    description: Task id.
                  size:
                    type: string
                  error:
                    type:
                      - object
                      - 'null'
                  model:
                    type: string
                  object:
                    type: string
                  prompt:
                    type: string
                  status:
                    type: string
                    description: >-
                      Task state: `queued`, `in_progress`, `completed`, or
                      `failed`.
                  seconds:
                    type: string
                  progress:
                    type: integer
                    description: Render progress from 0 to 100.
                  created_at:
                    type: integer
                    description: Unix timestamp of task creation.
                  expires_at:
                    type:
                      - integer
                      - 'null'
                  completed_at:
                    type:
                      - integer
                      - 'null'
                    description: Unix timestamp of completion.
                  remixed_from_video_id:
                    type:
                      - string
                      - 'null'
                  video_url:
                    type: string
                    description: >-
                      Time-limited download URL present when `status` is
                      `completed`. Mirror the file to your own storage for long
                      retention.
                example:
                  id: video_69b25d5f467c81908733a56bc236b4df
                  size: 1280x720
                  error: null
                  model: sora-2
                  object: video
                  prompt: A paper airplane glides across a desk.
                  status: in_progress
                  seconds: '4'
                  progress: 0
                  created_at: 1773296991
                  expires_at: null
                  completed_at: null
                  remixed_from_video_id: null
              examples:
                In progress:
                  summary: Task still rendering
                  value:
                    id: <video_id>
                    model: sora-2
                    object: video
                    status: in_progress
                    progress: 30
                    created_at: 1781079478
                Completed:
                  summary: Finished task with video URL
                  value:
                    id: <video_id>
                    model: sora-2
                    object: video
                    status: completed
                    progress: 100
                    video_url: >-
                      https://comet-api-bucket.s3.us-east-1.amazonaws.com/videos/<video_id>.mp4?...
                    created_at: 1781079478
                    completed_at: 1781079550
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            VIDEO_ID="<video_id>"

            curl "https://api.cometapi.com/v1/videos/$VIDEO_ID" \
              -H "Authorization: Bearer $COMETAPI_KEY"
        - lang: Shell
          label: Poll until done
          source: |
            VIDEO_ID="<video_id>"

            while true; do
              STATUS=$(curl -s "https://api.cometapi.com/v1/videos/$VIDEO_ID" \
                -H "Authorization: Bearer $COMETAPI_KEY" | python3 -c "import json,sys; print(json.load(sys.stdin)['status'])")
              echo "status: $STATUS"
              case "$STATUS" in completed | failed) break;; esac
              sleep 20
            done
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            video_id = "<video_id>"

            response = requests.get(
                f"https://api.cometapi.com/v1/videos/{video_id}",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
            )

            print(response.json())
        - lang: Python
          label: Poll until done
          source: |
            import os
            import time
            import requests

            video_id = "<video_id>"
            headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}

            while True:
                video = requests.get(
                    f"https://api.cometapi.com/v1/videos/{video_id}", headers=headers
                ).json()
                print(video["status"], video.get("progress"))
                if video["status"] in ("completed", "failed"):
                    break
                time.sleep(20)

            if video["status"] == "completed":
                print(video["video_url"])
        - lang: JavaScript
          label: Default
          source: >
            const videoId = "<video_id>";


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


            console.log(await response.json());
        - lang: JavaScript
          label: Poll until done
          source: >
            const videoId = "<video_id>";

            const headers = { Authorization: `Bearer
            ${process.env.COMETAPI_KEY}` };


            let video;

            while (true) {
                video = await (await fetch(`https://api.cometapi.com/v1/videos/${videoId}`, { headers })).json();
                console.log(video.status, video.progress);
                if (video.status === "completed" || video.status === "failed") break;
                await new Promise((resolve) => setTimeout(resolve, 20000));
            }


            if (video.status === "completed") console.log(video.video_url);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````