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

# 動画タスクの照会

> 動画生成タスクのステータスと結果を照会

作成エンドポイントが返したタスクIDを使い、送信済みのMixRoute動画タスクを照会します。共通エンドポイントを使うファミリーで、この共通のポーリング手順を使用します。

`GET https://api.mixroute.ai/v1/video/generations/{task_id}`

<ParamField path="task_id" type="string" required>
  送信時に返されたMixRouteのタスクID。
</ParamField>

```bash theme={null}
curl "https://api.mixroute.ai/v1/video/generations/TASK_ID" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY"
```

## レスポンスとステータス

ルートによって、タスクがトップレベル、`data`の内部、またはベンダーの`task`オブジェクトの内部に返される場合があります。比較前にステータスの大文字・小文字を統一してください。これらの構造は選択肢であり、すべてのレスポンスに必ず含まれるフィールドではありません。

| 状態 | 値 | 操作 |
| - | - | - |
| 待機中 | `queued`, `pending`, `submitted`, `NOT_START` | ポーリングを続けてください。 |
| 実行中 | `running`, `in_progress` | ポーリングを続けてください。 |
| 成功 | `succeeded`, `SUCCESS`, `completed` | resultオブジェクトを読み取り、出力をダウンロードしてください。 |
| 終端の失敗状態 | `failed`, `FAILURE`, `expired`, `cancelled`, `canceled` | ポーリングを停止し、`error`/`fail_reason`を確認します。 |

## 結果の格納場所

| レスポンスの構造 | 動画の場所 |
| - | - |
| MixRoute wrapper | `data.result_url` / `data.url` |
| タスクを直接返す形式 | `url` / `result_url` |
| Seedanceネイティブの結果 | タスク内の`content.video_url`（例：`data.data.content.video_url`）。 |
| MiniMax H3 result | タスクのエンベロープ内の`data.result_url`または`data.data.task.content.video_url`。ベンダーネイティブのレスポンスでは`task.content.url`が使われる場合があります。 |
| Veoネイティブの結果 | 返されたすべてのサンプル／動画を確認してください。ネイティブのGoogleの結果には、単一のトップレベルURLではなく、動画URIやエンコードされたデータが含まれる場合があります。 |
| Wan | SUCCESS後はdata.result\_urlを使用します。ネイティブの出力と使用量はdata.dataに含まれます。[Wanの詳細](/ja/api-reference/endpoint/wan)。 |
| Sora 2 | [動画のダウンロード](/ja/api-reference/endpoint/download-video) |

利用するルートからの実際のレスポンスを使用してください。`response.status`のみ、または`response.url`のみを確認するクライアントでは、ラップされた成功ステータスや結果を見落とす可能性があります。

### 例：ラッパー内の成功レスポンス

```json theme={null}
{
  "code": "success",
  "message": "",
  "data": {
    "task_id": "TASK_ID",
    "status": "SUCCESS",
    "result_url": "https://example.com/generated-video.mp4"
  }
}
```

## ポーリングの例

この例では、HTTPとアプリケーションエラーを確認し、一般的なラッパー構造を処理し、終端状態で停止し、クライアント側の期限を適用します。呼び出し元がルート固有の出力フィールドを処理できるよう、タスクオブジェクトを返します。

```python theme={null}
import os
import time
from urllib.parse import quote
import requests

def unpack_task(payload):
    task = payload
    for _ in range(6):
        if not isinstance(task, dict):
            raise ValueError("Unexpected task response")
        if task.get("error"):
            raise RuntimeError(task["error"])
        code = task.get("code")
        if code not in (None, 0, 200, "0", "200", "success"):
            raise RuntimeError(task.get("message") or task)
        if task.get("status"):
            return str(task["status"]).lower(), task
        nested = task.get("task")
        if not isinstance(nested, dict):
            nested = task.get("data")
        if not isinstance(nested, dict):
            break
        task = nested
    raise ValueError("Task status is missing from the response")

def wait_for_video(task_id, timeout_seconds=1200):
    deadline = time.monotonic() + timeout_seconds
    url = "https://api.mixroute.ai/v1/video/generations/" + quote(task_id, safe="")
    delay = 10
    pending = {"queued", "pending", "submitted", "not_start", "running", "in_progress"}
    terminal = {"failed", "failure", "expired", "cancelled", "canceled"}
    with requests.Session() as session:
        session.headers["Authorization"] = "Bearer " + os.environ["MIXROUTE_API_KEY"]
        while time.monotonic() < deadline:
            remaining = deadline - time.monotonic()
            if remaining <= 0:
                break
            response = session.get(url, timeout=min(30, remaining))
            if response.status_code in (429, 500, 502, 503, 504):
                delay = min(delay * 2, 30)
            else:
                response.raise_for_status()
                status, task = unpack_task(response.json())
                if status in {"success", "succeeded", "completed"}:
                    return task
                if status in terminal:
                    raise RuntimeError(task.get("fail_reason") or task.get("error") or task)
                if status not in pending:
                    raise ValueError("Unknown task status: " + status)
                delay = 10
            remaining = deadline - time.monotonic()
            if remaining <= 0:
                break
            time.sleep(min(delay, remaining))
    raise TimeoutError("Video task did not finish before the client deadline")

if __name__ == "__main__":
    print(wait_for_video("TASK_ID"))
```

約10秒間隔でポーリングしてください。レート制限や一時的なサーバーエラーが発生した場合は、間隔を延ばしてください。出力は速やかにダウンロードしてください。

[Seedance](/ja/api-reference/endpoint/seedance) | [Doubao](/ja/api-reference/endpoint/doubao) | [Dreamina](/ja/api-reference/endpoint/dreamina) | [Veo](/ja/api-reference/endpoint/veo) | [MiniMax H3](/ja/api-reference/endpoint/minimax-h3)

Wanでは、約15秒間隔でポーリングします。失敗したタスクではresult\_urlにエラーテキストが含まれる場合があります。statusがSUCCESSになるまで、このフィールドをダウンロード可能なURLとして扱わないでください。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.