> ## Documentation Index
> Fetch the complete documentation index at: https://www.krea.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 图生视频

> 通过 Krea API 用 ByteDance Seedance 等视频模型让图像动起来，支持图像 URL 或 base64 输入及 REST、SDK 示例。

<video autoPlay muted loop playsInline>
  <source src="https://s.krea.ai/docs-image-to-video-new.webm" type="video/webm" />
</video>

![](https://s.krea.ai/docs-image-to-video.webp)

# 图生视频

让图像动起来。借助 AI 驱动的动画与镜头运动,将静态图像转化为动态视频。

# 图生视频

让图像动起来。借助 AI 驱动的动画与镜头运动,将静态图像转化为动态视频。

如需使用 ByteDance 的模型让图像动起来，请参阅 [Seedance 图生视频 API 指南](https://www.krea.ai/docs/cn/developers/seedance.md#animate-an-image)。使用 Krea API token，并在 `start_image` 中传入你的图像。

## 热门模型

Veo 3.1 logo

### [Veo 3.1](https://www.krea.ai/docs/api-reference/video/veo-31.md)

Google 的视频模型,具备出色的提示词遵循能力和电影级画质。

Kling 2.5 logo

### [Kling 2.5](https://www.krea.ai/docs/api-reference/video/kling-25.md)

先进的运动控制,具备时间一致性与逼真的物理表现。

Hailuo 2.3 logo

### [Hailuo 2.3](https://www.krea.ai/docs/api-reference/video/hailuo-23.md)

生成速度快,运动流畅,场景过渡自然。

Wan 2.5 logo

### [Wan 2.5](https://www.krea.ai/docs/api-reference/video/wan-25.md)

高分辨率视频合成,支持风格控制并保留细节。

***

> [!NOTE]
>
> 图生视频会将您输入的图像与运动生成相结合。输出视频在与源图像保持视觉一致性的同时,加入逼真的运动效果。

***

## 第 1 步:准备您的图像

首先,您需要提供源图像。您可以上传文件、引用 URL,或提供 base64 数据 URI。

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
// npm install @krea-ai/sdk
import { openAsBlob } from "node:fs";
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

// Option 1: Upload a local file and use the hosted asset URL
const file = await openAsBlob("./input-image.jpg", { type: "image/jpeg" });
const asset = await krea.assets.upload(file, {
  description: "Input image",
});
const imageUrl = asset.image_url;

// Option 2: Using image URL
// const imageUrl = "https://example.com/input-image.jpg";
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
import requests

API_BASE = "https://api.krea.ai"
API_TOKEN = "YOUR_API_TOKEN"

# Option 1: Upload a local file and use the hosted asset URL
with open("input-image.jpg", "rb") as image_file:
    upload = requests.post(
        f"{API_BASE}/assets",
        headers={"Authorization": f"Bearer {API_TOKEN}"},
        files={"file": ("input-image.jpg", image_file, "image/jpeg")},
        data={"description": "Input image"},
    )
upload.raise_for_status()
image_url = upload.json()["image_url"]

# Option 2: Using image URL
# image_url = "https://example.com/input-image.jpg"
```

> [!NOTE]
>
> **替换为您的 API Token**
>
> 要替换上述示例中的 YOUR\_API\_TOKEN 占位符,您需要在 [krea.ai/settings/api-tokens](https://www.krea.ai/settings/api-tokens) 生成一个 API token。如需帮助,请参阅 [API 密钥与计费](https://www.krea.ai/docs/developers/api-keys-and-billing.md)页面。

***

## 第 2 步:生成视频

携带您的图像和运动参数,向 `/generate/video/kling/kling-2.5` 发起 POST 请求。

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

const job = await krea.video("kling/kling-2.5", {
  start_image: imageUrl,
  prompt: "gentle camera pan from left to right, subtle depth",
  duration: 5,
  aspect_ratio: "16:9"
});

console.log(`Job ID: ${job.job_id}`);
```

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl -X POST https://api.krea.ai/generate/video/kling/kling-2.5 \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "start_image": "https://example.com/input-image.jpg",
    "prompt": "gentle camera pan from left to right, subtle depth",
    "duration": 5,
    "aspect_ratio": "16:9"
  }'
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
response = requests.post(
    f"{API_BASE}/generate/video/kling/kling-2.5",
    headers={
        "Authorization": f"Bearer {API_TOKEN}",
        "Content-Type": "application/json"
    },
    json={
        "start_image": image_url,
        "prompt": "gentle camera pan from left to right, subtle depth",
        "duration": 5,
        "aspect_ratio": "16:9"
    }
)

job = response.json()
print(f"Job ID: {job['job_id']}")
```

```go Go theme={"theme":{"light":"github-light-default","dark":"vesper"}}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    apiBase := "https://api.krea.ai"
    apiToken := "YOUR_API_TOKEN"

    payload := map[string]interface{}{
        "start_image": "https://example.com/input-image.jpg",
        "prompt": "gentle camera pan from left to right, subtle depth",
        "duration": 5,
        "aspect_ratio": "16:9",
    }

    jsonData, _ := json.Marshal(payload)
    req, _ := http.NewRequest("POST", apiBase+"/generate/video/kling/kling-2.5", bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer "+apiToken)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    var job map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&job)
    fmt.Printf("Job ID: %s\n", job["job_id"])
}
```

> [!NOTE]
>
> **替换为您的 API Token**
>
> 要替换上述示例中的 YOUR\_API\_TOKEN 占位符,您需要在 [krea.ai/settings/api-tokens](https://www.krea.ai/settings/api-tokens) 生成一个 API token。如需帮助,请参阅 [API 密钥与计费](https://www.krea.ai/docs/developers/api-keys-and-billing.md)页面。

**响应示例**

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "scheduled",
  "created_at": "2025-01-15T10:30:00.000Z",
  "estimated_time": "60-120 seconds"
}
```

***

## 第 3 步:轮询结果

每 5 秒轮询一次 `/jobs/{job_id}`,以检查视频生成进度。

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

async function waitForVideo(jobId) {
  const completed = await krea.jobs.wait(jobId, { intervalMs: 5000 });
  return completed.result.urls[0];
}

const videoUrl = await waitForVideo(job.job_id);
console.log(`Video ready: ${videoUrl}`);
```

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl -X GET https://api.krea.ai/jobs/YOUR_JOB_ID \
  -H "Authorization: Bearer YOUR_API_TOKEN"
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
import time

def wait_for_video(job_id):
    while True:
        response = requests.get(
            f"{API_BASE}/jobs/{job_id}",
            headers={"Authorization": f"Bearer {API_TOKEN}"}
        )
        job = response.json()

        if job["status"] == "completed":
            return job["result"]["urls"][0]
        if job["status"] in ("failed", "cancelled"):
            raise Exception(f"Job failed: {job['status']}")

        # Show progress if available
        if "progress" in job:
            print(f"Progress: {job['progress']}%")
        else:
            print(f"Status: {job['status']}")

        time.sleep(5)

video_url = wait_for_video(job["job_id"])
print(f"Video ready: {video_url}")
```

```go Go theme={"theme":{"light":"github-light-default","dark":"vesper"}}
func waitForVideo(jobID string) (string, error) {
    for {
        req, _ := http.NewRequest("GET", apiBase+"/jobs/"+jobID, nil)
        req.Header.Set("Authorization", "Bearer "+apiToken)

        resp, _ := client.Do(req)
        var job map[string]interface{}
        json.NewDecoder(resp.Body).Decode(&job)
        resp.Body.Close()

        switch job["status"] {
        case "completed":
            result := job["result"].(map[string]interface{})
            urls := result["urls"].([]interface{})
            return urls[0].(string), nil
        case "failed", "cancelled":
            return "", fmt.Errorf("job failed: %s", job["status"])
        }

        // Show progress if available
        if progress, ok := job["progress"]; ok {
            fmt.Printf("Progress: %.0f%%\n", progress)
        } else {
            fmt.Printf("Status: %s\n", job["status"])
        }

        time.Sleep(5 * time.Second)
    }
}
```

**已完成响应示例**

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "completed",
  "created_at": "2025-01-15T10:30:00.000Z",
  "completed_at": "2025-01-15T10:31:45.000Z",
  "result": {
    "urls": ["https://gen.krea.ai/videos/your-video.mp4"]
  }
}
```

> [!NOTE]
>
> **支持 Webhook!**
>
> 设置 Webhook 即可在任务完成时收到通知。请参阅 [Webhooks 指南](https://www.krea.ai/docs/developers/webhooks.md)开始使用。

***

## 常用参数

> [!TIP]
>
> 如需查看所有模型的详细参数列表,请参阅[模型 API](https://www.krea.ai/docs/api-reference/introduction.md) 页面。

| 参数 | 类型 | 描述 |
| - | - | - |
| `start_image` | string | 源图像的 URL |
| `prompt` | string | 期望的运动和镜头移动的描述 |
| `duration` | number | 视频时长(秒)。支持的取值取决于具体模型。 |
| `aspect_ratio` | string | 视频宽高比,例如 `16:9`、`9:16` 或 `1:1` |
| `end_image` | string | 可选的结束帧 URL(仅部分模型支持) |
| `mode` | string | 可选的质量模式(仅部分模型提供) |

> [!TIP]
>
> **运动提示词技巧:**
>
> * 描述镜头运动(平移、缩放、推拉、俯仰)
> * 指明运动方向与速度
> * 提及景深和视差效果
> * 对细微动画使用克制的镜头语言
> * 对强烈效果使用更有力的动作动词


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.