Microsoft.Extensions.AI Integration
Cross-SDK comparison
See the centralized MEAI documentation for feature matrices and comparisons across all tryAGI SDKs.
The KlingAI SDK provides AIFunction tool wrappers compatible with Microsoft.Extensions.AI. These tools can be used with any IChatClient to give AI models access to Kling AI's text-to-video, image-to-video, and image generation capabilities.
Installation
1 | |
Available Tools
| Method | Tool Name | Description |
|---|---|---|
AsTextToVideoTool() |
TextToVideo |
Generates a video from a text prompt. Returns a task ID for status polling. |
AsImageToVideoTool() |
ImageToVideo |
Generates a video from an image URL with optional prompt guidance. Returns a task ID. |
AsImageGenerationTool() |
GenerateImage |
Generates images from a text prompt. Returns a task ID for status polling. |
AsGetTextToVideoTaskTool() |
GetTextToVideoTask |
Retrieves status and result of a text-to-video task by ID. |
AsGetImageToVideoTaskTool() |
GetImageToVideoTask |
Retrieves status and result of an image-to-video task by ID. |
AsGetImageGenerationTaskTool() |
GetImageGenerationTask |
Retrieves status and result of an image generation task by ID. |
Text-to-Video Tool
Use AsTextToVideoTool() to create an AIFunction that generates videos from text descriptions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
Image-to-Video Tool
Use AsImageToVideoTool() to animate an image into a video:
1 2 3 4 5 6 7 | |
Image Generation Tool
Use AsImageGenerationTool() to generate images from text:
1 2 3 4 5 6 7 8 | |
Task Status Tools
Kling AI uses an async task pattern -- creation endpoints return a task ID, and you poll for results. The AsGet*TaskTool() methods let the AI agent check task status:
1 2 3 4 5 6 7 8 | |
Combining All Tools
All tools can be used together to give the AI agent full generation and status-checking capabilities:
1 2 3 4 5 6 7 8 9 10 11 12 | |
Async Task Pattern
Kling AI generation tasks are asynchronous. The creation tools (AsTextToVideoTool, AsImageToVideoTool, AsImageGenerationTool) return a task ID and initial status. The status tools (AsGetTextToVideoTaskTool, AsGetImageToVideoTaskTool, AsGetImageGenerationTaskTool) can then be used to poll for completion. Task statuses are:
submitted-- Task has been receivedprocessing-- Generation is in progresssucceed-- Generation complete, results availablefailed-- Generation failed