# 查询 Kling v4 任务状态

> 视频生成

根据提交响应中的 `output.task_id` 查询任务；成功时 `output.urls` 返回生成资源地址。

## 请求地址

`GET https://api.modelverse.cn/v1/tasks/status`

## 请求参数

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| task_id | query | string | Yes | 提交任务返回的 `output.task_id`。 |

## 响应

- **200** — 任务状态响应。
- **400** — 任务标识无效或查询失败。
- **default** — 错误响应。

## OpenAPI 定义

```json
{
  "openapi": "3.1.0",
  "x-language": "zh-CN",
  "info": {
    "title": "Kling v4 视频生成接口文档",
    "version": "1.0.0",
    "description": "ModelVerse 统一以 `kling-v4` 提供文生视频、图生视频和 Omni 视频生成。\n使用 `POST /v1/tasks/submit` 提交任务，使用 `GET /v1/tasks/status` 查询结果。\n对外模型名只有 `kling-v4`；通过 `parameters.kling_type` 或输入素材选择生成类型。\n"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "ModelVerse 接口地址。"
    }
  ],
  "tags": [
    {
      "name": "Kling/v4",
      "description": "Kling v4 异步视频任务接口。"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/tasks/submit": {
      "post": {
        "tags": [
          "Kling/v4"
        ],
        "operationId": "submitKlingV4Task",
        "summary": "提交 Kling v4 视频生成任务",
        "description": "`kling_type` 可取 `t2v`、`i2v`、`omni_video`；不传时，视频或 Omni 专属素材优先推断为 `omni_video`，否则图片推断为 `i2v`，其余为 `t2v`。\nt2v 只使用 `input.prompt`，不接受 `parameters.contents`；i2v 和 Omni 可以使用 `input` 中的素材字段，或在 `parameters.contents` 中直接提供内容项。\n显式类型与输入不相容时会报错。图片输入不等于视频输入；视频输入按最终的 `base_video` 或 `feature_video` 内容项判定。\nOmni 多素材任务可为 `parameters.contents` 中的素材设置唯一的 `id`，再在提示词中使用 `@id` 引用。\n引用时建议写明每份素材要保留或参考的内容、作用范围，以及整体场景、事件顺序和声音要求；仅写 `@id` 而不说明用途可能导致模型自行推断。\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KlingV4SubmitRequest"
              },
              "examples": {
                "textToVideo": {
                  "summary": "文生视频",
                  "value": {
                    "model": "kling-v4",
                    "input": {
                      "prompt": "一只橘猫走过雨后的街道，电影质感"
                    },
                    "parameters": {
                      "kling_type": "t2v",
                      "duration": 5,
                      "resolution": "720p",
                      "aspect_ratio": "16:9"
                    }
                  }
                },
                "firstAndLastFrames": {
                  "summary": "首尾帧图生视频",
                  "value": {
                    "model": "kling-v4",
                    "input": {
                      "prompt": "镜头缓缓推进，人物自然转身",
                      "first_frame_url": "https://example.com/first-frame.png",
                      "last_frame_url": "https://example.com/last-frame.png"
                    },
                    "parameters": {
                      "kling_type": "i2v",
                      "duration": 5,
                      "resolution": "1080p"
                    }
                  }
                },
                "contentsFirstAndLastFrames": {
                  "summary": "通过 contents 指定首尾帧",
                  "value": {
                    "model": "kling-v4",
                    "input": {},
                    "parameters": {
                      "kling_type": "i2v",
                      "duration": 5,
                      "resolution": "1080p",
                      "contents": [
                        {
                          "type": "prompt",
                          "text": "镜头缓缓推进，人物自然转身"
                        },
                        {
                          "type": "first_frame",
                          "url": "https://example.com/first-frame.png"
                        },
                        {
                          "type": "last_frame",
                          "url": "https://example.com/last-frame.png"
                        }
                      ]
                    }
                  }
                },
                "omniVideoInput": {
                  "summary": "Omni 视频输入",
                  "value": {
                    "model": "kling-v4",
                    "input": {
                      "prompt": "参考 @video_1 的动作节奏，保留主体动作但不使用原背景；将画面转换为电影风格，加入轻柔环境声"
                    },
                    "parameters": {
                      "kling_type": "omni_video",
                      "duration": 5,
                      "resolution": "720p",
                      "contents": [
                        {
                          "type": "base_video",
                          "url": "https://example.com/source-video.mp4",
                          "id": "video_1"
                        }
                      ]
                    }
                  }
                },
                "omniMultiReference": {
                  "summary": "Omni 图片与视频素材引用",
                  "value": {
                    "model": "kling-v4",
                    "input": {
                      "prompt": "保持 @image_1 中人物的面孔、发型与服装；参考 @video_1 的动作节奏，不使用其中的背景。夜晚城市街道，电影质感；先缓慢转身，再走向镜头，保留脚步声并加入轻柔配乐。"
                    },
                    "parameters": {
                      "kling_type": "omni_video",
                      "duration": 5,
                      "resolution": "1080p",
                      "contents": [
                        {
                          "type": "refer_image",
                          "url": "https://example.com/character.png",
                          "id": "image_1"
                        },
                        {
                          "type": "feature_video",
                          "url": "https://example.com/motion-reference.mp4",
                          "id": "video_1"
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "任务提交成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KlingV4SubmitResponse"
                },
                "example": {
                  "output": {
                    "task_id": "task_id"
                  },
                  "request_id": "request_id"
                }
              }
            }
          },
          "400": {
            "description": "参数不合法或任务创建失败。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KlingV4ErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "错误响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KlingV4ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/tasks/status": {
      "get": {
        "tags": [
          "Kling/v4"
        ],
        "operationId": "getKlingV4TaskStatus",
        "summary": "查询 Kling v4 任务状态",
        "description": "根据提交响应中的 `output.task_id` 查询任务；成功时 `output.urls` 返回生成资源地址。",
        "parameters": [
          {
            "name": "task_id",
            "in": "query",
            "required": true,
            "description": "提交任务返回的 `output.task_id`。",
            "schema": {
              "type": "string"
            },
            "example": "task_id"
          }
        ],
        "responses": {
          "200": {
            "description": "任务状态响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KlingV4StatusResponse"
                },
                "examples": {
                  "success": {
                    "summary": "已成功",
                    "value": {
                      "output": {
                        "task_id": "task_id",
                        "task_status": "Success",
                        "urls": [
                          "https://example.com/result.mp4"
                        ],
                        "submit_time": 1756959000,
                        "finish_time": 1756959050
                      },
                      "usage": {
                        "duration": 5
                      },
                      "request_id": ""
                    }
                  },
                  "failure": {
                    "summary": "已失败",
                    "value": {
                      "output": {
                        "task_id": "task_id",
                        "task_status": "Failure",
                        "submit_time": 1756959000,
                        "finish_time": 1756959019,
                        "error_message": "任务生成失败"
                      },
                      "request_id": ""
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "任务标识无效或查询失败。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KlingV4ErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "错误响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KlingV4ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "在 `Authorization: Bearer <YOUR_API_KEY>` 请求头中传入 ModelVerse API 密钥。"
      }
    },
    "schemas": {
      "KlingV4SubmitRequest": {
        "type": "object",
        "required": [
          "model",
          "input"
        ],
        "properties": {
          "model": {
            "type": "string",
            "const": "kling-v4"
          },
          "input": {
            "$ref": "#/components/schemas/KlingV4Input"
          },
          "parameters": {
            "$ref": "#/components/schemas/KlingV4Parameters"
          }
        }
      },
      "KlingV4Input": {
        "type": "object",
        "description": "必须传入 `input` 对象。t2v 必须提供 `prompt`，且不能带图片或视频素材。\ni2v 至少需要一张图片；Omni 必须提供提示词，可放在 `input.prompt` 或 `parameters.contents` 的 prompt 项中。\n上游图片素材要求：JPG、JPEG、PNG；单张不超过 30 MB；宽和高均不小于 300 px；宽高比在 2:5～5:2 之间；可使用图片 URL 或 Base64。\n上游视频素材要求：MP4、MOV；单段不超过 300 MB；输入视频时长 3～30 秒；宽和高均在 700～4553 px 之间；\n总像素面积不超过 8,294,400；宽高比在 2:5～5:2 之间；帧率 24～60 fps；视频通过 URL 提供。\n以上为上游素材规格，并非本接口在提交时对媒体文件逐项完成的校验。\n",
        "properties": {
          "prompt": {
            "type": "string",
            "description": "生成提示词。非 t2v 模式下会与 `contents` 中的 prompt 项合并；如两者都存在，文本必须一致。\nOmni 多素材任务可用 `@素材ID` 引用 `parameters.contents` 中设置了 id 的素材，例如 `@image_1`；\n建议按“素材用途＋整体设定＋分段事件＋声音要求”组织描述，明确每份素材应保留、参考或排除的内容及其作用范围。\n"
          },
          "first_frame_url": {
            "type": "string",
            "description": "首帧图片地址；未指定 kling_type 时可触发 i2v。",
            "example": "https://example.com/first-frame.png"
          },
          "last_frame_url": {
            "type": "string",
            "description": "尾帧图片地址；与首帧配合使用。",
            "example": "https://example.com/last-frame.png"
          },
          "img_url": {
            "type": "string",
            "description": "首帧图片的兼容输入字段。"
          },
          "images": {
            "type": "array",
            "description": "图片列表；首张归一为 first_frame，其余归一为 middle_frame。",
            "items": {
              "type": "string"
            }
          },
          "video_url": {
            "type": "string",
            "description": "视频兼容输入字段；归一为 base_video，并可触发 omni_video。",
            "example": "https://example.com/source-video.mp4"
          }
        }
      },
      "KlingV4Parameters": {
        "type": "object",
        "properties": {
          "kling_type": {
            "type": "string",
            "enum": [
              "t2v",
              "i2v",
              "omni_video"
            ],
            "description": "选择子类型；不传时按素材自动推断。显式指定时必须与素材及子模型限制匹配。\n类型会参与计费分档；只有一个对外模型 `kling-v4`。\n"
          },
          "duration": {
            "type": "integer",
            "minimum": 3,
            "maximum": 30,
            "description": "目标输出时长，单位秒。V4 适配器接受非零的 3～30 秒整数，但任务入口优先按该模型计费配置中的 `allowed_duration` 校验；\n只有该列表包含所请求时长，才能使用相应秒数（尤其是 16～30 秒）。不传时服务不会根据 `default_duration` 自动赋值。\n"
          },
          "resolution": {
            "type": "string",
            "enum": [
              "720p",
              "1080p"
            ],
            "description": "输出分辨率；服务会先转为小写再校验，因此也接受 `720P`、`1080P`。"
          },
          "aspect_ratio": {
            "type": "string",
            "enum": [
              "21:9",
              "16:9",
              "9:16",
              "1:1",
              "adaptive"
            ],
            "description": "仅 t2v 和 Omni 可传；`adaptive` 仅 Omni 支持；i2v 传入此字段会报错。"
          },
          "contents": {
            "type": "array",
            "description": "i2v / Omni 使用的内容项；t2v 不接受。可改用 input 中的素材字段让服务自动转换为 contents。\n与旧式图片/视频字段同时传入时必须逐项完全一致，否则会报错；推荐只选择一种素材表达方式。\n为需要在 Prompt 中引用的素材设置唯一 id，并在 `input.prompt` 或 prompt 内容项的 text 中使用 `@id`。\n",
            "items": {
              "$ref": "#/components/schemas/KlingV4Content"
            }
          },
          "watermark_enabled": {
            "type": "boolean",
            "description": "控制水印；未传时使用 `watermark`（如有）。"
          },
          "watermark": {
            "type": "boolean",
            "description": "兼容的水印开关，优先级低于 `watermark_enabled`。"
          },
          "external_task_id": {
            "type": "string",
            "description": "传递给上游的自定义任务 ID；查询任务仍使用提交响应的 `output.task_id`。"
          }
        }
      },
      "KlingV4Content": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "prompt",
              "first_frame",
              "middle_frame",
              "last_frame",
              "refer_image",
              "base_video",
              "feature_video",
              "element",
              "voice"
            ],
            "description": "i2v 仅接受 prompt 和 first_frame / middle_frame / last_frame；refer_image、视频、element、voice 需使用 Omni。\n"
          },
          "text": {
            "type": "string",
            "description": "type=prompt 时必填且不能为空白；可使用 @id 引用同一 contents 中带 id 的素材。"
          },
          "url": {
            "type": "string",
            "description": "图片和视频内容项必填；图片可使用 URL 或 Base64，视频通过 URL 提供；详细媒体规格见 KlingV4Input 描述。"
          },
          "id": {
            "type": "string",
            "description": "素材 ID，存在时在同一任务内不可重复；element 和 voice 必填。可在 Prompt 中以 @id 引用，例如 id 为 image_1 时写 @image_1。"
          },
          "element_id": {
            "type": "string",
            "description": "type=element 时必填。"
          },
          "voice_id": {
            "type": "string",
            "description": "type=voice 时必填。"
          }
        },
        "description": "i2v 要求 1～10 张图片；Omni 最多 10 张图片、5 个视频（其中 base_video 最多 1 个）、7 个 element、3 个 voice，\n图片/视频/element/voice 合计最多 15 项，且必须有 prompt。内容的 id 不可重复。\n"
      },
      "KlingV4SubmitResponse": {
        "type": "object",
        "required": [
          "output",
          "request_id"
        ],
        "properties": {
          "output": {
            "type": "object",
            "required": [
              "task_id"
            ],
            "properties": {
              "task_id": {
                "type": "string",
                "description": "用于状态查询的异步任务 ID。"
              }
            }
          },
          "request_id": {
            "type": "string",
            "description": "本次提交请求的标识。"
          }
        }
      },
      "KlingV4StatusResponse": {
        "type": "object",
        "required": [
          "output",
          "request_id"
        ],
        "properties": {
          "output": {
            "type": "object",
            "required": [
              "task_id",
              "task_status"
            ],
            "properties": {
              "task_id": {
                "type": "string"
              },
              "task_status": {
                "type": "string",
                "enum": [
                  "Pending",
                  "Running",
                  "Success",
                  "Failure",
                  "Unknown",
                  "Cancelled",
                  "Expired"
                ],
                "description": "对外的任务状态。"
              },
              "urls": {
                "type": "array",
                "description": "成功时的结果资源地址；当前 Vtrix 适配器提取首个可用视频或图片地址。",
                "items": {
                  "type": "string"
                }
              },
              "submit_time": {
                "type": "integer",
                "format": "int64",
                "description": "任务提交的 Unix 秒级时间戳。"
              },
              "finish_time": {
                "type": "integer",
                "format": "int64",
                "description": "任务完成的 Unix 秒级时间戳。"
              },
              "error_message": {
                "type": "string",
                "description": "任务失败时的错误信息。"
              }
            }
          },
          "usage": {
            "type": "object",
            "description": "任务用量；`duration` 来自上游用量，优先使用 `quantity`，否则使用 `duration`。",
            "properties": {
              "duration": {
                "type": "integer",
                "description": "上游返回的计费用量或时长，单位秒，不一定等于请求中的目标输出时长。"
              }
            }
          },
          "request_id": {
            "type": "string",
            "description": "状态查询响应中当前为空字符串。"
          }
        }
      },
      "KlingV4ErrorResponse": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "error": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "param": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "request_id": {
            "type": "string"
          }
        }
      }
    }
  }
}
```
