Skip to content

KlingAI

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official KlingAI OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Supports .NET 10.0

Usage

1
2
3
using KlingAI;

using var client = new KlingAIClient(apiKey);

Text to Video

Shows how to create a text-to-video generation task and retrieve its status.

 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 a text-to-video task using the Kling v2 model with a 5-second duration.
var createResponse = await client.CreateTextToVideoAsync(
    prompt: "A golden retriever running through a sunlit meadow, cinematic slow motion",
    modelName: CreateTextToVideoRequestModelName.KlingV2,
    mode: CreateTextToVideoRequestMode.Std,
    aspectRatio: CreateTextToVideoRequestAspectRatio.x16_9,
    duration: CreateTextToVideoRequestDuration.x5);

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

// Retrieve the task to check its status and get the result when complete.
var taskResponse = await client.GetTextToVideoTaskAsync(
    id: createResponse.Data.TaskId!);

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

// When the task succeeds, the result will contain video URLs.
if (taskResponse.Data.TaskStatus == TaskDataTaskStatus.Succeed)
{
    Console.WriteLine($"Video URL: {taskResponse.Data.TaskResult.Videos![0].Url}");
}

Image to Video

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

 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");
}

Image Generation

Shows how to create an image generation task from a text prompt.

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

// Create an image generation task with a text prompt.
var createResponse = await client.CreateImageGenerationAsync(
    prompt: "A futuristic cityscape at sunset with flying vehicles, digital art",
    modelName: CreateImageGenerationRequestModelName.KlingV2,
    aspectRatio: CreateImageGenerationRequestAspectRatio.x16_9,
    n: 1);

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

// Retrieve the task to check the generation status and result.
var taskResponse = await client.GetImageGenerationTaskAsync(
    id: createResponse.Data.TaskId!);

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

// When the task succeeds, the result will contain image URLs.
if (taskResponse.Data.TaskStatus == TaskDataTaskStatus.Succeed)
{

    foreach (var image in taskResponse.Data.TaskResult.Images!)
    {
        Console.WriteLine($"Image {image.Index}: {image.Url}");
    }
}

Ecosystem maintenance

This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.

Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.

Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.

Support

Priority place for bugs: https://github.com/tryAGI/KlingAI/issues
Priority place for ideas and general questions: https://github.com/tryAGI/KlingAI/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.