|
| 1 | +# Wan 2.6 (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 | +* `alibaba/wan-2-6-i2v` |
| 9 | +{% endhint %} |
| 10 | +{% endcolumn %} |
| 11 | + |
| 12 | +{% column width="33.33333333333334%" %} |
| 13 | +<a href="https://aimlapi.com/app/alibaba/wan-2-6-i2v" class="button primary">Try in Playground</a> |
| 14 | +{% endcolumn %} |
| 15 | +{% endcolumns %} |
| 16 | + |
| 17 | +This model transforms images into dynamic video while preserving character identity, enabling consistent motion and synchronized audio. Compared to earlier versions, Wan 2.6 offers stronger instruction following, higher visual fidelity, and significantly enhanced sound generation. |
| 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 | +## How to Make a Call |
| 24 | + |
| 25 | +<details> |
| 26 | + |
| 27 | +<summary>Step-by-Step Instructions</summary> |
| 28 | + |
| 29 | +Generating a video using this model involves sequentially calling two endpoints: |
| 30 | + |
| 31 | +* The first one is for creating and sending a video generation task to the server (returns a generation ID). |
| 32 | +* The second one is for requesting the generated video from the server using the generation ID received from the first endpoint. Below, you can find both corresponding API schemas. |
| 33 | + |
| 34 | +</details> |
| 35 | + |
| 36 | +## API Schemas |
| 37 | + |
| 38 | +### Create a video generation task and send it to the server |
| 39 | + |
| 40 | +{% openapi-operation spec="wan2-6-i2v" path="/v2/video/generations" method="post" %} |
| 41 | +[OpenAPI wan2-6-i2v](https://raw.githubusercontent.com/aimlapi/api-docs/refs/heads/main/docs/api-references/video-models/Alibaba-Cloud/wan2.6-i2v.json) |
| 42 | +{% endopenapi-operation %} |
| 43 | + |
| 44 | +### Retrieve the generated video from the server |
| 45 | + |
| 46 | +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.\ |
| 47 | +If the video generation task status is `complete`, the response will include the final result — with the generated video URL and additional metadata. |
| 48 | + |
| 49 | +{% openapi-operation spec="universal-video-endpoint-fetch" path="/v2/video/generations" method="get" %} |
| 50 | +[OpenAPI universal-video-endpoint-fetch](https://raw.githubusercontent.com/aimlapi/api-docs/refs/heads/main/docs/api-references/video-models/universal-video-fetch.json) |
| 51 | +{% endopenapi-operation %} |
| 52 | + |
| 53 | +## Code Example |
| 54 | + |
| 55 | +The code below creates a video generation task, then automatically polls the server every **15** seconds until it finally receives the video URL. |
| 56 | + |
| 57 | +{% tabs %} |
| 58 | +{% tab title="Python" %} |
| 59 | +{% code overflow="wrap" %} |
| 60 | +```python |
| 61 | +import requests |
| 62 | +import time |
| 63 | + |
| 64 | +# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>: |
| 65 | +api_key = "<YOUR_AIMLAPI_KEY>" |
| 66 | +base_url = "https://api.aimlapi.com/v2" |
| 67 | + |
| 68 | +# Creating and sending a video generation task to the server |
| 69 | +def generate_video(): |
| 70 | + url = f"{base_url}/video/generations" |
| 71 | + headers = { |
| 72 | + "Authorization": f"Bearer {api_key}", |
| 73 | + "Content-Type": "application/json" |
| 74 | + } |
| 75 | + |
| 76 | + payload = { |
| 77 | + "model": "alibaba/wan-2-6-i2v", |
| 78 | + "prompt": "Mona Lisa puts on glasses with her hands.", |
| 79 | + "image_url": "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/mona_lisa_extended.jpg", |
| 80 | + "duration": "5", |
| 81 | + } |
| 82 | + |
| 83 | + response = requests.post(url, json=payload, headers=headers) |
| 84 | + |
| 85 | + if response.status_code >= 400: |
| 86 | + print(f"Error: {response.status_code} - {response.text}") |
| 87 | + else: |
| 88 | + response_data = response.json() |
| 89 | + return response_data |
| 90 | + |
| 91 | +# Requesting the result of the task from the server using the generation_id |
| 92 | +def get_video(gen_id): |
| 93 | + url = f"{base_url}/video/generations" |
| 94 | + params = { |
| 95 | + "generation_id": gen_id, |
| 96 | + } |
| 97 | + |
| 98 | + headers = { |
| 99 | + "Authorization": f"Bearer {api_key}", |
| 100 | + "Content-Type": "application/json" |
| 101 | + } |
| 102 | + |
| 103 | + response = requests.get(url, params=params, headers=headers) |
| 104 | + return response.json() |
| 105 | + |
| 106 | + |
| 107 | +def main(): |
| 108 | + # Running video generation and getting a task id |
| 109 | + gen_response = generate_video() |
| 110 | + print(gen_response) |
| 111 | + gen_id = gen_response.get("id") |
| 112 | + print("Generation ID: ", gen_id) |
| 113 | + |
| 114 | + # Try to retrieve the video from the server every 15 sec |
| 115 | + if gen_id: |
| 116 | + start_time = time.time() |
| 117 | + |
| 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="JS" %} |
| 146 | +{% code overflow="wrap" %} |
| 147 | +```javascript |
| 148 | +const https = require("https"); |
| 149 | +const { URL } = require("url"); |
| 150 | + |
| 151 | +// Replace <YOUR_AIMLAPI_KEY> with your actual AI/ML API key |
| 152 | +const apiKey = "<YOUR_AIMLAPI_KEY>"; |
| 153 | +const baseUrl = "https://api.aimlapi.com/v2"; |
| 154 | + |
| 155 | +// Creating and sending a video generation task to the server |
| 156 | +function generateVideo(callback) { |
| 157 | + const data = JSON.stringify({ |
| 158 | + model: "alibaba/wan-2-6-i2v", |
| 159 | + prompt: "Mona Lisa puts on glasses with her hands.", |
| 160 | + image_url: "https://raw.githubusercontent.com/aimlapi/api-docs/main/reference-files/mona_lisa_extended.jpg", |
| 161 | + duration: "5", |
| 162 | + }); |
| 163 | + |
| 164 | + const url = new URL(`${baseUrl}/video/generations`); |
| 165 | + const options = { |
| 166 | + method: "POST", |
| 167 | + headers: { |
| 168 | + "Authorization": `Bearer ${apiKey}`, |
| 169 | + "Content-Type": "application/json", |
| 170 | + "Content-Length": Buffer.byteLength(data), |
| 171 | + }, |
| 172 | + }; |
| 173 | + |
| 174 | + const req = https.request(url, options, (res) => { |
| 175 | + let body = ""; |
| 176 | + res.on("data", (chunk) => body += chunk); |
| 177 | + res.on("end", () => { |
| 178 | + if (res.statusCode >= 400) { |
| 179 | + console.error(`Error: ${res.statusCode} - ${body}`); |
| 180 | + callback(null); |
| 181 | + } else { |
| 182 | + const parsed = JSON.parse(body); |
| 183 | + callback(parsed); |
| 184 | + } |
| 185 | + }); |
| 186 | + }); |
| 187 | + |
| 188 | + req.on("error", (err) => console.error("Request error:", err)); |
| 189 | + req.write(data); |
| 190 | + req.end(); |
| 191 | +} |
| 192 | + |
| 193 | +// Requesting the result of the task from the server using the generation_id |
| 194 | +function getVideo(genId, callback) { |
| 195 | + const url = new URL(`${baseUrl}/video/generations`); |
| 196 | + url.searchParams.append("generation_id", genId); |
| 197 | + |
| 198 | + const options = { |
| 199 | + method: "GET", |
| 200 | + headers: { |
| 201 | + "Authorization": `Bearer ${apiKey}`, |
| 202 | + "Content-Type": "application/json", |
| 203 | + }, |
| 204 | + }; |
| 205 | + |
| 206 | + const req = https.request(url, options, (res) => { |
| 207 | + let body = ""; |
| 208 | + res.on("data", (chunk) => body += chunk); |
| 209 | + res.on("end", () => { |
| 210 | + const parsed = JSON.parse(body); |
| 211 | + callback(parsed); |
| 212 | + }); |
| 213 | + }); |
| 214 | + |
| 215 | + req.on("error", (err) => console.error("Request error:", err)); |
| 216 | + req.end(); |
| 217 | +} |
| 218 | + |
| 219 | +// Initiates video generation and checks the status every 15 seconds until completion or timeout |
| 220 | +function main() { |
| 221 | + generateVideo((genResponse) => { |
| 222 | + if (!genResponse || !genResponse.id) { |
| 223 | + console.error("No generation ID received."); |
| 224 | + return; |
| 225 | + } |
| 226 | + |
| 227 | + const genId = genResponse.id; |
| 228 | + console.log("Generation ID:", genId); |
| 229 | + |
| 230 | + const timeout = 1000 * 1000; // 1000 sec |
| 231 | + const interval = 15 * 1000; // 15 sec |
| 232 | + const startTime = Date.now(); |
| 233 | + |
| 234 | + const checkStatus = () => { |
| 235 | + if (Date.now() - startTime >= timeout) { |
| 236 | + console.log("Timeout reached. Stopping."); |
| 237 | + return; |
| 238 | + } |
| 239 | + |
| 240 | + getVideo(genId, (responseData) => { |
| 241 | + if (!responseData) { |
| 242 | + console.error("Error: No response from API"); |
| 243 | + return; |
| 244 | + } |
| 245 | + |
| 246 | + const status = responseData.status; |
| 247 | + |
| 248 | + if (["queued", "generating"].includes(status)) { |
| 249 | + console.log(`Status: ${status}. Checking again in 15 seconds.`); |
| 250 | + setTimeout(checkStatus, interval); |
| 251 | + } else { |
| 252 | + console.log("Processing complete:\n", responseData); |
| 253 | + } |
| 254 | + }); |
| 255 | + }; |
| 256 | + checkStatus(); |
| 257 | + }) |
| 258 | +} |
| 259 | + |
| 260 | +main(); |
| 261 | +``` |
| 262 | +{% endcode %} |
| 263 | +{% endtab %} |
| 264 | +{% endtabs %} |
| 265 | + |
| 266 | +<details> |
| 267 | + |
| 268 | +<summary>Response</summary> |
| 269 | + |
| 270 | +{% code overflow="wrap" %} |
| 271 | +```json5 |
| 272 | +{'id': 'V2cdWP9kao8xiofM-OvwG', 'status': 'queued', 'meta': {'usage': {'credits_used': 1575000}}} |
| 273 | +Generation ID: V2cdWP9kao8xiofM-OvwG |
| 274 | +Status: queued. Checking again in 15 seconds. |
| 275 | +Status: generating. Checking again in 15 seconds. |
| 276 | +Status: generating. Checking again in 15 seconds. |
| 277 | +Status: generating. Checking again in 15 seconds. |
| 278 | +Status: generating. Checking again in 15 seconds. |
| 279 | +Status: generating. Checking again in 15 seconds. |
| 280 | +Status: generating. Checking again in 15 seconds. |
| 281 | +Status: generating. Checking again in 15 seconds. |
| 282 | +Status: generating. Checking again in 15 seconds. |
| 283 | +Status: generating. Checking again in 15 seconds. |
| 284 | +Status: generating. Checking again in 15 seconds. |
| 285 | +Processing complete: |
| 286 | + {'id': 'V2cdWP9kao8xiofM-OvwG', 'status': 'completed', 'video': {'url': 'https://cdn.aimlapi.com/alpaca/1d/1b/20260107/0fa8e3c9/29195163-523901dd-f86f-434a-bf96-0223ec06c352.mp4?Expires=1767805107&OSSAccessKeyId=LTAI5tRcsWJEymQaTsKbKqGf&Signature=WY0q7xM%2F9N9dhsW7OiJfHPOegkU%3D'}} |
| 287 | +``` |
| 288 | +{% endcode %} |
| 289 | + |
| 290 | +</details> |
| 291 | + |
| 292 | +**Processing time**: \~ 2 min 52 sec. |
| 293 | + |
| 294 | +**Generated video** (1920x1080, with sound): |
| 295 | + |
| 296 | +{% embed url="https://drive.google.com/file/d/1Vm4vw72JrqV3XaXL699Z-x-I4mWjBnkk/view" %} |
0 commit comments