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

# Kling 任务查询

> 查询 Kling 视频、图片生成和虚拟试穿任务的状态与结果

> 更新日期：2026-06-06

# Kling 任务查询

## 可查询的任务路径

| 路径                                                     | 用途           |
| ------------------------------------------------------ | ------------ |
| `GET /kling/v1/videos/text2video/{task_id}`            | 查询文生视频任务     |
| `GET /kling/v1/videos/image2video/{task_id}`           | 查询图生视频任务     |
| `GET /kling/v1/videos/multi-image2video/{task_id}`     | 查询参考图生视频任务   |
| `GET /kling/v1/videos/omni-video/{task_id}`            | 查询 Omni 视频任务 |
| `GET /kling/v1/images/generations/{task_id}`           | 查询图片生成任务     |
| `GET /kling/v1/images/kolors-virtual-try-on/{task_id}` | 查询虚拟试穿任务     |

## 响应格式

所有 Kling 查询接口统一返回同一类任务结构：

```json theme={null}
{
  "code": "success",
  "message": "",
  "data": {
    "error": null,
    "format": "mp4",
    "metadata": null,
    "status": "SUCCESS",
    "task_id": "866168216002236456",
    "result_url": "https://media.crazyrouter.com/task-artifacts/2026/06/30/kling/866168216002236456.mp4",
    "artifact_url": "https://media.crazyrouter.com/task-artifacts/2026/06/30/kling/866168216002236456.mp4"
  }
}
```

### 排队中

```json theme={null}
{
  "code": "success",
  "message": "",
  "data": {
    "error": null,
    "format": "mp4",
    "metadata": null,
    "status": "queued",
    "task_id": "task_abc123",
    "result_url": "",
    "artifact_url": ""
  }
}
```

### 处理中

```json theme={null}
{
  "code": "success",
  "message": "",
  "data": {
    "error": null,
    "format": "mp4",
    "metadata": null,
    "status": "processing",
    "task_id": "task_abc123",
    "result_url": "",
    "artifact_url": ""
  }
}
```

### 已完成

```json theme={null}
{
  "code": "success",
  "message": "",
  "data": {
    "error": null,
    "format": "mp4",
    "metadata": null,
    "status": "SUCCESS",
    "task_id": "866168216002236456",
    "result_url": "https://media.crazyrouter.com/task-artifacts/2026/06/30/kling/866168216002236456.mp4",
    "artifact_url": "https://media.crazyrouter.com/task-artifacts/2026/06/30/kling/866168216002236456.mp4"
  }
}
```

### 失败

```json theme={null}
{
  "code": "success",
  "message": "",
  "data": {
    "error": {
      "message": "content moderation failed",
      "code": "task_failed"
    },
    "format": "mp4",
    "metadata": null,
    "status": "failed",
    "task_id": "task_abc123",
    "result_url": "",
    "artifact_url": ""
  }
}
```

## 任务状态

| 状态           | 说明                                      |
| ------------ | --------------------------------------- |
| `queued`     | 已提交或排队中                                 |
| `processing` | 正在生成                                    |
| `SUCCESS`    | 已完成，`result_url` 或 `artifact_url` 可直接访问 |
| `failed`     | 终态失败                                    |

***

## 完整流程示例

```python Python theme={null}
import requests
import time

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.crazyrouter.com"
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {API_KEY}"
}

# 1. 提交文生视频任务
resp = requests.post(
    f"{BASE_URL}/kling/v1/videos/text2video",
    headers=headers,
    json={
        "model_name": "kling-v2-5-turbo",
        "prompt": "一只猫咪在花园里追蝴蝶",
        "duration": "5",
        "aspect_ratio": "16:9"
    }
)
task_id = resp.json()["data"]["task_id"]

# 2. 轮询查询
while True:
    resp = requests.get(
        f"{BASE_URL}/kling/v1/videos/text2video/{task_id}",
        headers=headers
    )
    data = resp.json()["data"]

    if data["status"] == "SUCCESS":
        print(f"视频地址: {data.get('artifact_url') or data.get('result_url')}")
        break
    if data["status"] == "failed":
        print(f"失败: {data['error']}")
        break

    time.sleep(10)
```

<Note>
  Kling 的标准视频、Omni 视频、图片和试穿任务结果都可能返回站内归档地址 `media.crazyrouter.com/...`。对客户端来说，优先消费 `artifact_url` 或 `result_url` 即可，无需再解析上游原始 CDN。
</Note>
