Skip to content

Image to Video

Shows how to create an image-to-video task from an image URL with prompt guidance.

This example assumes using KlingAI; is in scope and apiKey contains your KlingAI API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using var client = new KlingAIClient(apiKey);

// Create an image-to-video task by providing an image URL and a motion prompt.
var createResponse = await client.CreateImageToVideoAsync(
    image: "https://example.com/landscape.jpg",
    prompt: "Camera slowly pans across the landscape with gentle wind blowing through the trees",
    modelName: CreateImageToVideoRequestModelName.KlingV2,
    mode: CreateImageToVideoRequestMode.Std,
    duration: CreateImageToVideoRequestDuration.x5);

Console.WriteLine($"Task ID: {createResponse.Data.TaskId}");

// Query the task status using the returned task ID.
var taskResponse = await client.GetImageToVideoTaskAsync(
    id: createResponse.Data.TaskId!);

Console.WriteLine($"Status: {taskResponse.Data.TaskStatus}");

// When complete, the result contains generated video URLs.
if (taskResponse.Data.TaskStatus == TaskDataTaskStatus.Succeed)
{
    Console.WriteLine($"Video URL: {taskResponse.Data.TaskResult.Videos![0].Url}");
    Console.WriteLine($"Duration: {taskResponse.Data.TaskResult.Videos[0].Duration}s");
}