Routes par modèle
Créer une tâche Kling de conversion d’image en vidéo par modèle
Créez une vidéo Kling à partir d’une image source avec une route propre au modèle, puis récupérez la vidéo à l’aide de l’identifiant de la tâche.
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"
}
}Envoyez une image source à
Si vous utilisez une autre image source, remplacez l’URL de l’image par une URL publique ou des données JPG ou PNG encodées en Base64. Envoyez ce corps à
Enregistrez
POST /image-to-video/{model} pour créer une tâche vidéo. Vous pouvez ajouter un Prompt pour décrire le mouvement. La réponse contient un id que vous utilisez pour récupérer le résultat.
Choisir un modèle
Indiquez l’identifiant du modèle dans l’URL. N’ajoutez pas de champ de modèle au corps JSON.| Identifiant du modèle | Résolution | Durée | Audio |
|---|---|---|---|
kling-4.0 | 720p, 1080p | Nombre entier compris entre 3 et 30 secondes | Omettre audio |
kling-3.0-turbo | 720p, 1080p | Nombre entier compris entre 3 et 15 secondes | Omettre audio |
kling-3.0 | 720p, 1080p, 4k | Nombre entier compris entre 3 et 15 secondes | native ou off |
kling-2.6 | 720p, 1080p | 5 ou 10 secondes | native ou off ; utilisez 1080p avec native |
kling-2.5-turbo | 720p, 1080p | 5 ou 10 secondes | Omettre audio |
kling-4.0 accepte first_frame, middle_frame et last_frame ; indiquez first_frame lorsque vous utilisez last_frame. kling-3.0-turbo accepte uniquement first_frame. kling-2.5-turbo,
kling-3.0, et kling-2.6 prennent également en charge last_frame ; indiquez
first_frame avec celui-ci. Pour kling-2.5-turbo et kling-2.6, la
combinaison de la première et de la dernière image nécessite 1080p.
Paramètres de requête
Placez chaque entrée danscontents. Une entrée prompt utilise text ; une entrée de type image utilise url. Pour une image, fournissez une URL accessible publiquement ou des données JPG ou PNG encodées en Base64.
| Champ | Type | Obligatoire | Description |
|---|---|---|---|
Chemin model | chaîne | Oui | Identifiant du modèle dans l’URL. Choisissez un identifiant dans le tableau ci-dessus ; ne l’ajoutez pas au corps de la requête. |
contents | tableau | Oui | Entrées. Incluez une image first_frame ; ajoutez une entrée prompt ou une image last_frame prise en charge par le modèle si nécessaire. |
contents[].type | chaîne | Oui | prompt, first_frame, ou last_frame. Incluez une entrée first_frame lorsque vous utilisez last_frame ; le modèle sélectionné détermine si last_frame est disponible. |
contents[].text | chaîne | Pour une entrée prompt | Texte décrivant le mouvement. |
contents[].url | chaîne | Pour une entrée de type image | URL publique de l’image ou données JPG ou PNG encodées en Base64. |
settings.resolution | chaîne | Non | Résolution de sortie indiquée dans la ligne du modèle sélectionné ci-dessus. La valeur par défaut est 720p. |
settings.duration | entier | Non | Durée de la vidéo en secondes, indiquée dans la ligne du modèle sélectionné ci-dessus. La valeur par défaut est 10 pour kling-4.0 et 5 pour les autres modèles. Envoyez un entier, pas une chaîne. |
settings.multi_shot | booléen | Non | Pour kling-3.0 uniquement, la valeur par défaut officielle est true. Définissez true pour plusieurs plans ou false pour un seul plan, et définissez explicitement la valeur lorsque vous utilisez ce champ. |
settings.audio | chaîne | Non | Pour kling-3.0 ou kling-2.6, définissez native pour générer de l’audio ou off pour ne pas en générer. Définissez explicitement la valeur lorsque vous utilisez ce champ. |
options.callback_url | chaîne | Non | URL publique qui reçoit les mises à jour de la tâche. |
options.external_task_id | chaîne | Non | Votre identifiant permettant d’associer la tâche à votre application. |
options.watermark_info | objet | Non | Configuration du filigrane pour la sortie. |
kling-4.0 n’expose pas de paramètre settings.audio. Ses vidéos comportent une piste audio ; omettez ce champ plutôt que d’envoyer une valeur que le modèle ignore.
La requête suivante anime une image source pour en faire une vidéo de cinq secondes :
{
"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 avec votre clé API CometAPI. Le panneau de code OpenAPI fournit des requêtes Shell, Python et JavaScript utilisant le même corps.
Récupérer la vidéo
La réponse à la création a la structure suivante :{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}
data.id. Utilisez Obtenir une tâche Kling avec cet identifiant jusqu’à ce que la tâche atteigne un état final. Récupérez l’URL de la vidéo dans le tableau outputs de la tâche.Paramètres de chemin
Corps
application/json
Image-to-video request fields exposed by the CometAPI route. The model ID is a path parameter, not a body field.
Réponse
200 - application/json
The task was created. Use data.id to retrieve its status and video output.
Dernière modification le 13 novembre 2026
⌘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"
}
}