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

> Query Kling video generation tasks by task_id via GET /kling/v1/{action}/{action2}/{task_id}, returning status, progress, and result metadata for polling.

Use this endpoint family after you create a Kling task. It is the common polling step for Kling async media jobs.

## What to check first

* `code`, `message`, and `request_id` for the query acknowledgement
* `data.task_status` for the task state, such as `submitted`, `processing`, `succeed`, or `failed`
* `data.task_result.videos[0].url` when the task succeeds
* `data.task_status_msg` or other returned detail fields when a task stops early

## Polling pattern

<Steps>
  <Step title="Create the task from the matching endpoint">
    Start with the Kling creation page for your workflow, such as [Text to Video](./text-to-video) or [Image to Video](./image-to-video).
  </Step>

  <Step title="Poll until the task is terminal">
    Keep querying with the returned task id until `data.task_status` reaches `succeed` or `failed`.
  </Step>

  <Step title="Continue to the next workflow step">
    Use the finished output directly, or move into the next provider-specific action page if your workflow supports chained operations.
  </Step>
</Steps>

## Common path pairs

| Workflow          | Query path                                      |
| ----------------- | ----------------------------------------------- |
| Text to video     | `/kling/v1/videos/text2video/{task_id}`         |
| Image to video    | `/kling/v1/videos/image2video/{task_id}`        |
| Multi-image video | `/kling/v1/videos/multi-image2video/{task_id}`  |
| Video effects     | `/kling/v1/videos/effects/{task_id}`            |
| Video extension   | `/kling/v1/videos/video-extend/{task_id}`       |
| Avatar video      | `/kling/v1/videos/avatar/image2video/{task_id}` |

<Note>
  For the full parameter reference, see the [official Kling documentation](https://docs.qingque.cn/d/home/eZQClW07IFEuX1csc-VejdY2M).
</Note>


## OpenAPI

````yaml api/openapi/video/kling/get-individual-queries.openapi.json GET /kling/v1/{action}/{action2}/{task_id}
openapi: 3.1.0
info:
  title: Individual queries  API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/{action}/{action2}/{task_id}:
    get:
      summary: 'Individual queries '
      description: >-
        The example uses `videos/text2video`; substitute the action segments
        that match your task type, such as `images/generations` or
        `audio/text-to-audio`.
      operationId: individual_queries
      parameters:
        - name: action
          in: path
          required: true
          description: 'Resource type. One of: `images`, `videos`, `audio`.'
          schema:
            type: string
        - name: action2
          in: path
          required: true
          description: >-
            Sub-action matching the resource type. For `images`: `generations`,
            `kolors-virtual-try-on`. For `videos`: `text2video`, `image2video`,
            `lip-sync`, `effects`, `multi-image2video`, `multi-elements`. For
            `audio`: `text-to-audio`, `video-to-audio`.
          schema:
            type: string
        - name: task_id
          in: path
          required: true
          description: Task ID
          schema:
            type: string
      responses:
        '200':
          description: Current Kling task state.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - request_id
                  - data
                properties:
                  code:
                    type: integer
                    description: Kling response code. 0 indicates the query was accepted.
                  message:
                    type: string
                    description: Kling response message.
                  request_id:
                    type: string
                    description: Identifier for this query request.
                  data:
                    type: object
                    required:
                      - task_id
                      - task_status
                      - task_info
                      - created_at
                      - updated_at
                    properties:
                      task_id:
                        type: string
                        description: Kling task id.
                      task_status:
                        type: string
                        description: Current task state.
                        enum:
                          - submitted
                          - processing
                          - succeed
                          - failed
                      task_status_msg:
                        type: string
                        description: Failure or status detail when returned.
                      task_info:
                        type: object
                        description: Additional task metadata. The object can be empty.
                        additionalProperties: true
                      task_result:
                        type: object
                        description: >-
                          Result metadata. Present as an empty object while
                          processing and populated on success.
                        properties:
                          videos:
                            type: array
                            description: Generated videos.
                            items:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: Generated video id.
                                url:
                                  type: string
                                  description: Generated video URL.
                                duration:
                                  type: string
                                  description: Video duration in seconds.
                        additionalProperties: true
                      created_at:
                        type: integer
                        description: Task creation timestamp in milliseconds.
                      updated_at:
                        type: integer
                        description: Last task update timestamp in milliseconds.
                      final_unit_deduction:
                        type: string
                        description: >-
                          Final unit deduction returned after a successful task,
                          when available.
              examples:
                Processing:
                  summary: Task still rendering
                  value:
                    code: 0
                    message: SUCCEED
                    request_id: <task_id>
                    data:
                      task_id: <task_id>
                      task_status: processing
                      task_info: {}
                      task_result: {}
                      created_at: 1781080355827
                      updated_at: 1781080362336
                Succeed:
                  summary: Finished task with video result
                  value:
                    code: 0
                    message: SUCCEED
                    data:
                      task_id: <task_id>
                      task_status: succeed
                      task_info: {}
                      created_at: 1781074110938
                      updated_at: 1781074171088
                      task_result:
                        videos:
                          - id: <video_id>
                            url: https://storage.fonedis.cc/.../video.mp4
                            duration: '5.1'
      x-codeSamples:
        - lang: Shell
          label: Default
          source: >
            TASK_ID="<task_id>"


            curl "https://api.cometapi.com/kling/v1/videos/text2video/$TASK_ID"
            \
              -H "Authorization: Bearer $COMETAPI_KEY"
        - lang: Shell
          label: Poll until done
          source: |
            TASK_ID="<task_id>"

            while true; do
              STATUS=$(curl -s "https://api.cometapi.com/kling/v1/videos/text2video/$TASK_ID" \
                -H "Authorization: Bearer $COMETAPI_KEY" | python3 -c "import json,sys; print(json.load(sys.stdin)['data']['task_status'])")
              echo "status: $STATUS"
              case "$STATUS" in succeed | failed) break;; esac
              sleep 30
            done
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            task_id = "<task_id>"

            response = requests.get(
                f"https://api.cometapi.com/kling/v1/videos/text2video/{task_id}",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
            )

            print(response.json()["data"]["task_status"])
        - lang: Python
          label: Poll until done
          source: |
            import os
            import time
            import requests

            task_id = "<task_id>"
            headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}

            while True:
                data = requests.get(
                    f"https://api.cometapi.com/kling/v1/videos/text2video/{task_id}", headers=headers
                ).json()["data"]
                print(data["task_status"])
                if data["task_status"] in ("succeed", "failed"):
                    break
                time.sleep(30)

            if data["task_status"] == "succeed":
                print(data["task_result"])
        - lang: JavaScript
          label: Default
          source: >
            const taskId = "<task_id>";


            const response = await
            fetch(`https://api.cometapi.com/kling/v1/videos/text2video/${taskId}`,
            {
                headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
            });


            const result = await response.json();

            console.log(result.data.task_status);
        - lang: JavaScript
          label: Poll until done
          source: >
            const taskId = "<task_id>";

            const headers = { Authorization: `Bearer
            ${process.env.COMETAPI_KEY}` };


            let data;

            while (true) {
                data = (await (await fetch(`https://api.cometapi.com/kling/v1/videos/text2video/${taskId}`, { headers })).json()).data;
                console.log(data.task_status);
                if (data.task_status === "succeed" || data.task_status === "failed") break;
                await new Promise((resolve) => setTimeout(resolve, 30000));
            }


            if (data.task_status === "succeed") console.log(data.task_result);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````