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

# 取得 Seedance 影片

> 透過 GET /v1/videos/{id} 在 CometAPI 依 id 輪詢 Seedance 影片任務。適用於 Seedance 1.0 Pro、1.5 Pro 與 2.0 任務。會回傳目前狀態、進度，以及任務達到 completed 後的已簽名 `video_url`。

使用此端點來讀取透過[建立 Seedance 影片](./create)所建立任務的狀態。路徑中的 `id` 是建立呼叫回傳的值，不論該任務是由哪個 Seedance 模型產生。

回應主體就是影片任務物件本身。請在頂層讀取 `status`、`progress` 與 `video_url`。

## 狀態機制

API 會回傳小寫的狀態字串。`queued` 與 `in_progress` 是非終態；`completed`、`failed` 與 `error` 是終態，任務之後不會再變動。

| 狀態            | 意義                      | 終態 |
| ------------- | ----------------------- | -- |
| `queued`      | 已接受並排入渲染佇列。             | 否  |
| `in_progress` | 正在渲染中。                  | 否  |
| `completed`   | 已完成。回應中會包含 `video_url`。 | 是  |
| `failed`      | 供應商拒絕了該任務。              | 是  |
| `error`       | 內部錯誤導致無法完成。             | 是  |

## 輪詢頻率

每 10 到 20 秒輪詢一次。多數工作會在 1 到 3 分鐘內完成，實際時間取決於模型、時長與尺寸。

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

TASK_ID = "<TASK_ID>"
headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}
TERMINAL = {"completed", "failed", "error"}

while True:
    response = requests.get(
        f"https://api.cometapi.com/v1/videos/{TASK_ID}",
        headers=headers,
        timeout=15,
    )
    response.raise_for_status()
    data = response.json()
    if data["status"] in TERMINAL:
        print(data.get("video_url"))
        break
    time.sleep(10)
