> ## 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 上の Seedance 動画タスクを id でポーリングします。Seedance 1.0 Pro、1.5 Pro、2.0 の各タスクに対応しています。現在の status、progress、およびタスクが completed に達した後の署名付き video_url を返します。

このエンドポイントは、[Seedance 動画を作成する](./create) で作成したタスクの状態を取得するために使用します。パス内の `id` は、どの Seedance モデルがタスクを生成したかに関係なく、作成時の呼び出しで返された値です。

レスポンス本文は動画タスクオブジェクトそのものです。トップレベルの `status`、`progress`、`video_url` を確認してください。

## ステータスマシン

API は小文字の status 文字列を返します。`queued` と `in_progress` は非終端で、`completed`、`failed`、`error` は終端です。終端に達すると、タスクはそれ以上変化しません。

| Status        | 意味                                 | Terminal |
| ------------- | ---------------------------------- | -------- |
| `queued`      | 受け付けられ、レンダリング待ちキューに入っています。         | no       |
| `in_progress` | レンダリング中です。                         | no       |
| `completed`   | 完了しています。レスポンスに `video_url` が含まれます。 | yes      |
| `failed`      | プロバイダーがタスクを拒否しました。                 | yes      |
| `error`       | 内部エラーにより完了できませんでした。                | yes      |

## ポーリング間隔

10〜20秒ごとにポーリングしてください。ほとんどのジョブは、model、duration、size に応じて 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` — UI に表示できる 0〜100 の整数です。
* `video_url` — 署名付きダウンロード URL で、`completed` レスポンスに含まれます。Seedance のダウンロードでは、別の `/v1/videos/{id}/content` ルートではなく、この URL を直接使用します。署名には有効期限があるため、期限が切れる前にファイルをダウンロードするか再ホストしてください。
* `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.

````