# Kling Video Generation API Documentation

Call the **BeeRoute video generation API** to generate video content. This document is dedicated to the **Kling** series of video generation models, supporting **text-to-video, image-to-video (first-frame based), image-to-video (first/last-frame based), reference-to-video, and video editing**.

#### [Download the MD file of this document](https://beeroute.ai/doc/coding/kling-video.md)  

---

## 1. Supported Models

### Model List

| Model Name | Description | Use Cases |
| :--- | :--- | :--- |
| `kling-v3-omni-video-generation` | Kling V3 all-in-one video generation | Text-to-video, image-to-video, reference-to-video, video editing |
| `kling-v3-video-generation` | Kling V3 video generation | Text-to-video, image-to-video (first frame / first-last frame) |

---

#### Kling Video Generation

| Model | Resolution | Mode | Price (USD) |
| :--- | :--- | :--- | :--- |
| **kling-v3-video-generation** | 720P | std (standard) | **$0.0985 / second** |
| | 1080P | pro (professional) | **$0.1314 / second** |
| **kling-v3-omni-video-generation** | 720P | std (standard) | **$0.0985 / second** |
| | 1080P | pro (professional) | **$0.1314 / second** |

> **Billing Notes**:
> - Billed by the **actual duration (seconds)** of the generated video; the `duration` parameter directly affects the cost.
> - The watermark feature (`watermark`) incurs no additional charge.

---

## 2. Generate Video

Since video generation tasks take a relatively long time (usually 1-5 minutes), the API uses asynchronous calls. The entire process consists of two core steps: **"Create task → Poll for result"**.

### API Endpoint

```
POST /v1/videos
```

### Request Headers

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| Authorization | string | Yes | User authentication token (`Bearer sk-xxxx`) |
| Content-Type | string | Yes | **application/json** |

