モデル別ルート
モデル別にKlingの画像から動画への変換タスクを作成
モデル別のルートを使用して元画像からKling動画を作成し、タスクIDで動画を取得します。
POST
/
image-to-video
/
{model}
cURL
curl https://api.cometapi.com/image-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene."
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg"
}
],
"settings": {
"resolution": "720p",
"duration": 5
}
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene.",
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
"settings": {
"resolution": "720p",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [
{ type: "prompt", text: "The camera slowly moves closer to the scene." },
{
type: "first_frame",
url: "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
settings: {
resolution: "720p",
duration: 5,
},
}),
},
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log((await response.json()).data.id);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/image-to-video/{model}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
'type' => 'prompt',
'text' => 'The camera slowly moves closer to the scene.'
],
[
'type' => 'first_frame',
'url' => 'https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/image-to-video/{model}"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/image-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/image-to-video/{model}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}元画像を
別の画像を使用する場合は、画像 URL を元画像の公開 URL または Base64 エンコードされた JPG/PNG データに置き換えてください。このボディを CometAPI API キーとともに
POST /image-to-video/{model}に送信して動画タスクを作成します。動きを説明するプロンプト(Prompt)を追加できます。レスポンスには、結果の取得に使用するidが含まれます。
モデルを選択する
URLにモデルIDを指定します。JSONボディにmodelフィールドを追加しないでください。| モデルID | 解像度 | 長さ | 音声 |
|---|---|---|---|
kling-4.0 | 720p, 1080p | 3~30秒の整数 | 省略 audio |
kling-3.0-turbo | 720p, 1080p | 3~15秒の整数 | 省略 audio |
kling-3.0 | 720p, 1080p, 4k | 3~15秒の整数 | native または off |
kling-2.6 | 720p, 1080p | 5秒または10秒 | native またはoff。1080pと次を併用: native |
kling-2.5-turbo | 720p, 1080p | 5秒または10秒 | 省略 audio |
kling-4.0 はfirst_frame、middle_frame、およびlast_frameを受け付けます。first_frameはlast_frameを使用する場合に含めてください。kling-3.0-turboはfirst_frameのみを受け付けます。kling-2.5-turbo、
kling-3.0、およびkling-2.6もlast_frameをサポートしています。これと併せて次を含めてください:
first_frame 。kling-2.5-turboとkling-2.6では、
最初と最後のフレームの組み合わせに1080pが必要です。
リクエストパラメータ
各入力をcontents に指定します。prompt エントリには text を、フレームエントリには url を使用します。画像には、一般にアクセス可能な URL、または Base64 エンコードされた JPG や PNG のデータを指定します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
パス model | 文字列 | はい | URL 内のモデル ID。上の表から ID を選択してください。リクエストボディには追加しないでください。 |
contents | 配列 | はい | 入力エントリ。first_frame 画像を含めます。必要に応じて、prompt エントリまたはモデルがサポートする last_frame 画像を追加します。 |
contents[].type | 文字列 | はい | prompt, first_frame、または last_frame。last_frame を使用する場合は first_frame を含めてください。last_frame を使用できるかどうかは、選択したモデルによって異なります。 |
contents[].text | 文字列 | prompt エントリの場合 | 動きを記述するテキスト。 |
contents[].url | 文字列 | フレームエントリの場合 | 公開されている画像 URL、または Base64 エンコードされた JPG や PNG のデータ。 |
settings.resolution | 文字列 | いいえ | 上の表の選択したモデルの行に記載された出力解像度。デフォルトは 720p. |
settings.duration | 整数 | いいえ | 上の表の選択したモデルの行に記載された動画の長さ(秒)。デフォルトは 10 で、これは kling-4.0 に適用されます。その他のモデルのデフォルトは 5 です。文字列ではなく整数を送信してください。 |
settings.multi_shot | 真偽値 | いいえ | kling-3.0 のみ、公式のデフォルトは true です。複数のショットには true を、1 つのショットには false を設定します。このフィールドを使用する場合は、値を明示的に設定してください。 |
settings.audio | 文字列 | いいえ | kling-3.0 または kling-2.6 では、音声を生成する場合は native を、生成しない場合は off を設定します。このフィールドを使用する場合は、値を明示的に設定してください。 |
options.callback_url | 文字列 | いいえ | タスクの更新を受信する公開 URL。 |
options.external_task_id | 文字列 | いいえ | タスクをアプリケーションと対応付けるための識別子。 |
options.watermark_info | オブジェクト | いいえ | 出力のウォーターマーク設定。 |
kling-4.0 は settings.audio スイッチを提供していません。このモデルの動画には音声トラックが含まれます。モデルが無視する値を送信するのではなく、フィールドを省略してください。
次のリクエストは、1 枚の元画像をアニメーション化して 5 秒間の動画にします。
{
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene."
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg"
}
],
"settings": {
"resolution": "720p",
"duration": 5
}
}
https://api.cometapi.com/image-to-video/kling-3.0-turbo に送信します。OpenAPI のコードパネルには、同じボディを使用する Shell、Python、JavaScript のリクエストが用意されています。
動画を取得する
作成レスポンスは次の形式です。{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}
data.id を保存します。次に、 Kling タスクを取得 を使用して、その ID でタスクが最終状態になるまで確認します。動画 URL はタスクの outputs 配列から取得します。パスパラメータ
ボディ
application/json
Image-to-video request fields exposed by the CometAPI route. The model ID is a path parameter, not a body field.
レスポンス
200 - application/json
The task was created. Use data.id to retrieve its status and video output.
最終更新日 2026年11月13日
⌘I
cURL
curl https://api.cometapi.com/image-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene."
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg"
}
],
"settings": {
"resolution": "720p",
"duration": 5
}
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene.",
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
"settings": {
"resolution": "720p",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [
{ type: "prompt", text: "The camera slowly moves closer to the scene." },
{
type: "first_frame",
url: "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
settings: {
resolution: "720p",
duration: 5,
},
}),
},
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log((await response.json()).data.id);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/image-to-video/{model}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
'type' => 'prompt',
'text' => 'The camera slowly moves closer to the scene.'
],
[
'type' => 'first_frame',
'url' => 'https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/image-to-video/{model}"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/image-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/image-to-video/{model}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}