Kling 3.0 Omni Video Generator
This skill enables the generation and manipulation of videos using the Kling 3.0 Omni model. It provides a structured workflow for constructing API requests based on user intent, ensuring compliance with the model's complex parameter constraints.
Reference Files
This skill includes the following reference files:
- -
references/api_reference.md — Complete official API parameter reference, including all fields, types, constraints, mutual exclusion rules (R1–R10), capability matrix, and invocation examples. Read this file before constructing any API call. - INLINECODE1 — Kling 3.0 Omni prompt writing principles, official formula, template syntax, and few-shot examples for all major scenarios.
- INLINECODE2 — Python utility class for JWT authentication, task creation, and polling.
Core Capabilities
- - Text-to-Video: Generate a video from a textual description.
- Image-to-Video: Animate a static image with a descriptive prompt.
- Video-to-Video (Editing): Modify an existing video based on a prompt (e.g., change subject, style).
- Video-to-Video (Reference): Use an existing video as a reference for camera movement and style.
- Multi-shot Generation: Create a video with multiple distinct scenes or shots.
- Audio Generation: Generate video with synchronized audio, including speech and sound effects.
Workflow: From User Intent to API Call
To correctly use the Kling API, you MUST follow this decision-making workflow to construct the API payload. The process is divided into two main stages: Prompt Design and Parameter Construction.
Stage 1: Prompt Design
Before constructing the API call, you must first design the prompt(s) based on the user's request. The quality of the prompt is the single most important factor for a good result.
- 1. Consult the Prompting Guide: Read
/home/ubuntu/skills/kling-video-generator/references/prompt_guide.md to understand the core principles, official formula, and few-shot examples for writing effective prompts.
- 2. Identify the Scenario: Determine which of the following scenarios the user is requesting:
- Single-shot video (from text, image, or video)
- Multi-shot video (storyboard with multiple scenes)
- 3. Write the Prompt(s):
- For
single-shot, write a single, detailed prompt following the guide's formula.
- For
multi-shot, write a separate prompt for each shot/scene.
-
Use Template Syntax: If the user provides reference images, elements, or videos, you MUST use the
<<<image_1>>>,
<<<element_1>>>,
<<<video_1>>> template syntax in the prompt to explicitly reference them. This is a core feature of the Omni model.
Stage 2: Parameter Construction
Once the prompt(s) are ready, construct the final API request payload by following this decision tree. This ensures all parameter constraints and interdependencies, discovered through extensive testing, are respected.
CODEBLOCK0
Key Parameter Rules (from testing)
This is not an exhaustive list, but a summary of the most critical, non-obvious rules that you MUST follow. For a complete guide, refer to the prompt_guide.md.
| Parameter | Rule |
|---|
| INLINECODE8 | MUST be explicit. Do not omit. Defaults to base but this is unreliable. Use base for editing, feature for reference. |
| INLINECODE12 |
Ignored in base mode. In
customize mode, it MUST equal the sum of
multi_prompt durations. |
|
sound |
Incompatible with video_list. Cannot be
on if a reference video is provided. |
|
shot_type |
MUST be customize for
multi_shot: true with the Omni model.
intelligence is not supported. |
|
multi_prompt |
index MUST start from 1. Total duration MUST match top-level
duration. Max 6 shots. |
|
aspect_ratio |
Required for feature mode. |
|
image_list | Max 7 images without video input,
max 4 images with video input. |
Execution
To execute a video generation task, use the provided Python script which handles authentication and polling.
- 1. Set Environment Variables: Ensure
KLING_ACCESS_KEY and KLING_SECRET_KEY are set.
- 2. Construct the Payload: Follow the workflow above to create the JSON payload for the API call.
- 3. Run the Script:
CODEBLOCK1
This structured approach ensures that all the nuances and constraints of the Kling 3.0 Omni API are handled correctly, leading to fewer errors and more predictable results.
Kling 3.0 Omni 视频生成器
该技能能够使用 Kling 3.0 Omni 模型生成和处理视频。它提供了一个结构化的工作流程,用于根据用户意图构建 API 请求,确保符合模型复杂的参数约束。
参考文件
该技能包含以下参考文件:
- - references/apireference.md — 完整的官方 API 参数参考,包括所有字段、类型、约束、互斥规则(R1–R10)、能力矩阵和调用示例。在构建任何 API 调用之前,请先阅读此文件。
- references/promptguide.md — Kling 3.0 Omni 提示词编写原则、官方公式、模板语法以及所有主要场景的少样本示例。
- scripts/kling_api.py — 用于 JWT 认证、任务创建和轮询的 Python 工具类。
核心能力
- - 文本转视频:根据文本描述生成视频。
- 图片转视频:通过描述性提示词将静态图片动画化。
- 视频转视频(编辑):根据提示词修改现有视频(例如,更改主体、风格)。
- 视频转视频(参考):使用现有视频作为镜头运动和风格的参考。
- 多镜头生成:创建包含多个不同场景或镜头的视频。
- 音频生成:生成带有同步音频的视频,包括语音和音效。
工作流程:从用户意图到 API 调用
为了正确使用 Kling API,您必须遵循此决策工作流程来构建 API 请求体。该过程分为两个主要阶段:提示词设计和参数构建。
阶段 1:提示词设计
在构建 API 调用之前,您必须首先根据用户的请求设计提示词。提示词的质量是获得良好结果的最重要因素。
- 1. 查阅提示词指南:阅读 /home/ubuntu/skills/kling-video-generator/references/prompt_guide.md,了解编写有效提示词的核心原则、官方公式和少样本示例。
- 2. 识别场景:确定用户请求的是以下哪种场景:
- 单镜头视频(来自文本、图片或视频)
- 多镜头视频(包含多个场景的分镜故事板)
- 3. 编写提示词:
- 对于
单镜头,按照指南的公式编写一个详细的提示词。
- 对于
多镜头,为每个镜头/场景编写单独的提示词。
-
使用模板语法:如果用户提供了参考图片、元素或视频,您必须在提示词中使用 <<
1>>>、<<1>>>、<<>> 模板语法来明确引用它们。这是 Omni 模型的核心功能。
阶段 2:参数构建
提示词准备就绪后,按照以下决策树构建最终的 API 请求体。这确保了通过广泛测试发现的所有参数约束和相互依赖关系都得到遵守。
mermaid
graph TD
A[开始] --> B{多镜头还是单镜头?};
B -- 多镜头 --> C[设置 multi_shot: true];
B -- 单镜头 --> D[设置 multi_shot: false];
C --> E{设置 shot_type: customize};
E --> F[从提示词构建 multi_prompt 数组];
F --> G[从 multi_prompt 计算总时长];
G --> H[设置顶层 duration];
H --> Z[最终请求体];
D --> I{是否提供了视频输入?};
I -- 是 --> J{编辑还是参考?};
I -- 否 --> K[文本/图片转视频路径];
J -- 编辑 --> L[设置 refer_type: base];
J -- 参考 --> M[设置 refer_type: feature];
L --> N[忽略 duration 参数];
M --> O[设置 aspect_ratio];
N --> P{音频处理};
O --> P;
K --> Q{音频处理};
P --> R{音频处理};
subgraph R [音频处理]
direction LR
R1{需要音频输出?} -- 是 --> R2[设置 sound: on];
R1 -- 否 --> R3[设置 sound: off];
R2 --> R4{是否存在视频输入?};
R4 -- 是 --> R5[错误:sound:on 与视频输入不兼容];
R4 -- 否 --> R6[OK];
end
Q --> Z;
R6 --> Z;
R3 --> Z;
R5 --> 停止([停止/错误]);
关键参数规则(来自测试)
这不是一个详尽的列表,而是您必须遵守的最关键、最不明显的规则的总结。完整指南请参考 prompt_guide.md。
| 参数 | 规则 |
|---|
| refertype | 必须明确指定。不能省略。默认为 base 但不可靠。编辑时使用 base,参考时使用 feature。 |
| duration |
在 base 模式下被忽略。在 customize 模式下,必须等于 multiprompt 时长的总和。 |
| sound | 与 video_list 不兼容。如果提供了参考视频,不能设置为 on。 |
| shottype | 对于 Omni 模型的 multishot: true,必须设置为 customize。不支持 intelligence。 |
| multi_prompt | index 必须从 1 开始。总时长必须与顶层 duration 匹配。最多 6 个镜头。 |
| aspect_ratio | 在 feature 模式下为必填项。 |
| image_list | 无视频输入时最多 7 张图片,有视频输入时最多 4 张图片。 |
执行
要执行视频生成任务,请使用提供的 Python 脚本,该脚本处理认证和轮询。
- 1. 设置环境变量:确保已设置 KLINGACCESSKEY 和 KLINGSECRETKEY。
- 2. 构建请求体:按照上述工作流程创建 API 调用的 JSON 请求体。
- 3. 运行脚本:
python
from kling_api import KlingAPI
# 从环境获取密钥
accesskey = os.environ.get(KLINGACCESS_KEY)
secretkey = os.environ.get(KLINGSECRET_KEY)
api = KlingAPI(accesskey, secretkey)
# 您构建的请求体
payload = {
model_name: kling-v3-omni,
# ... 根据工作流程的其他参数 ...
}
# 创建并轮询任务
taskresponse = api.createomnivideotask(payload)
if taskresponse and taskresponse.get(code) == 0:
taskid = taskresponse.get(data, {}).get(task_id)
print(f任务已创建:{task_id})
result = api.pollforcompletion(task_id)
if result:
print(最终视频 URL:, result.get(videos, [{}])[0].get(url))
这种结构化方法确保 Kling 3.0 Omni API 的所有细微差别和约束都得到正确处理,从而减少错误并获得更可预测的结果。