### Request Parameters (JSON Body)

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **model** | string | Yes | Model name. Options:<br>`kling-v3-omni-video-generation`<br>`kling-v3-video-generation` |
| **input** | object | Yes | Basic input information such as prompt and media materials. See [input Parameter Descriptions](#input-parameter-descriptions) below. |
| **parameters** | object | No | Video generation parameters such as generation mode, aspect ratio, video duration, etc. See [parameters Parameter Descriptions](#parameters-parameter-descriptions) below. |

#### input Parameter Descriptions

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **prompt** | string | Conditionally required | Text prompt. Describes the elements and visual characteristics expected in the generated video.<br>Supports Chinese and English, no more than 2500 characters; excess is automatically truncated.<br>Logic:<br>- **Required** when `shot_type=intelligence`.<br>- **Not effective** when `shot_type=customize`; `multi_prompt` takes precedence.<br><br>**Omni model reference format** (only `kling-v3-omni-video-generation`):<br>Reference subjects/images/videos via the `<<<>>>` format, e.g. `<<<element_1>>>`, `<<<image_1>>>`, `<<<video_1>>>`. The reference order is defined by the order of the `media` array. |
| **media** | array | No | Media material list, used to specify image or video materials. Not required for text-to-video tasks. See [media Element Descriptions](#media-element-descriptions) below. |
| **multi_shot** | boolean | No | Whether to enable multi-shot generation.<br>`false` (default): not enabled.<br>`true`: enables multi-shot generation. |
| **shot_type** | string | Conditionally required | Required when `multi_shot=true`. Multi-shot mode type:<br>`intelligence`: smart storyboarding, the model automatically plans shots.<br>`customize`: customize mode, supports custom prompts and durations for each segment. |
| **multi_prompt** | array | Conditionally required | Required when `shot_type=customize`. List of segments in multi-shot customize mode. See [multi_prompt Element Descriptions](#multi_prompt-element-descriptions) below. |
| **element_list** | array | No | Subject list, used to specify subject elements to be introduced into the video. See [element_list Element Descriptions](#element_list-element-descriptions) below. |

##### media Element Descriptions

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **type** | string | Yes | Media material type.<br><br>`kling-v3-video-generation` options:<br>- `first_frame`: first-frame image<br>- `last_frame`: last-frame image<br><br>`kling-v3-omni-video-generation` options:<br>- `first_frame`: first-frame image<br>- `last_frame`: last-frame image<br>- `refer`: reference image<br>- `base`: video to be edited<br>- `feature`: feature reference video |
| **url** | string | Yes | Media material URL (HTTP/HTTPS protocol).<br><br>**Image restrictions** (type=first\_frame / last\_frame / refer):<br>- Format: JPEG, JPG, PNG (transparent channel not supported)<br>- Resolution: width/height range [300, 8000] pixels<br>- File size: ≤10MB<br><br>**Video restrictions** (type=base / feature):<br>- Format: mp4, mov<br>- Duration: 3 ~ 10s<br>- Resolution: width/height range [720, 2160] pixels<br>- File size: ≤200MB<br>- Frame rate: 24 ~ 60fps |
| **keep_original_sound** | string | No | Only supported by `kling-v3-omni-video-generation`.<br>Effective when a video is passed (type=base or feature).<br>`no` (default): do not keep the original sound.<br>`yes`: keep the original sound. |

**Material Combination Rules**

`kling-v3-video-generation` supports the following combinations:
- **Image-to-video, first-frame based**: `first_frame` (1 first-frame image)
- **Image-to-video, first/last-frame based**: `first_frame` + `last_frame` (1 first-frame image, 1 last-frame image)

`kling-v3-omni-video-generation` supports the following combinations:
- **Image-to-video, first-frame based**: `first_frame` (1 image)
- **Image-to-video, first/last-frame based**: `first_frame` + `last_frame` (1 each)
- **Reference-to-video**:
  - `feature` only: must pass 1 video
  - `refer` only: the sum of reference images and `element_list` count ≤ 7
  - `feature` + `refer`: 1 video, the sum of reference images and `element_list` count ≤ 4
  - `feature` + `first_frame`: 1 video + 1 first frame
- **Video editing**:
  - `base` only: must pass 1 video
  - `base` + `refer`: 1 video, the sum of reference images and `element_list` count ≤ 4

##### multi_prompt Element Descriptions

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **index** | integer | Yes | Storyboard segment index; the number of shots is 1 ~ 6, indexed from 0. |
| **prompt** | string | Yes | Prompt for the corresponding segment, no more than 512 characters; excess is automatically truncated. |
| **duration** | integer | Yes | Duration of the corresponding segment (seconds), an integer between [1, `parameters.duration`]. |

##### element_list Element Descriptions

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **element_id** | integer | Conditionally required | Required when passing `element_list`. Subject ID; please refer to the Kling subject ID list to obtain it.<br><br>Quantity limits:<br>- Image-to-video, first-frame/first-last-frame based: up to 3 subjects<br>- Reference-to-video (`type=refer`): the sum of reference images and subject count ≤ 7<br>- Reference-to-video (`type=feature+refer`): the sum of reference images and subject count ≤ 4 |

#### parameters Parameter Descriptions

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **mode** | string | No | Video generation mode.<br>`pro` (default): professional mode, outputs 1080P.<br>`std`: standard mode, outputs 720P. |
| **aspect_ratio** | string | Conditionally required | Aspect ratio of the generated video. Options: `16:9` (default), `9:16`, `1:1`.<br><br>**Scenarios where it must be set**:<br>- Text-to-video<br>- Reference-to-video (`type=feature`, `type=feature+refer`, `type=refer`)<br><br>**Scenarios where it is not required** (based on the aspect ratio of the first frame or input video):<br>- Image-to-video, first-frame/first-last-frame based<br>- Reference-to-video (`type=feature+first_frame`)<br>- Video editing |
| **duration** | integer | No | Generated video duration (seconds).<br>- `kling-v3-omni-video-generation`: integer [3, 15], default 5. When a reference video is passed, [3, 10], default 5.<br>- `kling-v3-video-generation`: integer [3, 15], default 5.<br><br>⚠️ **duration directly affects cost, billed per second.** |
| **audio** | boolean | No | Whether to generate video with sound (automatically generates background music or sound effects based on the video content).<br>`false` (default): outputs silent video.<br>`true`: outputs video with sound.** |
| **watermark** | boolean | No | Whether to add a watermark (located in the bottom-right corner of the video, with the fixed text "Kling AI").<br>`false` (default): not added.<br>`true`: adds a watermark. |

---

### Request Examples

#### 1. Text-to-Video

```bash
curl --location --request POST 'https://beeroute.ai/v1/videos' \
--header 'Authorization: Bearer sk-xxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "kling-v3-video-generation",
    "input": {
        "prompt": "A kitten running under the moonlight"
    },
    "parameters": {
        "mode": "std",
        "aspect_ratio": "16:9",
        "duration": 5,
        "audio": false,
        "watermark": true
    }
}'
```

#### 2. Text-to-Video (Smart Storyboarding)

```bash
curl --location --request POST 'https://beeroute.ai/v1/videos' \
--header 'Authorization: Bearer sk-xxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "kling-v3-video-generation",
    "input": {
        "prompt": "",
        "multi_shot": true,
        "shot_type": "customize",
        "multi_prompt": [
            {
                "index": 1,
                "prompt": "Fogridge Town is even smaller than it looks on the map, with mountain fog clogging the street corners like cotton wool. Behind the post office there are indeed three locust trees, and the soil beside the roots of the third one has been disturbed.",
                "duration": 5
            },
            {
                "index": 2,
                "prompt": "Lin Che crouches down and digs up an iron box containing a rusty key and an old cassette tape.",
                "duration": 5
            }
        ],
        "media": [],
        "element_list": []
    },
    "parameters": {
        "mode": "pro",
        "duration": 10,
        "audio": true,
        "aspect_ratio": "9:16",
        "watermark": true
    }
}'
```

#### 3. Image-to-Video (First-Frame Based)

```bash
curl --location --request POST 'https://beeroute.ai/v1/videos' \
--header 'Authorization: Bearer sk-xxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "kling-v3-omni-video-generation",
    "input": {
        "prompt": "Bring the person in the image to life, with their hair blowing in the breeze",
        "media": [
            {
                "type": "first_frame",
                "url": "https://example.com/first_frame.jpg"
            }
        ]
    },
    "parameters": {
        "mode": "std",
        "duration": 5,
        "audio": false,
        "watermark": true
    }
}'
```

#### 4. Image-to-Video (First/Last-Frame Based)

```bash
curl --location --request POST 'https://beeroute.ai/v1/videos' \
--header 'Authorization: Bearer sk-xxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "kling-v3-omni-video-generation",
    "input": {
        "prompt": "Realistic style: a little black kitten looks curiously up at the sky; the camera rises gradually from eye level and ends with a high-angle shot of its curious eyes.",
        "media": [
            {
                "type": "first_frame",
                "url": "https://example.com/first_frame.png"
            },
            {
                "type": "last_frame",
                "url": "https://example.com/last_frame.png"
            }
        ]
    },
    "parameters": {
        "mode": "std",
        "duration": 5,
        "audio": false,
        "watermark": true
    }
}'
```

#### 5. Reference-to-Video (Video + Image)

Only supported by `kling-v3-omni-video-generation`.

```bash
curl --location --request POST 'https://beeroute.ai/v1/videos' \
--header 'Authorization: Bearer sk-xxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "kling-v3-omni-video-generation",
    "input": {
        "prompt": "With <<<element_1>>> as the background, <<<image_2>>> and <<<image_1>>> shake hands and talk, while the character from <<<video_1>>>, a detective in a black trench coat, stands on the apartment rooftop",
        "multi_shot": false,
        "shot_type": "intelligence",
        "multi_prompt": [],
        "media": [
            {
                "url": "https://example.com/reference_video.mp4",
                "type": "base",
                "keep_original_sound": "yes"
            },
            {
                "type": "refer",
                "url": "https://example.com/refer_image_1.jpg"
            },
            {
                "type": "refer",
                "url": "https://example.com/refer_image_2.jpg"
            }
        ],
        "element_list": [
            {
                "element_id": 171
            }
        ]
    },
    "parameters": {
        "mode": "pro",
        "duration": 10,
        "audio": false,
        "aspect_ratio": "1:1",
        "watermark": true
    }
}'
```

---

### Response Format

#### 200 - Submitted Successfully

```json
{
    "id": "task-xxxxxxxxxxxx"
}
```

> **Note**: The task ID is valid for **24 hours**; the result cannot be queried after expiration. Do not create duplicate tasks; just poll using the returned ID.

#### Error Response

```json
{
    "code": "InvalidApiKey",
    "message": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}
```

---

## 3. Query Task Status

Video generation usually takes 1-5 minutes; poll the status using the task ID. A polling interval of **15 seconds** is recommended.

### API Endpoint

```
GET /v1/videos/{video_id}
```

### Path Parameters

| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| video_id | string | Yes | The `id` returned by the generation API |

---

### Request Example

```bash
curl --location --request GET 'https://beeroute.ai/v1/videos/task-xxxxxxxxxxxx' \
--header 'Authorization: Bearer sk-xxx'
```

---

### Response Format

#### 200 - Completed Successfully (Completed)

```json
{
    "id": "task-xxxxxxxxxxxx",
    "object": "video.generation",
    "model": "kling-v3-video-generation",
    "status": "completed",
    "progress": "100%",
    "created_at": 1769263230,
    "started_at": 1769263245,
    "completed_at": 1769263322,
    "video_url": "https://xxx/xxx.mp4",
    "watermark_video_url": "https://xxx/xxx_watermark.mp4",
    "orig_prompt": "A kitten running under the moonlight",
    "usage": {
        "duration": 5,
        "size": "1280*720",
        "fps": 24,
        "video_count": 1,
        "audio": false,
        "SR": "720"
    }
}
```

#### 200 - Processing

```json
{
    "id": "kling-task-xxxxxxxxxxxx",
    "object": "video.generation",
    "model": "kling-v3-video-generation",
    "status": "processing",
    "progress": "50%",
    "created_at": 1769263230,
    "started_at": 1769263245
}
```

#### 200 - Queued

```json
{
    "id": "kling-task-xxxxxxxxxxxx",
    "object": "video.generation",
    "model": "kling-v3-video-generation",
    "status": "queued",
    "progress": "0%",
    "created_at": 1769263230
}
```

#### 200 - Task Failed (Failed)

```json
{
    "id": "kling-task-xxxxxxxxxxxx",
    "object": "video.generation",
    "model": "kling-v3-video-generation",
    "status": "failed",
    "created_at": 1769263230,
    "started_at": 1769263245,
    "completed_at": 1769263322,
    "code": "InvalidParameter",
    "message": "The parameter is invalid xxxxxx"
}
```

---

### Key Field Descriptions

| Field | Type | Description |
| :--- | :--- | :--- |
| **id** | string | Task ID. |
| **object** | string | Fixed as `video.generation`. |
| **model** | string | The model name used. |
| **status** | string | Task status:<br>`queued`: queued<br>`processing`: processing<br>`completed`: completed<br>`failed`: failed |
| **progress** | string | Generation progress percentage (e.g. `"50%"`, `"100%"`). |
| **created_at** | integer | Task creation time (Unix timestamp). |
| **started_at** | integer | Task processing start time (Unix timestamp). |
| **completed_at** | integer | Task completion time (Unix timestamp). |
| **video_url** | string | Video download link (returned only when `completed`). MP4 format (H.264 encoding); the link is valid for 30 days, please download promptly. |
| **watermark_video_url** | string | Download link for the watermarked video (returned only when `completed`). The link is valid for 30 days. |
| **orig_prompt** | string | The original input prompt. |
| **usage** | object | Output information statistics (returned only when `completed`). |
| **usage.duration** | integer | Total duration of the generated video (seconds), used for billing. |
| **usage.size** | string | Resolution of the generated video. Example: `"1280*720"`. |
| **usage.fps** | integer | Frame rate of the generated video. Example: `24`. |
| **usage.SR** | string | Resolution tier of the generated video. Example: `"720"`. |
| **usage.audio** | boolean | Whether it is a video with sound. |
| **usage.video_count** | integer | Number of generated videos, fixed at `1`. |
| **code** | string | Error code (returned only when `failed`). |
| **message** | string | Error details (returned only when `failed`). |

---

## 4. Task Status Transitions

```
queued → processing → completed / failed
```

- The initial query status is usually `queued` or `processing`.
- When the status becomes `completed`, the response will include `video_url`.
- If the status is `failed`, check the `code` and `message` error information and retry.
- The task ID is valid for **24 hours**; the result cannot be queried after expiration.

---

## 5. Applicable Models per Scenario (Quick Reference)

| Scenario | `kling-v3-video-generation` | `kling-v3-omni-video-generation` |
| :--- | :---: | :---: |
| Text-to-video | ✅ | ✅ |
| Text-to-video (smart storyboarding) | ✅ | ✅ |
| Image-to-video, first-frame based | ✅ | ✅ |
| Image-to-video, first/last-frame based | ✅ | ✅ |
| Reference-to-video | ❌ | ✅ |
| Video editing | ❌ | ✅ |
