Kling 4.0
kling-4-0 · Video · unitool
Видео до 30 секунд в 720p и 1080p: из текста, по ключевым кадрам или по вашим видео. Можно добавить своих персонажей и голоса.
Generations are async: create, wait or poll, the result by link for 7 days. Details: Media generations
Текст → видео
Mode t2v · kling-4-0:t2v
Price
Depends on the parameters: 108 tokens for the example below, base 108. Get the exact price of your request from POST /v1/quotes.
Price make-up (pricing from GET /v1/models/{id})
{
"unit": "tokens",
"kind": "by_parameters",
"base": 108,
"example_price": 108,
"matrix": [
{
"when": {
"resolution": "720p"
},
"when_set": [
"elements_duration_sec"
],
"rate": 12.84,
"per": "duration",
"plus": [
"elements_duration_sec"
],
"plus_mode": "max"
},
{
"when": {
"resolution": "1080p"
},
"when_set": [
"elements_duration_sec"
],
"rate": 19.25,
"per": "duration",
"plus": [
"elements_duration_sec"
],
"plus_mode": "max"
},
{
"when": {
"resolution": "720p"
},
"rate": 21.52,
"per": "duration"
},
{
"when": {
"resolution": "1080p"
},
"rate": 32.09,
"per": "duration"
}
]
}Parameters
| Parameter | Type | Description |
|---|---|---|
promptrequired | string | |
aspect_ratio | auto | 16:9 | 9:16 | 1:1 | 21:9 | Формат кадраDefault "auto" |
resolution | 720p | 1080p | КачествоDefault "720p" |
duration | number 3–30 | Длительность. От 3 до 30 секунд. Цена считается за каждую секунду ролика.Default 5 |
elements | array of object (≤ 7) | Персонажи и предметы. До 7 штук, из них не больше 3 по видео. Упоминайте их в описании по имени: @Имя. |
voices | array of object (≤ 3) | Голоса. До 3 голосов по образцу записи. Упоминайте в описании по имени: @Имя. |
reference_image_urls | array of file (≤ 10) | A file_ref (asset:… or attachment:…), an https URL or a data: URL. |
Example request
curl https://api.unitool.ai/v1/generations \
-H "Authorization: Bearer $UNITOOL_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Prefer: wait=60" \
-d '{
"model": "kling-4-0",
"mode": "t2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"aspect_ratio": "auto",
"resolution": "720p",
"duration": 5
}
}'import json, os, time, uuid, requests
API = "https://api.unitool.ai/v1"
headers = {"Authorization": f"Bearer {os.environ['UNITOOL_API_KEY']}"}
body = json.loads(r'''{
"model": "kling-4-0",
"mode": "t2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"aspect_ratio": "auto",
"resolution": "720p",
"duration": 5
}
}''')
gen = requests.post(f"{API}/generations", json=body,
headers={**headers, "Idempotency-Key": str(uuid.uuid4()), "Prefer": "wait=60"}).json()
while gen["status"] in ("queued", "running"):
time.sleep(5)
gen = requests.get(f"{API}/generations/{gen['id']}", headers=headers).json()
print(gen["status"], [o["url"] for o in gen["outputs"]])const API = "https://api.unitool.ai/v1";
const headers = { Authorization: `Bearer ${process.env.UNITOOL_API_KEY}`, "Content-Type": "application/json" };
const body = {
"model": "kling-4-0",
"mode": "t2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"aspect_ratio": "auto",
"resolution": "720p",
"duration": 5
}
};
let gen = await (await fetch(`${API}/generations`, {
method: "POST", body: JSON.stringify(body),
headers: { ...headers, "Idempotency-Key": crypto.randomUUID(), Prefer: "wait=60" },
})).json();
while (gen.status === "queued" || gen.status === "running") {
await new Promise((resolve) => setTimeout(resolve, 5000));
gen = await (await fetch(`${API}/generations/${gen.id}`, { headers })).json();
}
console.log(gen.status, gen.outputs.map((output) => output.url));Кадры → видео
Mode i2v · kling-4-0:i2v
Price
Depends on the parameters: 108 tokens for the example below, base 108. Get the exact price of your request from POST /v1/quotes.
Price make-up (pricing from GET /v1/models/{id})
{
"unit": "tokens",
"kind": "by_parameters",
"base": 108,
"example_price": 108,
"matrix": [
{
"when": {
"resolution": "720p"
},
"rate": 21.52,
"per": "duration"
},
{
"when": {
"resolution": "1080p"
},
"rate": 32.09,
"per": "duration"
}
]
}Parameters
| Parameter | Type | Description |
|---|---|---|
prompt | string | |
resolution | 720p | 1080p | КачествоDefault "720p" |
duration | number 3–30 | Длительность. От 3 до 30 секунд. Цена считается за каждую секунду ролика.Default 5 |
keyframe_urls | array of file (≤ 8) | Кадры в середине. До 8 кадров по порядку — в описании @keyframe_1, @keyframe_2. Всего кадров не больше, чем секунд + 1 (от 9 секунд — до 10 кадров). A file_ref (asset:… or attachment:…), an https URL or a data: URL. |
last_frame_url | file | Последний кадр. Чем закончится ролик — в описании @last_frame. A file_ref (asset:… or attachment:…), an https URL or a data: URL. |
image_urlsrequired | array of file (≤ 1) | A file_ref (asset:… or attachment:…), an https URL or a data: URL. |
Example request
curl https://api.unitool.ai/v1/generations \
-H "Authorization: Bearer $UNITOOL_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Prefer: wait=60" \
-d '{
"model": "kling-4-0",
"mode": "i2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"resolution": "720p",
"duration": 5,
"image_urls": [
"https://example.com/input.png"
]
}
}'import json, os, time, uuid, requests
API = "https://api.unitool.ai/v1"
headers = {"Authorization": f"Bearer {os.environ['UNITOOL_API_KEY']}"}
body = json.loads(r'''{
"model": "kling-4-0",
"mode": "i2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"resolution": "720p",
"duration": 5,
"image_urls": [
"https://example.com/input.png"
]
}
}''')
gen = requests.post(f"{API}/generations", json=body,
headers={**headers, "Idempotency-Key": str(uuid.uuid4()), "Prefer": "wait=60"}).json()
while gen["status"] in ("queued", "running"):
time.sleep(5)
gen = requests.get(f"{API}/generations/{gen['id']}", headers=headers).json()
print(gen["status"], [o["url"] for o in gen["outputs"]])const API = "https://api.unitool.ai/v1";
const headers = { Authorization: `Bearer ${process.env.UNITOOL_API_KEY}`, "Content-Type": "application/json" };
const body = {
"model": "kling-4-0",
"mode": "i2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"resolution": "720p",
"duration": 5,
"image_urls": [
"https://example.com/input.png"
]
}
};
let gen = await (await fetch(`${API}/generations`, {
method: "POST", body: JSON.stringify(body),
headers: { ...headers, "Idempotency-Key": crypto.randomUUID(), Prefer: "wait=60" },
})).json();
while (gen.status === "queued" || gen.status === "running") {
await new Promise((resolve) => setTimeout(resolve, 5000));
gen = await (await fetch(`${API}/generations/${gen.id}`, { headers })).json();
}
console.log(gen.status, gen.outputs.map((output) => output.url));Видео → видео
Mode v2v · kling-4-0:v2v
Price
Depends on the parameters: 128 tokens for the example below, base 128. Get the exact price of your request from POST /v1/quotes.
Price make-up (pricing from GET /v1/models/{id})
{
"unit": "tokens",
"kind": "by_parameters",
"base": 128,
"example_price": 128,
"matrix": [
{
"when": {
"resolution": "720p"
},
"rate": 12.84,
"per": "duration",
"plus": [
"video_url_duration_sec",
"elements_duration_sec"
],
"plus_mode": "max"
},
{
"when": {
"resolution": "1080p"
},
"rate": 19.25,
"per": "duration",
"plus": [
"video_url_duration_sec",
"elements_duration_sec"
],
"plus_mode": "max"
}
]
}Parameters
| Parameter | Type | Description |
|---|---|---|
prompt | string | |
video_urlrequired | array of file (≤ 5) | Ваши видео. До 5 роликов по 2–30 секунд, вместе не больше 30 секунд. В описании — @video_1, @video_2. Секунды ваших видео тоже оплачиваются, но не меньше длины результата. A file_ref (asset:… or attachment:…), an https URL or a data: URL. |
keep_original_sound | boolean | Сохранить звук из видео. Выключено — модель сама озвучит ролик.Default false |
resolution | 720p | 1080p | КачествоDefault "720p" |
duration | number 3–30 | Длительность. От 3 до 30 секунд. Цена считается за каждую секунду ролика.Default 5 |
elements | array of object (≤ 7) | Персонажи и предметы. До 7 штук, из них не больше 3 по видео. Упоминайте их в описании по имени: @Имя. |
voices | array of object (≤ 3) | Голоса. До 3 голосов по образцу записи. Упоминайте в описании по имени: @Имя. |
reference_image_urls | array of file (≤ 10) | A file_ref (asset:… or attachment:…), an https URL or a data: URL. |
Example request
curl https://api.unitool.ai/v1/generations \
-H "Authorization: Bearer $UNITOOL_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Prefer: wait=60" \
-d '{
"model": "kling-4-0",
"mode": "v2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"keep_original_sound": false,
"resolution": "720p",
"duration": 5,
"video_url": [
"https://example.com/input.mp4"
]
}
}'import json, os, time, uuid, requests
API = "https://api.unitool.ai/v1"
headers = {"Authorization": f"Bearer {os.environ['UNITOOL_API_KEY']}"}
body = json.loads(r'''{
"model": "kling-4-0",
"mode": "v2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"keep_original_sound": false,
"resolution": "720p",
"duration": 5,
"video_url": [
"https://example.com/input.mp4"
]
}
}''')
gen = requests.post(f"{API}/generations", json=body,
headers={**headers, "Idempotency-Key": str(uuid.uuid4()), "Prefer": "wait=60"}).json()
while gen["status"] in ("queued", "running"):
time.sleep(5)
gen = requests.get(f"{API}/generations/{gen['id']}", headers=headers).json()
print(gen["status"], [o["url"] for o in gen["outputs"]])const API = "https://api.unitool.ai/v1";
const headers = { Authorization: `Bearer ${process.env.UNITOOL_API_KEY}`, "Content-Type": "application/json" };
const body = {
"model": "kling-4-0",
"mode": "v2v",
"input": {
"prompt": "A red fox running through fresh snow at sunrise",
"keep_original_sound": false,
"resolution": "720p",
"duration": 5,
"video_url": [
"https://example.com/input.mp4"
]
}
};
let gen = await (await fetch(`${API}/generations`, {
method: "POST", body: JSON.stringify(body),
headers: { ...headers, "Idempotency-Key": crypto.randomUUID(), Prefer: "wait=60" },
})).json();
while (gen.status === "queued" || gen.status === "running") {
await new Promise((resolve) => setTimeout(resolve, 5000));
gen = await (await fetch(`${API}/generations/${gen.id}`, { headers })).json();
}
console.log(gen.status, gen.outputs.map((output) => output.url));