Kling Text-to-Video
创建文生视频任务,并跟踪其完成或失败状态。
概览
使用支持的模型创建异步文生视频任务。使用返回的任务 ID 查询状态,或提供 callback_url 接收终态投递。
快速开始
- 创建 API Key,并将其设置为 RUNAPI_API_KEY。
- 选择一个支持的模型,并发送与该模型 Schema 匹配的 POST 请求。
- 保存返回的任务 ID,随后轮询到终态,或处理终态回调。
端点
- 基础 URL
https://runapi.ai- API 版本
v1- 身份验证
Authorization: Bearer YOUR_API_TOKEN
支持的模型
打开模型页可查看当前价格、限流和商业使用详情。
请求 Schema
字段和允许的取值取决于所选模型。提供 callback_url 后,它会收到任务终态投递。
kling-3.014 个字段
aspect_ratiostringOutput aspect ratio.
可选值:16:9, 9:16, 1:1
callback_urlstringWebhook URL for async notifications.
cfg_scalenumberGuidance scale (0-1).
duration_secondsintegerDuration in seconds.
可选值:3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
enable_soundbooleanEnable sound generation.
first_frame_image_urlstringFirst frame image URL.
kling_elementsarrayElement references with image, video, or audio materials.
last_frame_image_urlstringLast frame image URL for single-shot mode.
modelstringModel slug.
multi_promptarrayPrompt segments for multi-shot mode.
multi_shotsbooleanEnable multi-shot generation.
negative_promptstringNegative prompt.
output_resolutionstringOutput resolution.
可选值:720p, 1080p, 4k
promptstringVideo description. Required unless multi_shots is enabled.
kling-o111 个字段
aspect_ratiostringOutput aspect ratio.
可选值:16:9, 9:16, 1:1
默认值: 16:9
callback_urlstringWebhook URL for async notifications.
duration_secondsintegerDuration in seconds.
可选值:5
默认值: 5
enable_soundbooleanSound generation must remain disabled.
默认值:false
modestringGeneration mode.
可选值:std, pro
默认值: std
modelstringModel slug.
preserve_reference_video_audiobooleanPreserve the reference video's original audio.
默认值:false
promptstringVideo description; reference media with matching numbered markers.
范围:1 - 2500
reference_image_urlsarrayOrdered public HTTP(S) JPG, JPEG, or PNG reference image URLs.
reference_video_typestringUse the video as a base edit or feature reference.
可选值:base, feature
默认值: base
reference_video_urlstringPublic HTTP(S) MP4 or MOV reference video URL.
kling-v2.1-master-text-to-video8 个字段
aspect_ratiostringOutput aspect ratio.
可选值:16:9, 9:16, 1:1
callback_urlstringWebhook URL for async notifications.
cfg_scalenumberGuidance scale (0-1).
duration_secondsintegerDuration in seconds.
可选值:5, 10
enable_soundbooleanEnable sound generation.
modelstringModel slug.
negative_promptstringNegative prompt.
promptstringVideo description.
kling-v2.5-turbo-text-to-video-pro8 个字段
aspect_ratiostringOutput aspect ratio.
可选值:16:9, 9:16, 1:1
callback_urlstringWebhook URL for async notifications.
cfg_scalenumberGuidance scale (0-1).
duration_secondsintegerDuration in seconds.
可选值:5, 10
enable_soundbooleanEnable sound generation.
modelstringModel slug.
negative_promptstringNegative prompt.
promptstringVideo description.
kling-v2.67 个字段
aspect_ratiostringOutput aspect ratio.
可选值:16:9, 9:16, 1:1
默认值: 16:9
callback_urlstringWebhook URL for async notifications.
duration_secondsintegerDuration in seconds.
可选值:5, 10
默认值: 5
enable_soundbooleanEnable sound generation; requires pro mode.
默认值:false
modestringGeneration mode.
可选值:std, pro
默认值: std
modelstringModel slug.
promptstringVideo description.
范围:1 - 2500
kling-v3-omni7 个字段
aspect_ratiostringOutput aspect ratio.
可选值:16:9, 9:16, 1:1
默认值: 16:9
callback_urlstringWebhook URL for async notifications.
duration_secondsintegerDuration in seconds.
可选值:3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
默认值: 5
enable_soundbooleanEnable synchronized sound generation.
默认值:false
modelstringModel slug.
output_resolutionstringOutput resolution.
可选值:720p, 1080p, 4k
默认值: 720p
promptstringVideo description.
范围:1 - 2500
kling-v3-turbo-text-to-video6 个字段
aspect_ratiostringOutput aspect ratio.
可选值:16:9, 9:16, 1:1
默认值: 16:9
callback_urlstringWebhook URL for async notifications.
duration_secondsintegerDuration in seconds.
可选值:3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
默认值: 5
modelstringModel slug.
output_resolutionstringOutput resolution.
可选值:720p, 1080p
默认值: 720p
promptstringVideo description.
范围:1 - 2500
创建已接受
POST /api/v1/kling/text_to_video
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
轮询处理中
GET /api/v1/kling/text_to_video/:id
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
轮询已完成
GET /api/v1/kling/text_to_video/:id
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "completed",
"videos": [
{
"url": "https://file.runapi.ai/reference-video.mp4"
}
]
}
轮询失败
GET /api/v1/kling/text_to_video/:id
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"error": "Task processing failed.",
"id": "tsk_reference_demo",
"status": "failed"
}
客户回调:已完成
POST callback_url
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "completed",
"videos": [
{
"url": "https://file.runapi.ai/reference-video.mp4"
}
]
}
客户回调:失败
POST callback_url
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"error": {
"code": "generation_failed",
"message": "Task processing failed."
},
"id": "tsk_reference_demo",
"status": "failed"
}
错误
{
"error": {
"code": "invalid_request",
"message": "A required request field is missing."
}
}
生成的代码示例
直接使用 cURL,或安装所用语言的 SDK。每个示例都会提交本参考中经过验证的请求。
curl -X POST https://runapi.ai/api/v1/kling/text_to_video \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"model":"kling-v3-turbo-text-to-video","prompt":"A paper kite flying above a quiet coastal town at sunrise","duration_seconds":5,"aspect_ratio":"16:9","output_resolution":"720p"}'
安装
npm install @runapi.ai/kling
import { KlingClient } from "@runapi.ai/kling";
const client = new KlingClient({ apiKey: process.env.RUNAPI_API_KEY });
const task = await client.textToVideo.create({
"model": "kling-v3-turbo-text-to-video",
"prompt": "A paper kite flying above a quiet coastal town at sunrise",
"duration_seconds": 5,
"aspect_ratio": "16:9",
"output_resolution": "720p"
});
安装
pip install runapi-kling
import os
from runapi.kling import KlingClient
client = KlingClient(api_key=os.environ["RUNAPI_API_KEY"])
task = client.text_to_video.create(
model="kling-v3-turbo-text-to-video",
prompt="A paper kite flying above a quiet coastal town at sunrise",
duration_seconds=5,
aspect_ratio="16:9",
output_resolution="720p"
)
安装
go get github.com/runapi-ai/kling-sdk/go@latest
package main
import (
"context"
"log"
"os"
"github.com/runapi-ai/core-sdk/go/option"
kling "github.com/runapi-ai/kling-sdk/go/kling"
)
func main() {
client, err := kling.NewClient(option.WithAPIKey(os.Getenv("RUNAPI_API_KEY")))
if err != nil {
log.Fatal(err)
}
_, err = client.TextToVideo.Create(context.Background(), kling.TextToVideoParams{
Model: "kling-v3-turbo-text-to-video",
Prompt: "A paper kite flying above a quiet coastal town at sunrise",
DurationSeconds: 5,
AspectRatio: "16:9",
OutputResolution: "720p",
})
if err != nil {
log.Fatal(err)
}
}
安装
gem install runapi-kling
client = RunApi::Kling::Client.new(api_key: ENV.fetch("RUNAPI_API_KEY"))
task = client.text_to_video.create(
model: "kling-v3-turbo-text-to-video",
prompt: "A paper kite flying above a quiet coastal town at sunrise",
duration_seconds: 5,
aspect_ratio: "16:9",
output_resolution: "720p"
)
安装
implementation("ai.runapi:runapi-kling")
import ai.runapi.core.polling.TaskCreateResponse;
import ai.runapi.kling.KlingClient;
import ai.runapi.kling.types.TextToVideoParams;
KlingClient client = KlingClient.builder()
.apiKey(System.getenv("RUNAPI_API_KEY"))
.build();
TaskCreateResponse task = client.textToVideo().create(
TextToVideoParams.builder()
.model("kling-v3-turbo-text-to-video")
.prompt("A paper kite flying above a quiet coastal town at sunrise")
.durationSeconds(5)
.aspectRatio("16:9")
.outputResolution("720p")
.build()
);
安装
composer require runapi-ai/kling
<?php
use RunApi\Core\ClientOptions;
use RunApi\Kling\KlingClient;
$client = new KlingClient(new ClientOptions(apiKey: getenv('RUNAPI_API_KEY')));
$task = $client->textToVideo->create([
"model" => "kling-v3-turbo-text-to-video",
"prompt" => "A paper kite flying above a quiet coastal town at sunrise",
"duration_seconds" => 5,
"aspect_ratio" => "16:9",
"output_resolution" => "720p"
]);