@runapi.ai/kling 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +43 -0
- package/dist/index.d.mts +169 -0
- package/dist/index.d.ts +169 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +171 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
- package/skills/kling/README.md +54 -0
- package/skills/kling/SKILL.md +248 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kling
|
|
3
|
+
description: Generate video (Kling 3.0 single/multi-shot, v2.5 Turbo text/image-to-video, AI avatars, motion-controlled video) through RunAPI.ai using the @runapi.ai/kling Node/TypeScript SDK. Use when the user asks to add Kling video generation, AI avatar talking heads, or motion-transfer video, or writes against @runapi.ai/kling. Triggers on "kling", "AI avatar", "motion control video", "可灵", "数字人", "@runapi.ai/kling".
|
|
4
|
+
documentation: https://runapi.ai/models/kling
|
|
5
|
+
provider_page: https://runapi.ai/providers/kuaishou
|
|
6
|
+
catalog: https://runapi.ai/models
|
|
7
|
+
---
|
|
8
|
+
# @runapi.ai/kling — RunAPI.ai Kling video generation
|
|
9
|
+
|
|
10
|
+
Build Node / TypeScript integrations that generate Kling video, talking-head avatars, and motion-transfer clips through RunAPI.ai.
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
Requires **Node 18+** (global `fetch`).
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @runapi.ai/kling
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Set your API key in the environment:
|
|
21
|
+
|
|
22
|
+
```dotenv
|
|
23
|
+
# .env
|
|
24
|
+
RUNAPI_API_KEY=runapi_xxx # get one at https://runapi.ai/settings/api_keys
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { KlingClient } from '@runapi.ai/kling';
|
|
29
|
+
|
|
30
|
+
// The SDK reads RUNAPI_API_KEY from the environment automatically.
|
|
31
|
+
const client = new KlingClient();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Pass `{ apiKey }` explicitly if you manage secrets differently. `baseUrl` defaults to `https://runapi.ai`; override only for local development.
|
|
35
|
+
|
|
36
|
+
## Core recipe — text to video
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const result = await client.textToVideo.run({
|
|
40
|
+
model: 'kling-3.0',
|
|
41
|
+
prompt: 'A cat walking through a sunlit garden',
|
|
42
|
+
aspect_ratio: '16:9',
|
|
43
|
+
duration: '5',
|
|
44
|
+
mode: 'pro',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const url = result.videos[0].url;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`run()` creates the task, auto-polls, and resolves only when the task completes — `videos[0].url` is guaranteed on the resolved value. On failure it throws `TaskFailedError`; on polling timeout it throws `TaskTimeoutError`. Use `run()` for scripts and short-lived processes. For request handlers, split it:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const { id } = await client.textToVideo.create({ model: 'kling-3.0', prompt: '...' });
|
|
54
|
+
// return 202 immediately; fetch later:
|
|
55
|
+
const status = await client.textToVideo.get(id);
|
|
56
|
+
if (status.status === 'completed') { /* ... */ }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Do not hold a web worker open waiting on `run()`. Split + webhook is the production pattern.
|
|
60
|
+
|
|
61
|
+
`run()` polls every 2 s for up to 15 min by default. Tune when needed:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
await client.textToVideo.run(params, { maxWaitMs: 30 * 60_000, pollIntervalMs: 5_000 });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
If `TaskTimeoutError` fires, the task is still running server-side — resume with `textToVideo.get(id)` or finish via webhook.
|
|
68
|
+
|
|
69
|
+
## Image to video and multi-shot
|
|
70
|
+
|
|
71
|
+
Attach `image_urls` to animate a still frame. For multi-scene output, use `multi_shots: true` with per-shot prompts:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
// Image to video
|
|
75
|
+
await client.textToVideo.run({
|
|
76
|
+
model: 'kling-3.0',
|
|
77
|
+
prompt: 'The dog starts running',
|
|
78
|
+
image_urls: ['https://cdn.example.com/dog.jpg'],
|
|
79
|
+
aspect_ratio: '16:9',
|
|
80
|
+
sound: true,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Multi-shot (audio is always on for multi-shot)
|
|
84
|
+
await client.textToVideo.run({
|
|
85
|
+
model: 'kling-3.0',
|
|
86
|
+
multi_shots: true,
|
|
87
|
+
sound: true,
|
|
88
|
+
aspect_ratio: '16:9',
|
|
89
|
+
multi_prompt: [
|
|
90
|
+
{ prompt: 'Wide shot of a waterfall', duration: 4 },
|
|
91
|
+
{ prompt: 'Camera pans to a rainbow above', duration: 6 },
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## v2.5 Turbo
|
|
97
|
+
|
|
98
|
+
Use the canonical text-to-video and image-to-video resources for the faster v2.5 Turbo variants:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// Text-to-video
|
|
102
|
+
await client.textToVideo.run({
|
|
103
|
+
model: 'kling-v2.5-turbo-text-to-video-pro',
|
|
104
|
+
prompt: 'A neon-lit alley at night, rain falling',
|
|
105
|
+
aspect_ratio: '9:16',
|
|
106
|
+
duration: '5',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Image-to-video
|
|
110
|
+
await client.imageToVideo.run({
|
|
111
|
+
model: 'kling-v2.5-turbo-image-to-video-pro',
|
|
112
|
+
image_url: 'https://cdn.example.com/frame.jpg',
|
|
113
|
+
prompt: 'The character walks forward slowly',
|
|
114
|
+
duration: '10',
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## AI avatars — talking-head video
|
|
119
|
+
|
|
120
|
+
Drive a portrait with an audio track:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const avatar = await client.aiAvatar.run({
|
|
124
|
+
model: 'kling-ai-avatar-pro',
|
|
125
|
+
image_url: 'https://cdn.example.com/headshot.jpg',
|
|
126
|
+
audio_url: 'https://cdn.example.com/voiceover.mp3',
|
|
127
|
+
prompt: 'Warm lighting, relaxed posture',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
console.log(avatar.videos[0].url);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Motion controls — transfer motion onto an image subject
|
|
134
|
+
|
|
135
|
+
Pass one or more driving videos plus one or more input images:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
await client.motionControl.run({
|
|
139
|
+
model: 'kling-3.0',
|
|
140
|
+
input_urls: ['https://cdn.example.com/person.jpg'],
|
|
141
|
+
video_urls: ['https://cdn.example.com/dance.mp4'],
|
|
142
|
+
prompt: 'Match the dance motion exactly',
|
|
143
|
+
mode: '1080p',
|
|
144
|
+
character_orientation: 'image',
|
|
145
|
+
background_source: 'input_image',
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Models
|
|
150
|
+
|
|
151
|
+
| Resource | `model` values |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `textToVideo` | `kling-3.0`, `kling-v2.5-turbo-text-to-video-pro` |
|
|
154
|
+
| `imageToVideo` | `kling-v2.5-turbo-image-to-video-pro` |
|
|
155
|
+
| `aiAvatar` | `kling-ai-avatar-pro`, `kling-ai-avatar-standard` |
|
|
156
|
+
| `motionControl` | `kling-3.0` |
|
|
157
|
+
|
|
158
|
+
Exact credit costs per model are shown at https://runapi.ai/pricing and in the dashboard — do not hardcode prices in application code.
|
|
159
|
+
|
|
160
|
+
## Callbacks (webhooks)
|
|
161
|
+
|
|
162
|
+
Pass `callback_url` on `create()` (or any `run()` call) and RunAPI will POST the final payload to you:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
await client.textToVideo.create({
|
|
166
|
+
model: 'kling-3.0',
|
|
167
|
+
prompt: '...',
|
|
168
|
+
callback_url: 'https://your.app/webhooks/runapi/kling',
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Payload shape:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
{ id: string; status: 'completed' | 'failed'; videos?: { url: string }[]; error?: string }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Always verify the signature before trusting the body.** RunAPI signs every callback with your account's Callback Secret (rotate at `/accounts/callback_secret`). Headers:
|
|
179
|
+
|
|
180
|
+
- `X-Callback-Id` — UUID, store to make handler idempotent
|
|
181
|
+
- `X-Callback-Timestamp` — unix seconds, reject if `|now - ts| > 300`
|
|
182
|
+
- `X-Callback-Signature` — base64 HMAC-SHA256 over `` `${id}.${ts}.${rawBody}` `` using the base64-decoded secret
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import crypto from 'node:crypto';
|
|
186
|
+
|
|
187
|
+
function verify(raw: string, id: string, ts: string, sig: string, secret: string) {
|
|
188
|
+
const key = Buffer.from(secret, 'base64');
|
|
189
|
+
const mac = crypto.createHmac('sha256', key)
|
|
190
|
+
.update(`${id}.${ts}.${raw}`)
|
|
191
|
+
.digest('base64');
|
|
192
|
+
return crypto.timingSafeEqual(Buffer.from(mac), Buffer.from(sig));
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Reply `2xx` within 10s; any non-2xx triggers retries.
|
|
197
|
+
|
|
198
|
+
## Errors
|
|
199
|
+
|
|
200
|
+
All errors are re-exported from `@runapi.ai/core`. Always `instanceof` — never string-match messages.
|
|
201
|
+
|
|
202
|
+
| Error | Status | Action |
|
|
203
|
+
|---|---|---|
|
|
204
|
+
| `AuthenticationError` | 401 | abort; surface "reconnect your API key" |
|
|
205
|
+
| `InsufficientCreditsError` | 402 | prompt user to top up at runapi.ai/billing |
|
|
206
|
+
| `ValidationError` | 400 / 422 | fix params; do not retry |
|
|
207
|
+
| `RateLimitError` | 429 | sleep `err.retryAfterMs`, then retry |
|
|
208
|
+
| `ServiceUnavailableError` | 503 / 455 | retry with backoff; transient service issue |
|
|
209
|
+
| `TaskFailedError` | — | show `err.details` to user; do not auto-retry |
|
|
210
|
+
| `TaskTimeoutError` | — | re-poll with `<resource>.get(id)` |
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
import { InsufficientCreditsError, TaskFailedError } from '@runapi.ai/kling';
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
await client.textToVideo.run({ model: 'kling-3.0', prompt: '...' });
|
|
217
|
+
} catch (err) {
|
|
218
|
+
if (err instanceof InsufficientCreditsError) { /* surface top-up CTA */ }
|
|
219
|
+
else if (err instanceof TaskFailedError) { /* show err.details */ }
|
|
220
|
+
else throw err;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Gotchas
|
|
225
|
+
|
|
226
|
+
- `model` is required on every call across every resource.
|
|
227
|
+
- Multi-shot mode requires `multi_shots: true` **and** `sound: true` — audio cannot be disabled.
|
|
228
|
+
- `image_urls` accepts at most 1 image in multi-shot mode.
|
|
229
|
+
- Motion controls expect both `input_urls` (images) and `video_urls` (driving motion); each is an array.
|
|
230
|
+
- `duration` is a string (`'3'` to `'15'`), not a number — matching the wire format.
|
|
231
|
+
- `callback_url` must be reachable from the public internet. `localhost` / `127.0.0.1` URLs will never fire — use a tunnel (cloudflared, ngrok, tailscale funnel) when developing locally.
|
|
232
|
+
|
|
233
|
+
## Dig deeper
|
|
234
|
+
|
|
235
|
+
Package README (full API surface, all params): `node_modules/@runapi.ai/kling/README.md`. Types: `@runapi.ai/kling/dist/types.d.ts`. Product docs: https://runapi.ai/docs.
|
|
236
|
+
|
|
237
|
+
## RunAPI public routing
|
|
238
|
+
|
|
239
|
+
kling ai api public links use the API-379 catalog route map. The main kling ai api page is https://runapi.ai/models/kling. SDK docs live at https://runapi.ai/docs#sdk-kling and product docs live at https://runapi.ai/docs#kling.
|
|
240
|
+
|
|
241
|
+
Pricing, rate limits, and commercial usage for kling ai api should point to the most specific variant page:
|
|
242
|
+
- [Kling 3.0](https://runapi.ai/models/kling/3.0)
|
|
243
|
+
- [AI avatar pro](https://runapi.ai/models/kling/ai-avatar-pro)
|
|
244
|
+
- [AI avatar standard](https://runapi.ai/models/kling/ai-avatar-standard)
|
|
245
|
+
- [V2.5 turbo text to video pro](https://runapi.ai/models/kling/v2.5-turbo-text-to-video-pro)
|
|
246
|
+
- [V2.5 turbo image to video pro](https://runapi.ai/models/kling/v2.5-turbo-image-to-video-pro)
|
|
247
|
+
|
|
248
|
+
Compare Kling with other Kuaishou models at https://runapi.ai/providers/kuaishou. Browse every RunAPI model and skill at https://runapi.ai/models. SDK repository: https://github.com/runapi-ai/kling-sdk. Skill repository: https://github.com/runapi-ai/kling.
|