POST
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 28 29 30 31 32 import requests import base64 # Use this function to convert an image file from the filesystem to base64 def image_file_to_base64(image_path): with open(image_path, 'rb') as f: image_data = f.read() return base64.b64encode(image_data).decode('utf-8') # Use this function to fetch an image from a URL and convert it to base64 def image_url_to_base64(image_url): response = requests.get(image_url) image_data = response.content return base64.b64encode(image_data).decode('utf-8') api_key = "YOUR_API_KEY" url = "https://api.segmind.com/v1/kling-text2video" # Request payload data = { "prompt": "A border collie, wearing clothes made of laser film, wearing a headset, VR glasses, with the Milky Way reflected in his eyes, classic black and white, high-definition quality, surrealism, microcomputer, hacker dress, cyber style, anthropomorphism, reality", "negative_prompt": "No buildings, no artificial objects", "cfg_scale": 0.5, "mode": "std", "aspect_ratio": "16:9", "duration": 5 } headers = {'x-api-key': api_key} response = requests.post(url, json=data, headers=headers) print(response.content) # The response is the generated image
RESPONSE
image/jpeg
HTTP Response Codes
200 - OKImage Generated
401 - UnauthorizedUser authentication failed
404 - Not FoundThe requested URL does not exist
405 - Method Not AllowedThe requested HTTP method is not allowed
406 - Not AcceptableNot enough credits
500 - Server ErrorServer had some issue with processing

Attributes


promptstr *

Text prompt to describe the desired image


negative_promptstr ( default: No buildings, no artificial objects )

Description of unwanted elements


cfg_scalefloat ( default: 0.5 )

CFG scale to control how closely the image matches the prompt (range 0-1)

min : 0,

max : 1


modeenum:str ( default: std )

std: Standard Mode, generates videos faster and has lower inference costs. pro: Professional Mode, generates videos use longer duration but higher quality video output.

Allowed values:


aspect_ratioenum:str ( default: 16:9 )

Aspect ratio of the output image

Allowed values:


durationenum:str ( default: 5 )

Duration of the output in seconds

Allowed values:

To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.

Kling AI Text-to-Video Generation

Kling AI is a state-of-the-art AI model developed by Kuaishou, designed to convert textual descriptions into high-quality, lifelike videos. Leveraging advanced AI technologies, Kling AI offers unparalleled capabilities in video generation, making it a powerful tool for content creators, marketers, and educators.

Key Features of Kling AI Text-to-Video

  • Dynamic-Resolution Training: The model’s dynamic-resolution training strategy allows it to create visually appealing content in various aspect ratios. This flexibility ensures that Kling AI can adapt to different video formats, making it suitable for a wide range of applications

  • KLING AI utilizes advanced 3D space-time attention and diffusion transformer technologies to accurately model movements and create imaginative scenes efficiently.

  • Kling AI supports the generation of videos up to 5s & 10s in length. This capability is particularly beneficial for creating comprehensive visual narratives and detailed educational content

How to use Kling AI Text-to-Video

  1. Drafting the Prompt: Provide a detailed text prompt that describes the desired video. Include specifics such as scene settings, character actions, and camera movements. For example, “A serene beach at sunset with waves gently crashing and seagulls flying overhead.”

  2. Generating the Video: Enter your prompt into the designated text field and initiate the video generation process. Kling AI will process the input and create a video based on your description.

  3. Customizing Output Settings: Adjust the output settings to match your project requirements. You can select the resolution, aspect ratio, and video length to ensure the final product meets your needs.

Best Practices for Optimal Results

  • Detailed Descriptions: The more specific and descriptive your text prompt, the better the AI can interpret and visualize your ideas. Include details about lighting, colors, and movements to enhance the realism of the generated video.

  • Iterative Refinement: Experiment with different prompts and settings to refine the output. Iterative adjustments allow you to achieve the best possible results by fine-tuning the input parameters.

  • High-Quality Inputs: Use well-crafted text prompts to ensure the initial frame and overall video quality are high. This will significantly improve the final output.

Be sure to read Kling's AI Video Guide for more tips on how to use this model. https://docs.qingque.cn/d/home/eZQDvlYrDMyE9lOforCeWA4KP