|
| 1 | +# video-v2.6-pro-image-to-video |
| 2 | + |
| 3 | +{% columns %} |
| 4 | +{% column width="66.66666666666666%" %} |
| 5 | +{% hint style="info" %} |
| 6 | +This documentation is valid for the following list of our models: |
| 7 | + |
| 8 | +* `klingai/video-v2-6-pro-image-to-video` |
| 9 | +{% endhint %} |
| 10 | +{% endcolumn %} |
| 11 | + |
| 12 | +{% column width="33.33333333333334%" %} |
| 13 | +<a href="https://aimlapi.com/app/klingai/video-v2-6-pro-image-to-video" class="button primary">Try in Playground</a> |
| 14 | +{% endcolumn %} |
| 15 | +{% endcolumns %} |
| 16 | + |
| 17 | +A high-end AI system for producing cinematic, high-fidelity videos from text prompts and reference images, featuring native audio generation and smooth, natural motion. The flagship Kling model as of early December 2025. |
| 18 | + |
| 19 | +## Setup your API Key |
| 20 | + |
| 21 | +If you don’t have an API key for the AI/ML API yet, feel free to use our [Quickstart guide](https://docs.aimlapi.com/quickstart/setting-up). |
| 22 | + |
| 23 | +## API Schemas |
| 24 | + |
| 25 | +Generating a video using this model involves sequentially calling two endpoints: |
| 26 | + |
| 27 | +* The first one is for creating and sending a video generation task to the server (returns a generation ID). |
| 28 | +* The second one is for requesting the generated video from the server using the generation ID received from the first endpoint. |
| 29 | + |
| 30 | +Below, you can find two corresponding API schemas and an example with both endpoint calls. |
| 31 | + |
| 32 | +### Create a video generation task and send it to the server |
| 33 | + |
| 34 | +{% openapi-operation spec="video-v2-6-pro-image-to-video" path="/v2/video/generations" method="post" %} |
| 35 | +[OpenAPI video-v2-6-pro-image-to-video](https://raw.githubusercontent.com/aimlapi/api-docs/refs/heads/main/docs/api-references/video-models/Kling-AI/video-v2-6-pro-image-to-video.json) |
| 36 | +{% endopenapi-operation %} |
| 37 | + |
| 38 | +### Retrieve the generated video from the server |
| 39 | + |
| 40 | +After sending a request for video generation, this task is added to the queue. This endpoint lets you check the status of a video generation task using its `generation_id`, obtained from the endpoint described above.\ |
| 41 | +If the video generation task status is `complete`, the response will include the final result — with the generated video URL and additional metadata. |
| 42 | + |
| 43 | +{% openapi-operation spec="kling-fetch" path="/v2/generate/video/kling/generation" method="get" %} |
| 44 | +[OpenAPI kling-fetch](https://raw.githubusercontent.com/aimlapi/api-docs/refs/heads/main/docs/api-references/video-models/Kling-AI/v1.6-standard-effects-pair.json) |
| 45 | +{% endopenapi-operation %} |
| 46 | + |
| 47 | +## Code Example |
| 48 | + |
| 49 | +The code below creates a video generation task, then automatically polls the server every **15** seconds until it finally receives the video URL. |
| 50 | + |
| 51 | +{% tabs %} |
| 52 | +{% tab title="Python" %} |
| 53 | +{% code overflow="wrap" %} |
| 54 | +```python |
| 55 | +import requests |
| 56 | +import time |
| 57 | + |
| 58 | +# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>: |
| 59 | +api_key = "<YOUR_AIMLAPI_KEY>" |
| 60 | +base_url = "https://api.aimlapi.com/v2" |
| 61 | + |
| 62 | +# Creating and sending a video generation task to the server |
| 63 | +def generate_video(): |
| 64 | + url = f"{base_url}/generate/video/kling/generation" |
| 65 | + headers = { |
| 66 | + "Authorization": f"Bearer {api_key}", |
| 67 | + } |
| 68 | + |
| 69 | + data = { |
| 70 | + "model": "klingai/video-v2-6-pro-image-to-video", |
| 71 | + "prompt": "Mona Lisa puts on glasses with her hands.", |
| 72 | + "image_url": "https://s2-111386.kwimgs.com/bs2/mmu-aiplatform-temp/kling/20240620/1.jpeg", |
| 73 | + "duration": "5", |
| 74 | + } |
| 75 | + |
| 76 | + response = requests.post(url, json=data, headers=headers) |
| 77 | + |
| 78 | + if response.status_code >= 400: |
| 79 | + print(f"Error: {response.status_code} - {response.text}") |
| 80 | + else: |
| 81 | + response_data = response.json() |
| 82 | + return response_data |
| 83 | + |
| 84 | + |
| 85 | +# Requesting the result of the task from the server using the generation_id |
| 86 | +def get_video(gen_id): |
| 87 | + url = f"{base_url}/generate/video/kling/generation" |
| 88 | + params = { |
| 89 | + "generation_id": gen_id, |
| 90 | + } |
| 91 | + |
| 92 | + headers = { |
| 93 | + "Authorization": f"Bearer {api_key}", |
| 94 | + "Content-Type": "application/json" |
| 95 | + } |
| 96 | + |
| 97 | + response = requests.get(url, params=params, headers=headers) |
| 98 | + return response.json() |
| 99 | + |
| 100 | + |
| 101 | +def main(): |
| 102 | + # Running video generation and getting a task id |
| 103 | + gen_response = generate_video() |
| 104 | + gen_id = gen_response.get("id") |
| 105 | + print("Generation ID: ", gen_id) |
| 106 | + |
| 107 | + # Trying to retrieve the video from the server every 15 sec |
| 108 | + if gen_id: |
| 109 | + start_time = time.time() |
| 110 | + |
| 111 | + timeout = 1000 |
| 112 | + while time.time() - start_time < timeout: |
| 113 | + response_data = get_video(gen_id) |
| 114 | + |
| 115 | + if response_data is None: |
| 116 | + print("Error: No response from API") |
| 117 | + break |
| 118 | + |
| 119 | + status = response_data.get("status") |
| 120 | + print("Status:", status) |
| 121 | + |
| 122 | + if status == "waiting" or status == "active" or status == "queued" or status == "generating": |
| 123 | + print("Still waiting... Checking again in 15 seconds.") |
| 124 | + time.sleep(15) |
| 125 | + else: |
| 126 | + print("Processing complete:/n", response_data) |
| 127 | + return response_data |
| 128 | + |
| 129 | + print("Timeout reached. Stopping.") |
| 130 | + return None |
| 131 | + |
| 132 | + |
| 133 | +if __name__ == "__main__": |
| 134 | + main() |
| 135 | +``` |
| 136 | +{% endcode %} |
| 137 | +{% endtab %} |
| 138 | +{% endtabs %} |
| 139 | + |
| 140 | +<details> |
| 141 | + |
| 142 | +<summary>Response</summary> |
| 143 | + |
| 144 | +{% code overflow="wrap" %} |
| 145 | +```json5 |
| 146 | +Generation ID: 27f25c85-e9db-44e9-909a-0c3ceb35cdd9:klingai/video-v2-6-pro-image-to-video |
| 147 | +Status: generating. Checking again in 15 seconds. |
| 148 | +Status: generating. Checking again in 15 seconds. |
| 149 | +Status: generating. Checking again in 15 seconds. |
| 150 | +Status: generating. Checking again in 15 seconds. |
| 151 | +Status: generating. Checking again in 15 seconds. |
| 152 | +Status: generating. Checking again in 15 seconds. |
| 153 | +Status: generating. Checking again in 15 seconds. |
| 154 | +Status: completed |
| 155 | +Processing complete:/n {'id': '27f25c85-e9db-44e9-909a-0c3ceb35cdd9:klingai/video-v2-6-pro-image-to-video', 'status': 'completed', 'video': {'url': 'https://cdn.aimlapi.com/flamingo/files/b/0a84eaeb/4JST2nBT5v7zbzIy6RlmW_output.mp4'}} |
| 156 | +``` |
| 157 | +{% endcode %} |
| 158 | + |
| 159 | +</details> |
| 160 | + |
| 161 | +**Processing time**: \~ 1 min 50 sec. |
| 162 | + |
| 163 | +**Generated video** (1180x1756, with sound): |
| 164 | + |
| 165 | +{% embed url="https://drive.google.com/file/d/1q5fWg4Qm92-tSOFPV93UtbMikfb6k0Ma/view" %} |
0 commit comments