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

# 获取 Kling 模型路由任务

> 通过任务 ID 获取 Kling 模型路由任务的状态和视频输出。

创建 Kling 模型路由请求后使用此端点。保存创建响应中的 `data.id`，并将该 ID 作为 `task_ids` 传入。

## 请求参数

| 参数 | 必填 | 说明 |
| - | - | - |
| `task_ids` | 是 | 模型路由创建请求返回的任务 ID，位于 `data.id`. |

要检索单个任务，请将 `<task_id>` 替换为创建响应中的 `data.id` 值：

```bash theme={null}
task_id="<task_id>"

curl "https://api.cometapi.com/tasks?task_ids=${task_id}" \
  -H "Authorization: Bearer $COMETAPI_KEY"
```

创建后，响应会立即包含已提交的任务：

```json theme={null}
{
  "code": 0,
  "message": "SUCCEED",
  "data": [
    {
      "id": "<task_id>",
      "status": "submitted"
    }
  ]
}
```

## 读取结果

从 `data[0]` 读取任务，并持续查询，直至其 `status` 进入终态。当状态为 `succeeded` 时，从该任务的 `outputs` 数组中读取视频 URL。某些观察到的 Comet 兼容性响应会返回裸任务对象，或包含顶层 `status`；这些是兼容性形式，而非规范封装。当存在 `data` 时，请使用 `data[0].status`。

已完成任务的响应结构如下：

```json theme={null}
{
  "code": 0,
  "message": "SUCCEED",
  "data": [
    {
      "id": "<task_id>",
      "status": "succeeded",
      "outputs": [
        {
          "type": "video",
          "url": "https://media.example.com/video.mp4",
          "duration": "5.041"
        }
      ]
    }
  ]
}
```

| 字段 | 说明 |
| - | - |
| `id` | 创建响应中的任务 ID。 |
| `status` | 当前任务状态。持续查询，直到其进入终态。 |
| `message` | 可用时返回的任务详情。 |
| `outputs[].type` | 输出媒体类型。请选择带有 `type: video`. |
| `outputs[].url` | 任务成功时用于下载或存储的视频 URL。 |
| `outputs[].duration` | 返回时的视频时长（秒）。 |

如果需要在返回的 URL 可用期结束后继续保留视频，请将完成的视频存储到您自己的存储空间中。


## OpenAPI

````yaml api/openapi/video/kling/model-routes/get-tasks.openapi.json GET /tasks
openapi: 3.1.0
info:
  title: Get a Kling model-route task
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /tasks:
    get:
      summary: Get a Kling task
      description: >-
        Retrieve the status and outputs for a task created through a Kling model
        route by its task ID.
      operationId: getKlingModelRouteTask
      parameters:
        - name: task_ids
          in: query
          required: true
          description: >-
            Task ID from the `data.id` field of a creation response. This
            CometAPI route documents one `task_ids` value per request.
          schema:
            type: string
          example: <task_id>
      responses:
        '200':
          description: >-
            The task state and available outputs are returned in the `data`
            array.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskEnvelope'
              examples:
                Submitted:
                  summary: Submitted task in the data array
                  value:
                    code: 0
                    message: SUCCEED
                    data:
                      - id: <task_id>
                        status: submitted
                Completed:
                  summary: Completed task with a video output
                  value:
                    code: 0
                    message: SUCCEED
                    data:
                      - id: <task_id>
                        status: succeeded
                        outputs:
                          - type: video
                            url: https://media.example.com/video.mp4
                            duration: '5.041'
      x-codeSamples:
        - lang: Shell
          label: Get task
          source: |
            task_id="<task_id>"

            curl "https://api.cometapi.com/tasks?task_ids=${task_id}" \
              -H "Authorization: Bearer $COMETAPI_KEY"
        - lang: Python
          label: Get task
          source: |
            import os
            import requests

            task_id = "<task_id>"
            response = requests.get(
                "https://api.cometapi.com/tasks",
                params={"task_ids": task_id},
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
            )
            response.raise_for_status()
            payload = response.json()
            task = payload.get("data", payload)
            if isinstance(task, list):
                task = task[0]
            print(task["status"], task.get("outputs", []))
        - lang: JavaScript
          label: Get task
          source: |
            const taskId = "<task_id>";
            const url = new URL("https://api.cometapi.com/tasks");
            url.searchParams.set("task_ids", taskId);
            const response = await fetch(url, {
              headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
            });
            if (!response.ok) throw new Error(`HTTP ${response.status}`);
            const payload = await response.json();
            const data = payload.data ?? payload;
            const task = Array.isArray(data) ? data[0] : data;
            console.log(task.status, task.outputs ?? []);
components:
  schemas:
    TaskEnvelope:
      type: object
      required:
        - data
      properties:
        code:
          oneOf:
            - type: integer
            - type: string
          description: Response code returned with the task list.
        message:
          type: string
          description: Response message returned with the task list.
        status:
          type: string
          description: >-
            Observed Comet compatibility response-level status when returned.
            Read the selected task state from `data[0].status`.
        request_id:
          type: string
          description: Request ID for support when returned.
        data:
          type: array
          minItems: 1
          maxItems: 1
          description: >-
            The task record returned for the requested task. The current
            CometAPI route returns it as `data[0]`.
          items:
            $ref: '#/components/schemas/TaskItem'
      description: >-
        Canonical task response for the CometAPI route. Read the selected task
        from `data[0]`; a bare task object is a compatibility form.
    TaskItem:
      type: object
      required:
        - id
        - status
      properties:
        id:
          type: string
          description: Task ID returned when the video task was created.
        status:
          type: string
          description: >-
            Task state, such as `submitted`, `processing`, `succeeded`, or
            `failed`.
        message:
          type: string
          description: Task detail when returned.
        outputs:
          type: array
          description: Generated media when the task returns outputs.
          items:
            type: object
            properties:
              id:
                type: string
                description: Generated output ID when returned.
              type:
                type: string
                description: Output media type, such as `video`.
              url:
                type: string
                format: uri
                description: URL of the generated media.
              duration:
                type: string
                description: Generated media duration in seconds when returned.
        create_time:
          type: integer
          description: Task creation time in Unix milliseconds when returned.
        update_time:
          type: integer
          description: Last task update time in Unix milliseconds when returned.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Use your CometAPI API key as a Bearer token.

````

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