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

# SeeDance Tasks API 的對接和使用

> ByteDance Seedance Video Generation 集成指南 - XHuoAPI

SeeDance Tasks API 的主要功能是通過輸入 SeeDance Video Generation API 生成的任務ID來查詢該任務的執行情況。

本文檔將詳細介紹 SeeDance Tasks API 的對接說明，幫助您輕鬆集成並充分利用該 API 的強大功能。通過 SeeDance Tasks API ，您可以輕鬆實現查詢 SeeDance Video Generation API 的任務執行情況。

## 申請流程

要使用 SeeDance Tasks API，需要先到 申請頁面 [SeeDance Video Generation API](https://api.xhuoapi.ai/documents/seedance-videos)申請相應的服務，然後複製 SeeDance Video Generation API的任務ID，如圖所示：

<p>
  <img src="https://cdn.xhuoapi.ai/om6p6g.png" width="500" className="m-auto" />
</p>

最後進入Tasks API頁面 [SeeDance Tasks API](https://api.xhuoapi.ai/documents/seedance-tasks)申請相應的服務，進入頁面之後，點擊「Acquire」按鈕，如圖所示：

![申請頁面](https://cdn.xhuoapi.ai/rci31i.png)

如果您尚未登錄或註冊，會自動跳轉到[登錄頁面](https://api.xhuoapi.ai)邀請您來註冊和登錄，登錄註冊之後會自動返回當前頁面。

首次申請時會有免費額度贈送，可以免費使用該 API。

## 請求示例

SeeDance Tasks API 可以用於查詢 SeeDance Video Generation API 的結果。關於怎樣使用 SeeDance Video Generation API，請參考文檔 [SeeDance Video Generation API ](https://api.xhuoapi.ai/documents/seedance-videos-integration)。

我們以 SeeDance Video Generation API 服務返回的任務ID一個為例，演示如何使用該 API。假設我們有一個任務ID：20068983-0cc9-4c6a-aeb6-9c6a3c668be0，接下來演示如何通過傳入一個任務ID來。

### 任務示例圖

<p>
  <img src="https://cdn.xhuoapi.ai/om6p6g.png" width="500" className="m-auto" />
</p>

### 設置請求頭和請求體

**Request Headers** 包括：

* `accept`：指定接收 JSON 格式的響應結果，這裡填寫為 `application/json`。
* `authorization`：調用 API 的密鑰，申請之後可以直接下拉選擇。

**Request Body** 包括：

* `id`：上傳的任務ID。
* `action`：對任務的操作方式。

設置如下圖所示：

<p>
  <img src="https://cdn.xhuoapi.ai/yuyte9.png" width="500" className="m-auto" />
</p>

### 代碼示例

可以發現，在頁面右側已經自動生成了各種語言的代碼，如圖所示：

<p>
  <img src="https://cdn.xhuoapi.ai/b0wt0d.png" width="500" className="m-auto" />
</p>

部分代碼示例如下：

#### CURL

```bash theme={null}
curl -X POST 'https://api.xhuoapi.ai/v1/seedance/tasks' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "id": "a6e0d456-189b-4c78-9232-2fe72166ab39",
  "action": "retrieve"
}'
```

### 響應示例

請求成功後，API 將返回此處任務的詳細信息。例如：

```json theme={null}
{
    "_id": "69480c5cff2676299c7b351d",
    "id": "9462ca25-468b-45a5-9e75-6f516dedcc80",
    "api_id": "44e45d2b-8754-4a93-b793-c63271335f6f",
    "application_id": "1456a4bf-e2f4-4247-9b2d-fb49effc6eca",
    "created_at": 1766329436.091, 
    "credential_id": "3e20b461-f750-48d3-a1f7-3aea48d15d77",
    "request": {
        "model": "doubao-seedance-1-0-pro-250528",
        "content": [
            {
                "type": "text",
                "text": "多個鏡頭。一名偵探進入一間光線昏暗的房間。他檢查桌上的線索，手裡拿起桌上的某個物品。鏡頭轉向他正在思索。 --ratio 16:9"
            }
        ],
        "callback_url": "dummy"
    },
    "trace_id": "24b1b09c-5649-4290-98db-eab23e5efcac",
    "type": "videos",
    "user_id": "ad7afe47-cea9-4cda-980f-2ad8810e51cf",
    "response": {
        "success": true,
        "task_id": "9462ca25-468b-45a5-9e75-6f516dedcc80",
        "trace_id": "24b1b09c-5649-4290-98db-eab23e5efcac",
        "data": {
            "task_id": "cgt-20251221230356-sxgt7",
            "status": "succeeded",
            "video_url": "https://platform.cdn.xhuoapi.ai/seedance/d1c2e49e-d854-4a2e-b0c0-88e520f82e2e.mp4",
            "last_frame_url": null,
            "model": "doubao-seedance-1-0-pro-250528"
        }
    }
}
```

返回結果一共有多個字段，request 字段就是發起任務時的 request body，同時response 字段是任務完成後返回的response body。字段介紹如下。

* `id`，生成任務的 ID，用於唯一標識此次生成任務。
* `request`，查詢任務中的請求信息。
* `response`，查詢任務中的返回信息。

## 批量查詢操作

這是是針對多個任務ID來進行查詢任務詳細信息，與上面不同的是需要將action選中為retrieve\_batch

**Request Body** 包括：

* `ids`：上傳的任務ID數組。
* `action`：對任務的操作方式。

設置如下圖所示：

<p>
  <img src="https://cdn.xhuoapi.ai/ycc4th.png" width="500" className="m-auto" />
</p>

### 代碼示例

可以發現，在頁面右側已經自動生成了各種語言的代碼，如圖所示：

<p>
  <img src="https://cdn.xhuoapi.ai/u6bt64.png" width="500" className="m-auto" />
</p>

部分代碼示例如下：

### 響應示例

請求成功後，API 將返回此次所有批量任務的具體詳細信息。例如：

```json theme={null}
{
    "items": [
        {
            "_id": "69480c5cff2676299c7b351d",
            "id": "9462ca25-468b-45a5-9e75-6f516dedcc80",
            "api_id": "44e45d2b-8754-4a93-b793-c63271335f6f",
            "application_id": "1456a4bf-e2f4-4247-9b2d-fb49effc6eca",
            "created_at": 1766329436.091,
            "credential_id": "3e20b461-f750-48d3-a1f7-3aea48d15d77",
            "request": {
                "model": "doubao-seedance-1-0-pro-250528",
                "content": [
                    {
                        "type": "text",
                        "text": "多個鏡頭。一名偵探進入一間光線昏暗的房間。他檢查桌上的線索，手裡拿起桌上的某個物品。鏡頭轉向他正在思索。 --ratio 16:9"
                    }
                ],
                "callback_url": "dummy"
            },
            "trace_id": "24b1b09c-5649-4290-98db-eab23e5efcac",
            "type": "videos",
            "user_id": "ad7afe47-cea9-4cda-980f-2ad8810e51cf",
            "response": {
                "success": true,
                "task_id": "9462ca25-468b-45a5-9e75-6f516dedcc80",
                "trace_id": "24b1b09c-5649-4290-98db-eab23e5efcac",
                "data": {
                    "task_id": "cgt-20251221230356-sxgt7",
                    "status": "succeeded",
                    "video_url": "https://platform.cdn.xhuoapi.ai/seedance/d1c2e49e-d854-4a2e-b0c0-88e520f82e2e.mp4",
                    "last_frame_url": null,
                    "model": "doubao-seedance-1-0-pro-250528"
                }
            }
        },
        {
            "_id": "69480e0dff2676299c7cb98b",
            "id": "d9e576bd-ca14-4c6f-a541-f4734e941dbe",
            "api_id": "44e45d2b-8754-4a93-b793-c63271335f6f",
            "application_id": "1456a4bf-e2f4-4247-9b2d-fb49effc6eca",
            "created_at": 1766329436.091,
            "credential_id": "3e20b461-f750-48d3-a1f7-3aea48d15d77",
            "request": {
                "model": "doubao-seedance-1-0-pro-250528",
                "content": [
                    {
                        "type": "text",
                        "text": "多個鏡頭。一名偵探進入一間光線昏暗的房間。他檢查桌上的線索，手裡拿起桌上的某個物品。鏡頭轉向他正在思索。 --ratio 16:9"
                    }
                ],
                "callback_url": "dummy"
            },
            "trace_id": "e3da01aa-5026-4653-8d07-c68c4fcf466a",
            "type": "videos",
            "user_id": "ad7afe47-cea9-4cda-980f-2ad8810e51cf",
            "response": {
                "success": true,
                "task_id": "d9e576bd-ca14-4c6f-a541-f4734e941dbe",
                "trace_id": "e3da01aa-5026-4653-8d07-c68c4fcf466a",
                "data": {
                    "task_id": "cgt-20251221231109-cnkhp",
                    "status": "succeeded",
                    "video_url": "https://platform.cdn.xhuoapi.ai/seedance/eb99ba03-178c-4616-8d19-e625fee2e884.mp4",
                    "last_frame_url": null,
                    "model": "doubao-seedance-1-0-pro-250528"
                }
            }
        }
    ],
    "count": 2
}
```

返回結果一共有多個字段，其中items是包含了批量任務的具體詳情信息，每個任務的具體信息與上文的字段一樣，字段信息如下。

* `items`，批量任務的所有具體詳情信息。它是一個數組，每個數組的元素和上文查詢單個任務的返回結果格式是一樣的。
* `count`，此處批量查詢任務的個數。

#### CURL

```bash theme={null}
curl -X POST 'https://api.xhuoapi.ai/v1/seedance/tasks' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "ids": ["9462ca25-468b-45a5-9e75-6f516dedcc80","d9e576bd-ca14-4c6f-a541-f4734e941dbe"],
  "action": "retrieve_batch"
}'
```

## 錯誤處理

在調用 API 時，如果遇到錯誤，API 會返回相應的錯誤代碼和信息。例如：

* `400 token_mismatched`：Bad request, possibly due to missing or invalid parameters.
* `400 api_not_implemented`：Bad request, possibly due to missing or invalid parameters.
* `401 invalid_token`：Unauthorized, invalid or missing authorization token.
* `429 too_many_requests`：Too many requests, you have exceeded the rate limit.
* `500 api_error`：Internal server error, something went wrong on the server.

### 錯誤響應示例

```json theme={null}
{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
```

## 結論

通過本文檔，您已經了解了如何使用 SeeDance Tasks API 進行查詢單個或批量任務的所有具體詳情信息。希望本文檔能幫助您更好地對接和使用該 API。如有任何問題，請隨時聯繫我們的技術支持團隊。
