مسارات النماذج
إنشاء مهمة Kling لتحويل صورة إلى فيديو حسب النموذج
أنشئ فيديو باستخدام Kling من صورة مصدر عبر مسار خاص بالنموذج، ثم استرجع الفيديو باستخدام معرّف المهمة.
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 عام أو ببيانات JPG/PNG مرمّزة باستخدام Base64 لصورة المصدر. أرسل هذا المتن إلى
احفظ
POST /image-to-video/{model} لإنشاء مهمة فيديو. يمكنك إضافة Prompt لوصف الحركة. تحتوي الاستجابة على id تستخدمه لاسترجاع النتيجة.
اختر نموذجًا
ضع معرّف النموذج في عنوان URL. لا تضف الحقل model إلى متن JSON.| معرّف النموذج | الدقة | المدة | الصوت |
|---|---|---|---|
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 متاحًا للعامة أو بيانات JPG أو PNG مرمّزة باستخدام Base64.
| الحقل | النوع | مطلوب | الوصف |
|---|---|---|---|
المسار model | سلسلة نصية | نعم | معرّف النموذج في عنوان URL. اختر معرّفًا من الجدول أعلاه؛ ولا تضفه إلى متن الطلب. |
contents | مصفوفة | نعم | إدخالات المدخلات. أدرج صورة first_frame، وأضف إدخال prompt أو صورة last_frame يدعمها النموذج عند الحاجة. |
contents[].type | سلسلة نصية | نعم | prompt, first_frame، أو last_frame. أدرج first_frame عند استخدام last_frame؛ ويحدد النموذج المحدد ما إذا كان last_frame متاحًا. |
contents[].text | سلسلة نصية | لإدخال prompt | نص يصف الحركة. |
contents[].url | سلسلة نصية | لإدخال الإطار | عنوان URL عام للصورة أو بيانات JPG أو PNG مرمّزة باستخدام Base64. |
settings.resolution | سلسلة نصية | لا | دقة الإخراج من صف النموذج المحدد أعلاه. القيمة الافتراضية هي 720p. |
settings.duration | عدد صحيح | لا | مدة الفيديو بالثواني من صف النموذج المحدد أعلاه. القيمة الافتراضية هي 10 للنموذج kling-4.0 و5 للنماذج الأخرى. أرسل عددًا صحيحًا، وليس سلسلة نصية. |
settings.multi_shot | قيمة منطقية | لا | بالنسبة إلى kling-3.0 فقط، القيمة الافتراضية الرسمية هي true. عيّن true للقطات متعددة أو 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. تتضمن فيديوهاته مسارًا صوتيًا؛ احذف الحقل بدلًا من إرسال قيمة يتجاهلها النموذج.
يحرّك الطلب التالي صورة مصدر واحدة في فيديو مدته خمس ثوانٍ:
{
"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 باستخدام مفتاح CometAPI API الخاص بك. توفر لوحة تعليمات OpenAPI البرمجية طلبات Shell وPython وJavaScript بالمتن نفسه.
استرداد الفيديو
تأتي استجابة الإنشاء بهذا الشكل:{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}
data.id. استخدم الحصول على مهمة Kling باستخدام ذلك المعرّف حتى تصل المهمة إلى حالة نهائية. اقرأ عنوان 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.
آخر تعديل في ١٣ نوفمبر ٢٠٢٦
⌘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"
}
}