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

# Kling 图生视频

> <ul><li>使用 Kling 模型从图片生成视频。</li><li>支持通过 image 参数传入图片 URL 或 Base64 编码的图片数据。</li></ul>

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl --request POST \
    --url 'https://api.elkapi.com/kling/v1/videos/image2video' \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "kling-v3",
    "prompt": "一只小猫在阳光下的花园里奔跑，电影感，高细节",
    "image": "https://example.com/image.png",
    "duration": 5,
    "response_format": "json",
    "metadata": {}
  }'
  ```

  ```python Python theme={null} theme={null}
  import requests

  url = "https://api.elkapi.com/kling/v1/videos/image2video"
  headers = {
      "Authorization": "Bearer <token>"
  }
  headers["Content-Type"] = "application/json"
  payload = {
      "model": "kling-v3",
      "prompt": "一只小猫在阳光下的花园里奔跑，电影感，高细节",
      "image": "https://example.com/image.png",
      "duration": 5,
      "response_format": "json",
      "metadata": {}
  }

  response = requests.request("POST", url, headers=headers, json=payload)
  print(response.json())
  ```

  ```javascript JavaScript theme={null} theme={null}
  const url = "https://api.elkapi.com/kling/v1/videos/image2video";

  const headers = {
    "Authorization": "Bearer <token>"
  };
  headers["Content-Type"] = "application/json";
  const payload = {
    "model": "kling-v3",
    "prompt": "一只小猫在阳光下的花园里奔跑，电影感，高细节",
    "image": "https://example.com/image.png",
    "duration": 5,
    "response_format": "json",
    "metadata": {}
  };

  const response = await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(payload)
  });

  console.log(await response.json());
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null} theme={null}
  {
    "task_id": "task_1234567890",
    "status": "queued"
  }
  ```

  ```json 400 theme={null} theme={null}
  {
    "error": {
      "message": "message",
      "type": "type",
      "param": "param",
      "code": "code"
    }
  }
  ```
</ResponseExample>

## Authorizations

<ParamField header="Authorization" type="string" required>
  所有接口均需要使用 Bearer Token 进行认证。

  在请求头中添加：

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" default="kling-v3">
  模型/风格 ID

  示例：`kling-v3`
</ParamField>

<ParamField body="prompt" type="string">
  文本描述提示词

  示例：`宇航员站起身走了`
</ParamField>

<ParamField body="image" type="string">
  图片输入 (URL 或 Base64)

  示例：`https://example.com/image.jpg`
</ParamField>

<ParamField body="duration" type="number">
  视频时长（秒）

  示例：`5`
</ParamField>

<ParamField body="width" type="integer">
  视频宽度

  示例：`1280`
</ParamField>

<ParamField body="height" type="integer">
  视频高度

  示例：`720`
</ParamField>

<ParamField body="fps" type="integer">
  视频帧率

  示例：`30`
</ParamField>

<ParamField body="seed" type="integer">
  随机种子

  示例：`20231234`
</ParamField>

<ParamField body="n" type="integer">
  生成视频数量

  示例：`1`
</ParamField>

<ParamField body="response_format" type="string">
  响应格式

  示例：`url`
</ParamField>

<ParamField body="user" type="string">
  用户标识

  示例：`user-1234`
</ParamField>

<ParamField body="metadata" type="object">
  扩展参数 (如 negative\_prompt, style, quality\_level 等)
</ParamField>

## Response

<ResponseField name="task_id" type="string">
  任务 ID

  示例：`abcd1234efgh`
</ResponseField>

<ResponseField name="status" type="string">
  任务状态

  示例：`queued`
</ResponseField>