```

## 需要關注的欄位

* `status` — 決定你的輪詢迴圈何時停止的條件。
* `progress` — 介於 0 到 100 的整數，可用於在 UI 中顯示。
* `video_url` — 已簽名的下載 URL，會出現在 `completed` 回應中。Seedance 下載會直接使用此 URL，而不是使用獨立的 `/v1/videos/{id}/content` 路由。簽名有時間限制；請在簽名到期前下載或重新託管該檔案。
* `completed_at` — 平台回傳的選用 Unix 時間戳。不要用它來停止輪詢；請改用 `status`。
* `model` — 回傳建立任務時所使用的 Seedance model id。

## 常見錯誤

* HTTP `400` 且 `message: "task_not_exist"` 表示該 `id` 不存在。請確認你已從成功的 POST `/v1/videos` 回應中取得 `id`，並且原樣使用。
* HTTP `401` 表示 bearer token 遺失或無效。請檢查請求標頭是否為 `Authorization: Bearer $COMETAPI_KEY`。


## OpenAPI

````yaml api/openapi/video/seedance/get-seedance-query.openapi.json GET /v1/videos/{id}
openapi: 3.1.0
info:
  title: Seedance Video Task Retrieval API
  version: 1.0.0
  description: >-
    Poll a Seedance video task by id. The same endpoint serves Seedance 1.0 Pro,
    1.5 Pro, and 2.0 tasks. It returns the current status, progress, and a
    signed video_url once the task reaches completed.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /v1/videos/{id}:
    get:
      summary: Retrieve a Seedance video task
      description: >-
        Read the latest state of a video task that was created through POST
        /v1/videos. Works for every Seedance model family. Poll every 10 to 20
        seconds until status reaches a terminal value (`completed`, `failed`, or
        `error`). `video_url` is returned on `completed` responses.
      operationId: seedance_retrieve_video
      parameters:
        - name: id
          in: path
          required: true
          description: Task id returned by POST /v1/videos.
          schema:
            type: string
          example: task_abc123
      responses:
        '200':
          description: Current Seedance video task state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VideoTask'
              examples:
                in_progress:
                  summary: Task still running
                  value:
                    id: task_abc123
                    object: video
                    model: doubao-seedance-2-0
                    status: in_progress
                    progress: 30
                    created_at: 1777385418
                    completed_at: 1777385485
                completed:
                  summary: Task finished successfully
                  value:
                    id: task_abc123
                    object: video
                    model: doubao-seedance-2-0
                    status: completed
                    progress: 100
                    created_at: 1777385418
                    completed_at: 1777385526
                    video_url: https://example.com/seedance-output.mp4
                failed:
                  summary: Task ended with an error
                  value:
                    id: task_abc123
                    object: video
                    model: doubao-seedance-2-0
                    status: failed
                    progress: 0
                    created_at: 1777385418
                    completed_at: 1777385526
        '400':
          description: The id does not match any task.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                task_not_exist:
                  summary: Unknown task id
                  value:
                    code: null
                    message: task_not_exist
        '401':
          description: The API key is missing or invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Bearer token rejected
                  value:
                    error:
                      code: ''
                      message: invalid token
                      type: comet_api_error
      x-codeSamples:
        - lang: Shell
          label: Retrieve task status
          source: |
            curl https://api.cometapi.com/v1/videos/<TASK_ID> \
              -H "Authorization: Bearer $COMETAPI_KEY"
        - lang: Python
          label: Retrieve task status
          source: |
            import os
            import time
            import requests

            TASK_ID = "<TASK_ID>"
            headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}
            TERMINAL = {"completed", "failed", "error"}

            while True:
                response = requests.get(
                    f"https://api.cometapi.com/v1/videos/{TASK_ID}",
                    headers=headers,
                    timeout=15,
                )
                response.raise_for_status()
                data = response.json()
                print(data["status"], data.get("progress"))
                if data["status"] in TERMINAL:
                    print(data.get("video_url"))
                    break
                time.sleep(10)
        - lang: JavaScript
          label: Retrieve task status
          source: |
            const TASK_ID = "<TASK_ID>";
            const terminal = new Set(["completed", "failed", "error"]);

            while (true) {
              const response = await fetch(
                `https://api.cometapi.com/v1/videos/${TASK_ID}`,
                { headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` } },
              );
              const data = await response.json();
              console.log(data.status, data.progress);
              if (terminal.has(data.status)) {
                console.log(data.video_url);
                break;
              }
              await new Promise((resolve) => setTimeout(resolve, 10_000));
            }
components:
  schemas:
    VideoTask:
      type: object
      required:
        - id
        - object
        - model
        - status
        - progress
        - created_at
      properties:
        id:
          type: string
          description: Task id.
        object:
          type: string
          description: Object type, always `video`.
        model:
          type: string
          description: Model id that generated the task.
        status:
          type: string
          enum:
            - queued
            - in_progress
            - completed
            - failed
            - error
          description: >-
            Task status. `queued` and `in_progress` are non-terminal.
            `completed`, `failed`, and `error` are terminal.
        progress:
          type: integer
          minimum: 0
          maximum: 100
          description: Completion percentage.
        video_url:
          type:
            - string
            - 'null'
          description: >-
            Signed download URL for the finished video. Present on `completed`
            responses. Seedance downloads use this URL directly instead of a
            separate `/v1/videos/{id}/content` route. The signature is
            time-limited, so download or re-upload the file to your own storage
            soon after you receive it.
        created_at:
          type: integer
          description: Task creation time as a Unix timestamp in seconds.
        completed_at:
          type:
            - integer
            - 'null'
          description: >-
            Optional Unix timestamp returned by the platform. Use `status`, not
            this field, to decide when polling can stop.
      additionalProperties: true
    ErrorResponse:
      description: >-
        Error body. The endpoint returns one of two shapes depending on where
        the validation fails.
      oneOf:
        - type: object
          properties:
            code:
              type:
                - string
                - 'null'
            message:
              type: string
          required:
            - message
          additionalProperties: true
        - type: object
          properties:
            error:
              type: object
              properties:
                code:
                  type:
                    - string
                    - 'null'
                message:
                  type: string
                type:
                  type: string
              required:
                - message
                - type
              additionalProperties: true
          required:
            - error
          additionalProperties: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````