Routes par modèle
Créer une tâche Kling de génération de vidéo à partir de texte par modèle
Créez une vidéo Kling à partir d’un Prompt textuel à l’aide d’une route propre au modèle, puis récupérez la vidéo à l’aide de l’identifiant de la tâche.
POST
/
text-to-video
/
{model}
cURL
curl https://api.cometapi.com/text-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
}
}'
import os
import requests
response = requests.post(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "A paper boat drifts across a calm pond at sunrise.",
settings: {
resolution: "720p",
aspect_ratio: "16:9",
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/text-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([
'prompt' => 'A paper boat drifts across a calm pond at sunrise.'
]),
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/text-to-video/{model}"
payload := strings.NewReader("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\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/text-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/text-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 \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}Envoyez un Prompt à
Envoyez ce corps à
Enregistrez
POST /text-to-video/{model} pour créer une tâche vidéo. La réponse contient un id que vous utiliserez 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 model au corps JSON.| Identifiant du modèle | Résolution | Durée | Audio |
|---|---|---|---|
kling-4.0 | 720p, 1080p | Nombre entier de 3 à 30 secondes | À omettre audio |
kling-3.0-turbo | 720p, 1080p | Nombre entier de 3 à 15 secondes | À omettre audio |
kling-3.0 | 720p, 1080p, 4k | Nombre entier de 3 à 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 |
Paramètres de la requête
| 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. |
prompt | chaîne | Oui | Description de la vidéo à générer. |
settings.resolution | chaîne | Non | Résolution de sortie indiquée dans la ligne du modèle sélectionné ci-dessus. Valeur par défaut : 720p. |
settings.aspect_ratio | chaîne | Non | Format d’image en sortie : 21:9 (kling-4.0 uniquement), 16:9, 9:16 ou 1:1. Valeur par défaut : 16:9. |
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, et non 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 comprennent une piste audio ; omettez ce champ plutôt que d’envoyer une valeur que le modèle ignore.
La requête suivante crée une vidéo de cinq secondes avec kling-3.0-turbo :
{
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
}
}
https://api.cometapi.com/text-to-video/kling-3.0-turbo avec votre clé API CometAPI. Le panneau de code OpenAPI fournit des requêtes Shell, Python et JavaScript avec 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 Récupérer 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
Text-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/text-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
}
}'
import os
import requests
response = requests.post(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "A paper boat drifts across a calm pond at sunrise.",
settings: {
resolution: "720p",
aspect_ratio: "16:9",
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/text-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([
'prompt' => 'A paper boat drifts across a calm pond at sunrise.'
]),
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/text-to-video/{model}"
payload := strings.NewReader("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\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/text-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/text-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 \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}