klingai-video-extension
Automates the process of extending existing videos by appending new footage through the Kling AI API.
Install
mkdir -p .claude/skills/klingai-video-extension && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/8791" && unzip -o skill.zip -d .claude/skills/klingai-video-extension && rm skill.zipInstalls to .claude/skills/klingai-video-extension
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Extend video duration using Kling AI continuation. Use when creatingKey capabilities
- →Extend existing Kling AI video clips
- →Chain multiple video extensions together
- →Specify motion/scene descriptions for extensions
- →Set duration and mode for extended segments
- →Poll for completion of video extension tasks
How it works
The skill sends a POST request to the Kling AI video-extend endpoint with the task ID of a completed video and new parameters. It then polls the API until the extension task succeeds, providing the URL of the new video.
Inputs & outputs
When to use klingai-video-extension
- →Extend video duration from existing clips
- →Build seamless video sequences
- →Automate motion generation for longer segments
- →Integrate Kling AI video continuation into workflows
About this skill
Kling AI Video Extension
Overview
Extend an existing video by appending additional seconds. The extension endpoint takes the task_id of a completed video and generates a seamless continuation.
Endpoint: POST https://api.klingai.com/v1/videos/video-extend
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
task_id | string | Yes | Task ID of the completed source video |
prompt | string | No | Motion/scene description for extension |
duration | string | No | Extension length: "5" (default) |
mode | string | No | "standard" or "professional" |
model_name | string | No | Default: "kling-v2-master" |
callback_url | string | No | Webhook for completion |
Basic Extension
import jwt, time, os, requests
BASE = "https://api.klingai.com/v1"
def get_headers():
ak, sk = os.environ["KLING_ACCESS_KEY"], os.environ["KLING_SECRET_KEY"]
token = jwt.encode(
{"iss": ak, "exp": int(time.time()) + 1800, "nbf": int(time.time()) - 5},
sk, algorithm="HS256", headers={"alg": "HS256", "typ": "JWT"}
)
return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
# Step 1: Generate the initial 5s video
initial = requests.post(f"{BASE}/videos/text2video", headers=get_headers(), json={
"model_name": "kling-v2-master",
"prompt": "A rocket launching from a desert landscape, cinematic",
"duration": "5",
"mode": "standard",
}).json()
initial_task_id = initial["data"]["task_id"]
# Wait for completion...
# (poll until task_status == "succeed")
# Step 2: Extend by 5 more seconds
extension = requests.post(f"{BASE}/videos/video-extend", headers=get_headers(), json={
"task_id": initial_task_id,
"prompt": "The rocket ascends through clouds into the stratosphere",
"duration": "5",
"mode": "standard",
}).json()
ext_task_id = extension["data"]["task_id"]
# Step 3: Poll extension task
while True:
time.sleep(15)
result = requests.get(
f"{BASE}/videos/video-extend/{ext_task_id}", headers=get_headers()
).json()
if result["data"]["task_status"] == "succeed":
extended_url = result["data"]["task_result"]["videos"][0]["url"]
print(f"Extended video: {extended_url}")
break
elif result["data"]["task_status"] == "failed":
print(f"Failed: {result['data']['task_status_msg']}")
break
Chain Multiple Extensions
def chain_extensions(initial_task_id: str, prompts: list[str],
duration: str = "5", mode: str = "standard") -> list[str]:
"""Chain multiple extensions to build a longer video."""
current_task_id = initial_task_id
video_urls = []
for i, prompt in enumerate(prompts):
print(f"Extension {i + 1}/{len(prompts)}: submitting...")
# Submit extension
r = requests.post(f"{BASE}/videos/video-extend", headers=get_headers(), json={
"task_id": current_task_id,
"prompt": prompt,
"duration": duration,
"mode": mode,
}).json()
ext_task_id = r["data"]["task_id"]
# Poll for completion
while True:
time.sleep(15)
result = requests.get(
f"{BASE}/videos/video-extend/{ext_task_id}", headers=get_headers()
).json()
status = result["data"]["task_status"]
if status == "succeed":
url = result["data"]["task_result"]["videos"][0]["url"]
video_urls.append(url)
current_task_id = ext_task_id # next extension chains from this
print(f"Extension {i + 1} complete: {url}")
break
elif status == "failed":
raise RuntimeError(f"Extension {i + 1} failed: {result['data']['task_status_msg']}")
return video_urls
Usage: Build a 20-Second Video
# Generate initial 5s
initial_r = requests.post(f"{BASE}/videos/text2video", headers=get_headers(), json={
"model_name": "kling-v2-master",
"prompt": "Morning sunrise over a mountain lake, mist rising",
"duration": "5",
"mode": "standard",
}).json()
initial_id = initial_r["data"]["task_id"]
# ... poll until complete ...
# Chain 3 more extensions = 5 + 5 + 5 + 5 = 20 seconds total
extensions = chain_extensions(initial_id, [
"Sun rises higher, birds begin flying across the lake",
"A deer approaches the water's edge to drink",
"Wide shot pulling back to reveal the full mountain range",
])
Cost
Each extension costs the same as a new generation:
| Extension Duration | Standard | Professional |
|---|---|---|
| 5 seconds | 10 credits | 35 credits |
A 20-second video (initial + 3 extensions) costs 40 credits in standard mode.
Error Handling
| Error | Cause | Fix |
|---|---|---|
Invalid task_id | Source task doesn't exist | Verify task_id is from a completed generation |
| Source not complete | Extending a task still processing | Wait for source task to reach succeed status |
| Extension failed | Prompt conflict with source | Align extension prompt with original scene |
Resources
When not to use it
- →When video continuation is not required
- →When the initial video task has not yet succeeded
Limitations
- →Each extension costs credits, similar to a new generation
- →The source task ID must be from a completed video generation
- →Extension prompts should align with the original scene to avoid failure
How it compares
This skill programmatically extends video duration by chaining API calls, which automates the process of creating longer videos from shorter clips compared to manual generation.
Compared to similar skills
klingai-video-extension side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| klingai-video-extension (this skill) | 0 | 27d | Caution | Intermediate |
| motion-canvas | 58 | 6mo | Review | Advanced |
| jianying-editor | 38 | 2mo | Review | Advanced |
| manim | 29 | 6mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by jeremylongshore
View all by jeremylongshore →You might also like
motion-canvas
davila7
Complete production-ready guide for Motion Canvas with ESM/CommonJS workarounds, full setup templates, and troubleshooting for programmatic video creation using TypeScript
jianying-editor
luoluoluo22
剪映 (JianYing) AI自动化剪辑的高级封装 API (JyWrapper)。提供开箱即用的 Python 接口,支持录屏、素材导入、字幕生成、Web 动效合成及项目导出。
manim
davila7
Comprehensive guide for Manim Community - Python framework for creating mathematical animations and educational videos with programmatic control
vectcut-api
sun-guannan
VectCutAPI is a powerful cloud-based video editing API tool that provides programmatic control over CapCut/JianYing (剪映) for professional video editing. Use this skill when users need to: (1) Create video draft projects programmatically, (2) Add video/audio/image materials with precise control, (3) Add text, subtitles, and captions, (4) Apply effects, transitions, and animations, (5) Add keyframe animations, (6) Process videos in batch, (7) Generate AI-powered videos, (8) Integrate with n8n workflows, (9) Build MCP video editing agents. The API supports HTTP REST and MCP protocols, works with both CapCut (international) and JianYing (China), and provides web preview without downloading.
remotion
davila7
Best practices and comprehensive guide for Remotion - programmatic video creation in React with animations, compositions, and media handling
heygen-best-practices
davila7
Best practices for HeyGen - AI avatar video creation API