Skip to content

Commit 4845d29

Browse files
kristinaorekhovagitbook-bot
authored andcommitted
GITBOOK-1103: No subject
1 parent 29388f3 commit 4845d29

2 files changed

Lines changed: 256 additions & 0 deletions

File tree

‎docs/SUMMARY.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
* [v3-pro/text-to-video](api-references/video-models/kling-ai/v3-pro-text-to-video.md)
369369
* [v3-pro/image-to-video](api-references/video-models/kling-ai/v3-pro-image-to-video.md)
370370
* [v3-standard-turbo-image-to-video](api-references/video-models/kling-ai/v3-standard-turbo-image-to-video.md)
371+
* [v3-turbo-pro-image-to-video](api-references/video-models/kling-ai/v3-turbo-pro-image-to-video.md)
371372
* [v3-standard-turbo-text-to video](api-references/video-models/kling-ai/v3-standard-turbo-text-to-video.md)
372373
* [v3-turbo-pro-text-to-video](api-references/video-models/kling-ai/v3-turbo-pro-text-to-video.md)
373374
* [Krea](api-references/video-models/krea/README.md)
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
# v3-turbo-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-v3-turbo-pro-image-to-video`
9+
* `kling-video/v3/turbo/pro/image-to-video`
10+
{% endhint %}
11+
{% endcolumn %}
12+
13+
{% column width="33.33333333333334%" %}
14+
<a href="https://aimlapi.com/app/v3-turbo-pro-image-to-video" class="button primary">Try in Playground</a>
15+
{% endcolumn %}
16+
{% endcolumns %}
17+
18+
Kling 3.0 Turbo Pro generates high-quality 1080p videos from images with improved lipsync and multishot generation capabilities.
19+
20+
## Setup your API Key
21+
22+
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).
23+
24+
## How to Make a Call
25+
26+
<details>
27+
28+
<summary>Step-by-Step Instructions</summary>
29+
30+
Generating a video using this model involves sequentially calling two endpoints:
31+
32+
* The first one is for creating and sending a video generation task to the server (returns a generation ID).
33+
* The second one is for requesting the generated video from the server using the generation ID received from the first endpoint.
34+
35+
Below, you can find both corresponding API schemas.
36+
37+
</details>
38+
39+
## API Schemas
40+
41+
{% hint style="success" %}
42+
Now, all of our API schemas for video models use our new universal short URL — `https://api.aimlapi.com/v2/video/generations`.\
43+
However, you can still call this model using the legacy URL that includes the vendor name.
44+
{% endhint %}
45+
46+
### Create a video generation task and send it to the server
47+
48+
{% hint style="info" %}
49+
The aspect ratio of the generated video is solely determined by the aspect ratio of the input reference image.
50+
{% endhint %}
51+
52+
{% openapi-operation spec="video-v3-turbo-pro-image-to-video" path="/v2/video/generations" method="post" %}
53+
[OpenAPI video-v3-turbo-pro-image-to-video](https://raw.githubusercontent.com/aimlapi/api-docs/refs/heads/main/docs/api-references/video-models/Kling-AI/v3-turbo-pro-image-to-video.json)
54+
{% endopenapi-operation %}
55+
56+
### Retrieve the generated video from the server
57+
58+
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 `id`, obtained from the endpoint described above.\
59+
If the video generation task status is `completed`, the response will include the final result — with the generated video URL and additional metadata.
60+
61+
## Full Example: Generating and Retrieving the Video From the Server
62+
63+
{% tabs %}
64+
{% tab title="Python" %}
65+
{% code overflow="wrap" %}
66+
```python
67+
import requests
68+
import time
69+
70+
# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
71+
api_key = "<YOUR_AIMLAPI_KEY>"
72+
base_url = "https://api.aimlapi.com/v2"
73+
74+
# Creating and sending a video generation task to the server
75+
def generate_video():
76+
url = f"{base_url}/video/generations"
77+
headers = {
78+
"Authorization": f"Bearer {api_key}",
79+
}
80+
81+
data = {
82+
"model": "klingai/video-v3-turbo-pro-image-to-video",
83+
"prompt": "Mona Lisa puts on glasses with her hands.",
84+
"image_url": "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/mona_lisa_extended.jpg"
85+
}
86+
87+
response = requests.post(url, json=data, headers=headers)
88+
89+
if response.status_code >= 400:
90+
print(f"Error: {response.status_code} - {response.text}")
91+
else:
92+
response_data = response.json()
93+
return response_data
94+
95+
# Requesting the result of the task from the server using the generation_id
96+
def get_video(gen_id):
97+
url = f"{base_url}/video/generations"
98+
params = {
99+
"generation_id": gen_id,
100+
}
101+
102+
headers = {
103+
"Authorization": f"Bearer {api_key}",
104+
"Content-Type": "application/json"
105+
}
106+
107+
response = requests.get(url, params=params, headers=headers)
108+
return response.json()
109+
110+
111+
def main():
112+
gen_response = generate_video()
113+
gen_id = gen_response.get("id")
114+
print("Generation ID: ", gen_id)
115+
116+
if gen_id:
117+
start_time = time.time()
118+
timeout = 1000
119+
while time.time() - start_time < timeout:
120+
response_data = get_video(gen_id)
121+
122+
if response_data is None:
123+
print("Error: No response from API")
124+
break
125+
126+
status = response_data.get("status")
127+
128+
if status in ["queued", "generating"]:
129+
print(f"Status: {status}. Checking again in 15 seconds.")
130+
time.sleep(15)
131+
else:
132+
print("Processing complete:\n", response_data)
133+
return response_data
134+
135+
print("Timeout reached. Stopping.")
136+
return None
137+
138+
139+
if __name__ == "__main__":
140+
main()
141+
```
142+
{% endcode %}
143+
{% endtab %}
144+
145+
{% tab title="JavaScript" %}
146+
{% code overflow="wrap" %}
147+
```javascript
148+
const https = require("https");
149+
const { URL } = require("url");
150+
151+
const apiKey = "<YOUR_AIMLAPI_KEY>";
152+
const baseUrl = "https://api.aimlapi.com/v2";
153+
154+
function generateVideo(callback) {
155+
const data = JSON.stringify({"model": "klingai/video-v3-turbo-pro-image-to-video", "prompt": "Mona Lisa puts on glasses with her hands.", "image_url": "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/mona_lisa_extended.jpg"});
156+
157+
const url = new URL(`${baseUrl}/video/generations`);
158+
const options = {
159+
method: "POST",
160+
headers: {
161+
"Authorization": `Bearer ${apiKey}`,
162+
"Content-Type": "application/json",
163+
"Content-Length": Buffer.byteLength(data),
164+
},
165+
};
166+
167+
const req = https.request(url, options, (res) => {
168+
let body = "";
169+
res.on("data", (chunk) => body += chunk);
170+
res.on("end", () => {
171+
if (res.statusCode >= 400) {
172+
console.error(`Error: ${res.statusCode} - ${body}`);
173+
callback(null);
174+
} else {
175+
const parsed = JSON.parse(body);
176+
callback(parsed);
177+
}
178+
});
179+
});
180+
181+
req.on("error", (err) => console.error("Request error:", err));
182+
req.write(data);
183+
req.end();
184+
}
185+
186+
function getVideo(genId, callback) {
187+
const url = new URL(`${baseUrl}/video/generations`);
188+
url.searchParams.append("generation_id", genId);
189+
190+
const options = {
191+
method: "GET",
192+
headers: {
193+
"Authorization": `Bearer ${apiKey}`,
194+
"Content-Type": "application/json",
195+
},
196+
};
197+
198+
const req = https.request(url, options, (res) => {
199+
let body = "";
200+
res.on("data", (chunk) => body += chunk);
201+
res.on("end", () => {
202+
const parsed = JSON.parse(body);
203+
callback(parsed);
204+
});
205+
});
206+
207+
req.on("error", (err) => console.error("Request error:", err));
208+
req.end();
209+
}
210+
211+
function main() {
212+
generateVideo((genResponse) => {
213+
if (!genResponse || !genResponse.id) {
214+
console.error("No generation ID received.");
215+
return;
216+
}
217+
218+
const genId = genResponse.id;
219+
console.log("Generation ID:", genId);
220+
221+
const timeout = 1000 * 1000;
222+
const interval = 15 * 1000;
223+
const startTime = Date.now();
224+
225+
const checkStatus = () => {
226+
if (Date.now() - startTime >= timeout) {
227+
console.log("Timeout reached. Stopping.");
228+
return;
229+
}
230+
231+
getVideo(genId, (responseData) => {
232+
if (!responseData) {
233+
console.error("Error: No response from API");
234+
return;
235+
}
236+
237+
const status = responseData.status;
238+
239+
if (["queued", "generating"].includes(status)) {
240+
console.log(`Status: ${status}. Checking again in 15 seconds.`);
241+
setTimeout(checkStatus, interval);
242+
} else {
243+
console.log("Processing complete:\n", responseData);
244+
}
245+
});
246+
};
247+
checkStatus();
248+
})
249+
}
250+
251+
main();
252+
```
253+
{% endcode %}
254+
{% endtab %}
255+
{% endtabs %}

0 commit comments

Comments
 (0)