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

# Get a Kling model-route task

> Get the status and video output of one Kling model-route task by its task ID.

Use this endpoint after a Kling model-route creation request. Save `data.id` from the creation response and pass that ID as `task_ids`.

## Request parameter

| Parameter  | Required | Description                                                                      |
| ---------- | -------- | -------------------------------------------------------------------------------- |
| `task_ids` | Yes      | One task ID returned by a model-route creation request. Send one ID per request. |

To retrieve one task, replace `<task_id>` with the `data.id` value from the creation response:

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

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

Immediately after creation, the response contains the submitted task:

```json theme={null}
{
  "id": "<task_id>",
  "status": "submitted"
}
```

## Read the result

The response contains either a task object or a `data` array with one task. Read the task's `status`. When it is `succeeded`, read the video URL from that task's `outputs` array. An array response can also contain a top-level `status`; use the status inside `data[0]` for the selected task.

A completed task has this response shape:

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

| Field                | Description                                                              |
| -------------------- | ------------------------------------------------------------------------ |
| `id`                 | Task ID from the creation response.                                      |
| `status`             | Current task state. Continue querying until it reaches a terminal state. |
| `message`            | Task detail returned when available.                                     |
| `outputs[].type`     | Output media type. Select an item with `type: video`.                    |
| `outputs[].url`      | Video URL to download or store when the task succeeds.                   |
| `outputs[].duration` | Video duration in seconds when returned.                                 |

Store the finished video in your own storage if you need to retain it beyond the returned URL's availability.


## 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 one Kling task
      description: Retrieve one task created through a Kling model route by its task ID.
      operationId: getKlingModelRouteTask
      parameters:
        - name: task_ids
          in: query
          required: true
          description: One task ID from the `data.id` field of a creation response.
          schema:
            type: string
          example: <task_id>
      responses:
        '200':
          description: Current state and available outputs for the requested task.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/TaskItem'
                  - $ref: '#/components/schemas/TaskEnvelope'
              examples:
                Submitted:
                  summary: Task record immediately after creation
                  value:
                    id: <task_id>
                    status: submitted
                Completed:
                  summary: Task record with a video output
                  value:
                    code: 0
                    message: SUCCEED
                    status: SUCCEEDED
                    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:
    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.
    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: >-
            Response-level status when returned, such as `SUCCEEDED`. 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 ID.
          items:
            $ref: '#/components/schemas/TaskItem'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Use your CometAPI API key as a Bearer token.

````