文生视频
创建 Kling 兼容文生视频任务。
Create Task
Request
http
POST /v1/videos/text2video| 字段 | 类型 | 必填 | 支持值与限制 | 说明 |
|---|---|---|---|---|
model_name | string | 是 | kling-v2-5-turbo、kling-v3 | 模型名。kling-v2-5-turbo 适合基础文生视频;kling-v3 支持更多时长和多镜头。 |
prompt | string | 否 | 最长 2500 字符 | kling-v2-5-turbo 下必填。kling-v3 下当 multi_shot=false 时必填,用于描述主体、动作、场景、镜头和风格;当 multi_shot=true 时该字段无效。 |
multi_shot | boolean | 否 | 仅 kling-v3;true、false | 是否生成多镜头视频,默认 false。当 multi_shot=true 时,prompt 无效;当 multi_shot=false 时,shot_type 和 multi_prompt 无效。kling-v2-5-turbo 不支持该字段。 |
shot_type | string | 否 | 仅 kling-v3;仅支持 customize | 当 multi_shot=true 时必填;当 multi_shot=false 时该字段无效。当前仅支持自定义分镜,intelligence 不支持。 |
multi_prompt | array | 否 | 仅 kling-v3;1 到 6 项 | 当 multi_shot=true 且 shot_type=customize 时必填;当 multi_shot=false 时该字段无效,用于逐镜头定义提示词和时长。 |
multi_prompt[].index | integer | 是 | 仅 kling-v3 | 分镜序号,建议从 1 开始递增。 |
multi_prompt[].prompt | string | 是 | 仅 kling-v3;最长 512 字符 | 当前分镜的提示词,可写该镜头的主体、动作、场景、机位和风格。 |
multi_prompt[].duration | string | 是 | 仅 kling-v3;每段至少 1 秒 | 当前分镜时长,所有分镜时长之和必须等于总 duration。 |
negative_prompt | string | 否 | 最长 2500 字符 | 负向提示词,用于约束不希望出现的内容、风格或瑕疵。 |
sound | string | 否 | 仅 kling-v3;on、off | 是否同时生成音频,默认 off。kling-v2-5-turbo 不支持该字段。 |
mode | string | 否 | std、pro | 生成模式。std 为标准模式,偏性价比;pro 为高质量模式。4k 不支持。 |
aspect_ratio | string | 否 | 16:9、9:16、1:1 | 输出画面宽高比,默认 16:9。 |
duration | string | 否 | kling-v2-5-turbo:5、10;kling-v3:3 到 15 | 视频总时长,单位秒。多镜头时,所有 multi_prompt[].duration 之和要等于这里的值。 |
watermark_info | object | 否 | {"enabled": boolean} | 是否同时返回带水印结果。 |
external_task_id | string | 否 | 自定义字符串 | 自定义任务 ID,可用于后续查询;同一账号下应保持唯一。 |
Response
json
{
"code": 0,
"message": "success",
"request_id": "req_abc123",
"data": {
"task_id": "sg_vid_xxxxxxxx",
"task_status": "submitted",
"created_at": 1776209922,
"updated_at": 1776209922
}
}Example
基础示例
bash
curl -sS "https://api.exchangetoken.ai/v1/videos/text2video" \
-H "Authorization: Bearer sk-xxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kling-v3",
"prompt": "雨夜城市街道中一辆红色电车穿过路口,地面有反光,电影感镜头",
"negative_prompt": "模糊,低质量",
"mode": "pro",
"sound": "off",
"aspect_ratio": "16:9",
"duration": "5",
"watermark_info": {"enabled": false}
}'多镜头示例
bash
curl -sS "https://api.exchangetoken.ai/v1/videos/text2video" \
-H "Authorization: Bearer sk-xxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kling-v3",
"multi_shot": true,
"shot_type": "customize",
"multi_prompt": [
{"index": 1, "prompt": "清晨安静的咖啡馆,阳光穿过窗户", "duration": "2"},
{"index": 2, "prompt": "白色咖啡杯上升起热气的特写", "duration": "3"}
],
"mode": "pro",
"sound": "on",
"aspect_ratio": "16:9",
"duration": "5"
}'Query Task
Request
http
GET /v1/videos/text2video/{task_id}后续轮询使用 data.task_id。
Response
json
{
"code": 0,
"message": "success",
"request_id": "req_abc123",
"data": {
"task_id": "sg_vid_xxxxxxxx",
"task_status": "succeed",
"watermark_info": {
"enabled": false
},
"task_result": {
"videos": [
{
"url": "https://example.com/output.mp4"
}
]
},
"created_at": 1776209922,
"updated_at": 1776210072
}
}状态枚举
task_status | 含义 |
|---|---|
submitted | 任务已接受,尚未开始执行。 |
processing | 任务排队中或执行中。 |
succeed | 任务完成,可能包含 task_result.videos。 |
failed | 任务失败或已取消。若存在 task_status_msg,可查看失败原因。 |
Example
bash
curl -sS "https://api.exchangetoken.ai/v1/videos/text2video/sg_vid_xxxxxxxx" \
-H "Authorization: Bearer sk-xxxxxx"