Image-to-Video API Guide: First Frame, Last Frame, Webhooks
How to call an image-to-video API: send a first frame or first and last frames, create the async task, then collect the result by polling or webhook.

On this page
An image-to-video call has three parts: you send one or two images and a prompt, the API creates an asynchronous task, and you collect the finished video by polling or by receiving a webhook. That loop is the same on every model. The field names, the status strings and the lifetime of the result link are not.
This guide walks through the loop with Seedance 2.5 as the running example, then shows where Kling 4.0 and Wan 3.0 differ. Every endpoint, parameter and limit below comes from the DreamTo API docs. For the rest of the Seedance API, see the Seedance 2.5 API guide.
Three models, three request formats#
Each of the three models takes a first frame alone or a first and last frame, but they do not share a request format.
| Model | Create endpoint | First frame | Last frame | Duration | Resolution |
|---|---|---|---|---|---|
seedance-2.5 | POST /api/v3/contents/generations/tasks | image_url item with role: first_frame | role: last_frame | 4 to 30 s, or -1 | 480p, 720p, 1080p, 4k |
kling-4.0 | POST /v1/videos | input.image_url | input.last_frame_url | 3 to 30 s | 720P, 1080P, 2K, 4K |
wan3.0-video | POST /api/v1/services/aigc/video-generation/video-synthesis | input.media item with type: first_frame | type: last_frame | 2 to 30 s, or -1 | 480P, 720P, 1080P |
All three use the same Authorization: Bearer $DREAMTO_API_KEY header. Create a key on the API Key page of the console and keep it on your server; see the authentication docs.
Set duration and resolution explicitly, because the defaults differ. Seedance 2.5 defaults to duration: -1 (the model picks 4 to 30 seconds) at 720p, Kling 4.0 to 5 seconds at 720P, and Wan 3.0 to 5 seconds at 1080P.
Send a first frame to Seedance 2.5#
The first frame is the image the video starts from. In the prompt, describe how the image should move; there is no need to restate what it shows.
On Seedance the prompt and the image go in one content array, and the image item carries role: first_frame. The output follows the image's aspect ratio, and ratio has no effect.
curl -X POST "https://api.dreamto.ai/api/v3/contents/generations/tasks" \ -H "Authorization: Bearer $DREAMTO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "seedance-2.5", "content": [ { "type": "text", "text": "Slow push-in, the person smiles, hair gently moving in the breeze, cinematic lighting" }, { "type": "image_url", "image_url": { "url": "https://example.com/portrait.jpg" }, "role": "first_frame" } ], "duration": 5, "resolution": "720p" }'The response is a task id, not a video:
{ "id": "task_8c1d2e3f4a5b6c7d8e9f0a1b", "request_id": "req_3f9a1c2b7d4e5f60718293a4"}You poll with id. request_id equals the X-Request-Id response header; quote it when you contact support.
Image URLs, Base64 and asset references#
Seedance accepts an image as a public http(s) URL, as asset://<asset Id> for a file in the asset library, or as inline Base64 in the form data:image/png;base64,.... Base64 is limited to 45 MB per item after decoding and 64 MB for the whole request body; invalid or oversized Base64 returns HTTP 400.
The image must be jpeg, png, webp, bmp, tiff or gif, with an aspect ratio between 0.4 and 2.5, sides of 300 to 6000 px and at most 30 MB. The model enforces those limits, so an image outside them does not fail the create call: the task ends as failed with the reason.
Kling reads image_url and last_frame_url as public URLs to a jpeg, jpg or png of up to 10 MB. Wan takes a public http(s) URL or, for images, Base64 data in the form data:{MIME};base64,{data}; temporary storage URLs such as oss:// are not supported.
When Kling cannot fetch the URL, the task ends as failed with a message such as InvalidParameterValue: Please input the ImageURL that can be retrieved from the external network.
Add a last frame for a transition#
A last frame turns the call into a transition: the video starts on one image and ends on the other, and the prompt describes the motion in between. The closer the two images are in composition and subject, the smoother the transition. The output still follows the input ratio.
On Seedance, add a second image item with role: last_frame:
{ "model": "seedance-2.5", "content": [ { "type": "text", "text": "Smoothly transition from the first image to the second, steady push-in, soft light, cinematic transition" }, { "type": "image_url", "image_url": { "url": "https://example.com/frame_start.jpg" }, "role": "first_frame" }, { "type": "image_url", "image_url": { "url": "https://example.com/frame_end.jpg" }, "role": "last_frame" } ], "duration": 5, "resolution": "720p"}Kling puts both URLs inside input, next to the prompt and the generation settings. last_frame_url must be sent together with image_url:
{ "model": "kling-4.0", "input": { "prompt": "The camera pushes in slowly as day turns to night and the city lights come on", "image_url": "https://your-cdn.example.com/first-frame.png", "last_frame_url": "https://your-cdn.example.com/last-frame.png", "resolution": "1080P", "duration": 8 }}Wan requests follow the DashScope protocol: frames are items in input.media, generation settings go in parameters, and the create call needs one more header, X-DashScope-Async: enable:
{ "model": "wan3.0-video", "input": { "prompt": "The character walks from the window to the door; the camera follows.", "media": [ { "type": "first_frame", "url": "https://your-cdn.example.com/first-frame.jpg" }, { "type": "last_frame", "url": "https://your-cdn.example.com/last-frame.jpg" } ] }, "parameters": { "resolution": "720P", "duration": 6 }}Frame mode on Wan takes no audio input, and frames cannot be combined with reference images, videos or audio.
Create the task and poll for the result#
Creation returns a task id, not a video, so the client needs a loop. The script below creates a Seedance first-frame task, polls it and downloads the result. Set DREAMTO_API_KEY and replace the image URL.
import osimport timeimport requestsURL = "https://api.dreamto.ai/api/v3/contents/generations/tasks"HEADERS = {"Authorization": f"Bearer {os.environ['DREAMTO_API_KEY'].strip()}"}payload = { "model": "seedance-2.5", "content": [ {"type": "text", "text": "Slow push-in, the person smiles, hair gently moving in the breeze"}, { "type": "image_url", "image_url": {"url": "https://example.com/portrait.jpg"}, "role": "first_frame", }, ], "duration": 5, "resolution": "720p",}resp = requests.post(URL, headers=HEADERS, json=payload, timeout=60)if not resp.ok: err = resp.json()["error"] raise RuntimeError(f"{resp.status_code} {err['code']}: {err['message']} (param={err.get('param')})")task_id = resp.json()["id"]started = time.time()while True: task = requests.get(f"{URL}/{task_id}", headers=HEADERS, timeout=30).json() if task["status"] == "succeeded": video_url = task["content"]["video_url"] break if task["status"] == "failed": raise RuntimeError(task["error"]["message"]) elapsed = time.time() - started if elapsed > 30 * 60: raise TimeoutError(f"task {task_id} not finished after 30 minutes") time.sleep(3 if elapsed < 30 else 5 if elapsed < 120 else 10)# The video URL is a direct link: do not send the Authorization header.with requests.get(video_url, stream=True, timeout=300) as r: r.raise_for_status() with open(f"{task_id}.mp4", "wb") as f: for chunk in r.iter_content(chunk_size=1 << 20): f.write(chunk)print("saved", f"{task_id}.mp4")The schedule is the one in the Seedance docs: every 3 seconds for the first 30 seconds, every 5 seconds up to 2 minutes, then every 10 seconds. Query a task with the API key that created it; any other key gets a 404.
Status values and result fields by model#
Each model names its states and its result field differently:
| Model | Poll endpoint | Status field | In progress | Success | Failure | Video URL |
|---|---|---|---|---|---|---|
seedance-2.5 | GET /api/v3/contents/generations/tasks/{id} | status | running | succeeded | failed | content.video_url |
kling-4.0 | GET /v1/videos/{task_id} | status | queued, in_progress | completed | failed | video_url |
wan3.0-video | GET /api/v1/tasks/{task_id} | output.task_status | PENDING, RUNNING | SUCCEEDED | FAILED, CANCELED, UNKNOWN | output.video_url |
The task id in the create response is id on Seedance, task_id on Kling and output.task_id on Wan.
The Kling docs say a video takes several minutes and ask for a poll every 10 to 15 seconds, not faster. The Wan docs say about every 15 seconds. Wan task ids can be queried for 24 hours; after that, or when the task does not exist or belongs to another account, the query returns task_status: UNKNOWN, so treat UNKNOWN as a final state.
Receive the result by webhook#
On Seedance, add callback_url to the create request and the platform sends one POST to that URL when the task reaches a final state, succeeded or failed:
{ "model": "seedance-2.5", "content": [ { "type": "text", "text": "Slow push-in, steam rising from the cup" }, { "type": "image_url", "image_url": { "url": "https://example.com/cup.jpg" }, "role": "first_frame" } ], "duration": 5, "resolution": "720p", "callback_url": "https://your-server.example.com/dreamto/callback"}The callback body differs from the query response, so parse it separately. Its status is success or failed, where the query endpoint says succeeded:
{ "event": "task.completed", "taskId": "task_8c1d2e3f4a5b6c7d8e9f0a1b", "status": "success", "result": ["https://example-cdn.com/videos/2026/11/11/output.mp4"], "errorMsg": "", "timestamp": "2026-11-11T08:03:16Z", "signature": "5d0c1b7e9a..."}On failure result is [] and errorMsg carries the reason. The task callback docs set these rules for the receiver:
callback_urlmust behttporhttps; anything else returns HTTP 400 at creation.- If the URL resolves to a private, loopback or link-local address, delivery is refused, so
localhostwill not work. - The timeout is 10 seconds and any
2xxcounts as success. A failed first attempt is retried after 1, 5 and 30 minutes, for at most 4 deliveries. - The same task can be delivered more than once, so deduplicate on
taskId. - After the last retry fails, nothing more is sent. Recover the result through Get task or List tasks.
Verify the callback signature#
If your account has a webhook signing secret, each callback carries an X-DreamTo-Signature header. You generate the secret on the API Key page of the console; it is whsec_ followed by 48 lowercase hex characters. The signature is the lowercase hex HMAC-SHA256 of timestamp.taskId.status, keyed with the full secret including the whsec_ prefix. The X-DreamTo-Timestamp header repeats the body timestamp.
Without a secret the signature header is not sent and the body signature is an empty string, so the docs recommend generating one for production. This receiver rejects unsigned callbacks, compares signatures in constant time and leaves the download to a background job:
import hashlibimport hmacimport jsonimport osfrom flask import Flask, abort, requestapp = Flask(__name__)WEBHOOK_SECRET = os.environ["DREAMTO_WEBHOOK_SECRET"] # whsec_...def expected_signature(secret: str, timestamp: str, task_id: str, status: str) -> str: message = f"{timestamp}.{task_id}.{status}".encode("utf-8") return hmac.new(secret.encode("utf-8"), message, hashlib.sha256).hexdigest()@app.post("/dreamto/callback")def dreamto_callback(): payload = json.loads(request.get_data()) signature = request.headers.get("X-DreamTo-Signature", "") timestamp = request.headers.get("X-DreamTo-Timestamp", "") if not signature or timestamp != payload.get("timestamp"): abort(401) expected = expected_signature( WEBHOOK_SECRET, payload["timestamp"], payload["taskId"], payload["status"] ) if not hmac.compare_digest(expected, signature): abort(401) # Be idempotent on taskId: retries can deliver the same task more than once. if payload["status"] == "success": video_url = payload["result"][0] # enqueue a download of video_url else: print("task failed:", payload["taskId"], payload["errorMsg"]) return "", 204The signature covers timestamp, taskId and status, not the result URL. To verify the URL as well, call Get task with the taskId after the callback arrives. Keep a low-frequency poll running too: the docs say callbacks only speed up notification, and the query endpoint is the source of truth.
Kling 4.0 and Wan 3.0: polling only#
The Kling 4.0 and Wan 3.0 docs describe polling only and list no callback parameter, so build those two around the poll loop.
Handle rejected requests and failed tasks#
The create call is rejected. No task exists and nothing is billed. The Seedance task API returns an HTTP status and a body with error.code, error.message and, for validation errors, error.param:
| HTTP | error.code | Typical cause |
|---|---|---|
| 400 | invalid_parameter | Empty content, no text prompt, duration out of range, unsupported parameter |
| 400 | invalid_request | Malformed request, or not allowed by business rules |
| 401 | unauthorized | Missing or invalid API key |
| 402 | insufficient_balance | Not enough balance |
| 403 | forbidden | No access to the resource or model |
| 404 | not_found | Task missing or created by another API key; model unknown or not enabled |
| 429 | rate_limit_exceeded | Rate limit exceeded |
| 500 | api_error | Internal error |
| 502, 503, 504 | service_unavailable | Temporarily unavailable or timed out |
The errors page gives the rule: 4xx errors other than 429 usually need a corrected request, while 429 and 5xx can be retried with exponential backoff. Branch on the HTTP status and error.code, not on the message text.
On Kling, a duration out of range names the field and the allowed range, but a bad enum value such as resolution returns a generic message without the field name, so check the request against the parameter table. Wan rejects invalid parameters with a 400 InvalidParameter.
The task fails during generation. The create call succeeded, so the failure shows up when you poll. Seedance returns HTTP 200 with status: failed and an error object whose code is always task_failed:
{ "id": "task_8c1d2e3f4a5b6c7d8e9f0a1b", "model": "seedance-2.5", "status": "failed", "error": { "code": "task_failed", "message": "Video generation failed, please retry" }, "created_at": 1794384000, "updated_at": 1794384120, "request_id": "req_b2c4d6e8f0a1b3c5d7e9f1a2"}A failed Kling task has status: failed with the reason in error.message. A failed Wan task has task_status: FAILED with output.code and output.message. Read the message before retrying.
Every response, success or failure, carries an X-Request-Id header. Log it with the task id.
Download the video before the link expires#
None of the three result URLs is permanent, and the lifetimes differ:
| Model | What the docs say about the result URL |
|---|---|
seedance-2.5 | Direct download link, no Authorization header; copy it to your own storage soon, it is not permanent |
kling-4.0 | video_url is valid for 7 days after the task completes |
wan3.0-video | output.video_url is a DreamTo link valid for 24 hours from task creation |
Download in the same job that observes success.
Prices and which model to call#
All three models bill per second of output video, at a rate set by the resolution. The table shows DreamTo prices as of December 2026, in USD per second, for a request without a reference video, which is what a frame request is. They include the current discount: 30% on Seedance 2.5 and Wan 3.0, 10% on Kling 4.0. Prices change; the prices page has the current numbers.
| Resolution | seedance-2.5 | kling-4.0 | wan3.0-video |
|---|---|---|---|
| 480p | $0.10794 | not offered | $0.035 |
| 720p | $0.242676 | $0.1413 | $0.07 |
| 1080p | $0.597051 | $0.2115 | $0.14 |
| 2K | not offered | $0.25434 | not offered |
| 4K | $0.959364 | $0.4941 | not offered |
At 720p, a 5-second clip comes to about $1.21 on Seedance 2.5, $0.71 on Kling 4.0 and $0.35 on Wan 3.0. Set duration explicitly when the cost has to be predictable: with -1, Seedance and Wan choose the length and you pay for what was generated. On Kling, 2K and 4K are upscaled output billed at that resolution's price.
What the docs give you to choose on:
- Seedance 2.5 is the only one of the three with a documented webhook, and the same endpoint goes on to references, video editing and extension. See the long video guide.
- Kling 4.0 takes one flat
inputobject. Every video includes audio, and there is no parameter to turn it off. See the Kling 4.0 API guide. - Wan 3.0 follows the DashScope protocol, so existing DashScope code works after changing the base URL and API key. See the Wan 3.0 API guide.
For a side-by-side, read Kling 4.0 vs Seedance 2.5. To try a model before writing code, open its playground: Seedance 2.5, Kling 4.0 or Wan 3.0. The full catalog is on the models page.
Request references: Seedance 2.5 image to video and first and last frame, Kling 4.0, and Wan 3.0 image to video and first and last frame.
FAQ#
What is the difference between first frame and last frame in image-to-video?#
The first frame is the image the video begins on, and the prompt describes the motion that follows. A last frame is an optional second image the video ends on, so the model generates the transition between the two. Seedance 2.5, Kling 4.0 and Wan 3.0 each accept a first frame alone or the pair.
Does the output keep my image's aspect ratio?#
Yes. On Seedance 2.5 the output follows the image ratio and ratio has no effect. On Kling 4.0, aspect_ratio has no effect once a first frame is set. On Wan 3.0 the ratio follows the image, and the docs say to leave ratio at its default, adaptive.
Should I poll or use a webhook?#
On Seedance 2.5, use both: pass callback_url for timely notification and keep a low-frequency poll as a fallback, because a callback is delivered at most 4 times and then nothing more is sent. For Kling 4.0 and Wan 3.0 the docs describe polling only.
How long does the generated video stay available?#
Kling 4.0 keeps video_url valid for 7 days after the task completes, and Wan 3.0 links are valid for 24 hours from task creation. Seedance 2.5 returns a direct link with no stated lifetime; the docs say to copy the file to your own storage soon and not to treat the link as permanent.
Am I charged when a task fails?#
The Kling 4.0 and Wan 3.0 docs state that failed tasks and invalid requests are not charged. On Seedance 2.5, a request rejected by validation creates no task and is not billed.


