Kling Image Animation API
Transform static images into smooth videos with natural motion
✓ 5-10 seconds
✓ Natural motion
✓ Pro mode
✓ High quality
احراز هویت
برای دسترسی به Kling Image-to-Video API از طریق API دویتانگ (Doitong)، از کلید API خود استفاده کنید. این کلید را در هدرهای REST API یا Mutationهای GraphQL قرار دهید.
// GraphQL Header
{
"Authorization": "Bearer YOUR_API_KEY"
}
// REST Header
"X-API-Key": "YOUR_API_KEY"
شروع سریع
در عرض چند دقیقه کار با Kling Image-to-Video API را شروع کنید. این مراحل ساده را برای ساخت اولین image to video خود دنبال کنید.
مرحله ۱: دریافت کلید API
در سایت دویتانگ ثبتنام کنید و برای ساخت کلید API به پنل کاربری خود بروید.
مرحله ۲: اولین درخواست خود را ارسال کنید
از نمونه کدهای زیر برای ارسال اولین درخواست API خود استفاده کنید.
curl -X POST https://api.doitong.com/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: unique-request-id-123" \
-d '{
"query": "mutation Generate($input: GenerateInput!) { generate(input: $input) { id status type provider url metadata creditCost } }",
"variables": {
"input": {
"type": "VIDEO",
"provider": "kling-i2v",
"input": {
"image": "https://example.com/your-image.jpg"
},
"options": {
"duration": 5,
"motionIntensity": "medium"
}
}
}
}'
const response = await fetch('https://api.doitong.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
query: `
mutation AnimateImage($input: ImageAnimationInput!) {
animateImage(input: $input) {
id
status
url
}
}
`,
variables: {
input: {
service: 'kling-i2v',
imageUrl: 'https://example.com/your-image.jpg',
duration: 5,
motionIntensity: 'medium'
}
}
})
});
const data = await response.json();
console.log('Animated Video:', data.data.animateImage);
import requests
import json
url = "https://api.doitong.com/graphql"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
query = """
mutation Generate($input: GenerateInput!) {
generate(input: $input) {
id
status
type
provider
url
metadata
creditCost
}
}
"""
variables = {
"input": {
"type": "VIDEO",
"provider": "kling-i2v",
"input": {
"imageUrl": "https://example.com/your-image.jpg"
},
"options": {
"duration": 5,
"motionIntensity": "medium"
}
}
}
response = requests.post(url, json={
"query": query,
"variables": variables
}, headers=headers)
data = response.json()
print("Result:", data["data"]["generate"])
mutation Generate($input: GenerateInput!) {
generate(input: $input) {
id
status
type
provider
url
metadata
creditCost
createdAt
}
}
# Variables
{
"input": {
"type": "VIDEO",
"provider": "kling-i2v",
"input": {
"imageUrl": "https://example.com/your-image.jpg"
},
"options": {
"duration": 5,
"motionIntensity": "medium",
"version": "1.6"
}
}
}
قیمتگذاری
سرویس Kling Image-to-Video API از مدل قیمتگذاری مبتنی بر اعتبار (Credit) استفاده میکند. میزان مصرف اعتبار بر اساس پیچیدگی و زمان محتوای تولید شده محاسبه میشود.
| قابلیت | اعتبار | توضیحات |
|---|---|---|
| استفاده معمولی | 10-50 اعتبار | کیفیت و زمان استاندارد |
| استفاده ویژه | 100-500 اعتبار | کیفیت بالا و امکانات گسترده |
نقاط اتصال API
سرویس Kling Image-to-Video API از طریق نقطه اتصال یکپارچه GraphQL ما در دسترس است.
نقطه اتصال GraphQL
POST https://api.doitong.com/graphql
نقطه اتصال REST
POST https://api.doitong.com/v1/image_to_video
پارامترها
پارامترهای موجود برای درخواستهای Kling Image-to-Video API:
| پارامتر | نوع | اجباری | توضیحات |
|---|---|---|---|
service |
رشته (String) | Yes | شناسه سرویس: "kling-i2v" |
prompt |
رشته (String) | Yes | توضیح متنی از آنچه میخواهید تولید شود |
duration |
عدد صحیح (Integer) | No | مدت زمان ویدیو به ثانیه (پیشفرض: ۵) |
aspectRatio |
رشته (String) | No | نسبت تصویر: "16:9"، "9:16"، "1:1" (پیشفرض: "16:9") |
version |
رشته (String) | No | Model version: "1.0", "1.5", "1.6" |
webhookUrl |
رشته (String) | No | آدرس URL برای دریافت اعلانهای تکمیل عملیات |
فرمت پاسخ
تمامی پاسخهای API از یک ساختار ثابت پیروی میکنند:
پاسخ موفق (Success)
{
"data": {
"imagevideo": {
"id": "abc123xyz",
"status": "processing",
"url": null,
"webhookUrl": "https://your-webhook.com/callback",
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
پاسخ تکمیل شده (Completed)
{
"data": {
"imagevideo": {
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.mp4",
"duration": 5,
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
مدیریت خطاها
این API از کدهای وضعیت استاندارد HTTP استفاده کرده و پیامهای خطای دقیقی را برمیگرداند.
کدهای خطای رایج
| کد وضعیت | نوع خطا | توضیحات |
|---|---|---|
| 400 | Bad Request | Invalid parameters or malformed request |
| 401 | Unauthorized | Missing or invalid API key |
| 402 | Payment Required | Insufficient credits |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server error, please retry |
فرمت پاسخ خطا
{
"errors": [
{
"message": "Insufficient credits for this operation",
"extensions": {
"code": "INSUFFICIENT_CREDITS",
"creditsRequired": 100,
"creditsAvailable": 50
}
}
]
}
وبهوکها (Webhooks)
هنگام اتمام فرآیند تولید image to video، اعلانهای لحظهای دریافت کنید.
راهاندازی وبهوکها
Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.
پیکره (Payload) وبهوک
{
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.mp4",
"service": "kling-i2v",
"createdAt": "2024-01-01T00:00:00Z",
"completedAt": "2024-01-01T00:01:00Z",
"metadata": {
"duration": 5,
"width": 1920,
"height": 1080
}
}
امنیت وبهوک
تمامی درخواستهای وبهوک شامل یک هدر امضا (Signature) برای تایید اصالت هستند:
X-Doitong-Signature: sha256=abc123...
محدودیت نرخ فراخوانی
برای اطمینان از استفاده منصفانه و پایداری سیستم، محدودیتهای زیر اعمال میشوند:
| طرح | درخواست در دقیقه | پردازشهای همزمان | محدودیت روزانه |
|---|---|---|---|
| رایگان | 10 | 1 | 100 |
| استارتر | 30 | 3 | 1,000 |
| حرفهای | 60 | 10 | 10,000 |
| سازمانی | سفارشی | سفارشی | نامحدود |
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Window reset timestamp
توصیههای کلیدی
۱. بهینهسازی پرامپتها
برای دریافت بهترین نتیجه، پرامپتهای دقیق و توصیفی بنویسید:
- Be specific about visual elements, style, and mood
- Include details about lighting, camera angles, and composition
- Avoid contradictory or impossible requests
۲. مدیریت پردازشهای نامتقارن
فرآیند تولید محتوا بهصورت نامتقارن (Async) است. از روش Polling یا Webhook استفاده کنید:
// Polling example
async function pollStatus(jobId) {
let status = 'processing';
while (status === 'processing') {
await sleep(2000); // Wait 2 seconds
const result = await checkJobStatus(jobId);
status = result.status;
}
return result;
}
۳. بازیابی خطا
منطق تلاش مجدد (Retry) را با استفاده از عقبنشینی نمایی (Exponential Backoff) پیادهسازی کنید:
async function retryWithBackoff(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await sleep(Math.pow(2, i) * 1000);
}
}
}
۴. نظارت بر مصرف اعتبار
میزان مصرف اعتبار خود را زیر نظر داشته باشید تا از قطع سرویس جلوگیری کنید:
- Check credit balance before large batch operations
- Set up alerts for low credit thresholds
- Implement credit-aware request queuing
آماده شروع هستید؟
به هزاران توسعهدهندهای بپیوندید که از Kling Image-to-Video API برای خلق محتوای شگفتانگیز استفاده میکنند.