@runapi.ai/kling 0.2.8 → 0.2.10

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/dist/index.mjs CHANGED
@@ -2,9 +2,566 @@
2
2
  import { BaseClient } from "@runapi.ai/core";
3
3
 
4
4
  // src/resources/text-to-video.ts
5
- import { compactParams } from "@runapi.ai/core";
5
+ import { ValidationError, compactParams, validateParams } from "@runapi.ai/core";
6
6
  import { pollUntilComplete } from "@runapi.ai/core/internal";
7
+
8
+ // src/contract_gen.ts
9
+ var contract = {
10
+ "avatar": {
11
+ "models": [
12
+ "kling-ai-avatar-pro",
13
+ "kling-ai-avatar-standard",
14
+ "kling-ai-avatar-v1-pro",
15
+ "kling-v1-avatar-standard"
16
+ ],
17
+ "fields_by_model": {
18
+ "kling-ai-avatar-pro": {
19
+ "model": {
20
+ "required": true
21
+ },
22
+ "prompt": {
23
+ "required": true
24
+ },
25
+ "source_audio_url": {
26
+ "required": true
27
+ },
28
+ "source_image_url": {
29
+ "required": true
30
+ }
31
+ },
32
+ "kling-ai-avatar-standard": {
33
+ "model": {
34
+ "required": true
35
+ },
36
+ "prompt": {
37
+ "required": true
38
+ },
39
+ "source_audio_url": {
40
+ "required": true
41
+ },
42
+ "source_image_url": {
43
+ "required": true
44
+ }
45
+ },
46
+ "kling-ai-avatar-v1-pro": {
47
+ "model": {
48
+ "required": true
49
+ },
50
+ "prompt": {
51
+ "required": true
52
+ },
53
+ "source_audio_url": {
54
+ "required": true
55
+ },
56
+ "source_image_url": {
57
+ "required": true
58
+ }
59
+ },
60
+ "kling-v1-avatar-standard": {
61
+ "model": {
62
+ "required": true
63
+ },
64
+ "prompt": {
65
+ "required": true
66
+ },
67
+ "source_audio_url": {
68
+ "required": true
69
+ },
70
+ "source_image_url": {
71
+ "required": true
72
+ }
73
+ }
74
+ }
75
+ },
76
+ "image-to-video": {
77
+ "models": [
78
+ "kling-v2.1-master-image-to-video",
79
+ "kling-v2.1-pro",
80
+ "kling-v2.1-standard",
81
+ "kling-v2.5-turbo-image-to-video-pro",
82
+ "kling-v2.6",
83
+ "kling-v3-turbo-image-to-video"
84
+ ],
85
+ "fields_by_model": {
86
+ "kling-v2.1-master-image-to-video": {
87
+ "duration_seconds": {
88
+ "enum": [
89
+ 5,
90
+ 10
91
+ ],
92
+ "type": "integer"
93
+ },
94
+ "first_frame_image_url": {
95
+ "required": true
96
+ },
97
+ "model": {
98
+ "required": true
99
+ },
100
+ "prompt": {
101
+ "required": true
102
+ }
103
+ },
104
+ "kling-v2.1-pro": {
105
+ "duration_seconds": {
106
+ "enum": [
107
+ 5,
108
+ 10
109
+ ],
110
+ "type": "integer"
111
+ },
112
+ "first_frame_image_url": {
113
+ "required": true
114
+ },
115
+ "model": {
116
+ "required": true
117
+ },
118
+ "prompt": {
119
+ "required": true
120
+ }
121
+ },
122
+ "kling-v2.1-standard": {
123
+ "duration_seconds": {
124
+ "enum": [
125
+ 5,
126
+ 10
127
+ ],
128
+ "type": "integer"
129
+ },
130
+ "first_frame_image_url": {
131
+ "required": true
132
+ },
133
+ "model": {
134
+ "required": true
135
+ },
136
+ "prompt": {
137
+ "required": true
138
+ }
139
+ },
140
+ "kling-v2.5-turbo-image-to-video-pro": {
141
+ "duration_seconds": {
142
+ "enum": [
143
+ 5,
144
+ 10
145
+ ],
146
+ "type": "integer"
147
+ },
148
+ "first_frame_image_url": {
149
+ "required": true
150
+ },
151
+ "model": {
152
+ "required": true
153
+ },
154
+ "prompt": {
155
+ "required": true
156
+ }
157
+ },
158
+ "kling-v2.6": {
159
+ "aspect_ratio": {
160
+ "enum": [
161
+ "16:9",
162
+ "9:16",
163
+ "1:1"
164
+ ]
165
+ },
166
+ "duration_seconds": {
167
+ "enum": [
168
+ 5,
169
+ 10
170
+ ],
171
+ "type": "integer"
172
+ },
173
+ "first_frame_image_url": {
174
+ "required": true
175
+ },
176
+ "mode": {
177
+ "enum": [
178
+ "std",
179
+ "pro"
180
+ ]
181
+ },
182
+ "model": {
183
+ "required": true
184
+ },
185
+ "prompt": {
186
+ "required": true,
187
+ "min": 1,
188
+ "max": 2500,
189
+ "length": true
190
+ }
191
+ },
192
+ "kling-v3-turbo-image-to-video": {
193
+ "duration_seconds": {
194
+ "enum": [
195
+ 3,
196
+ 4,
197
+ 5,
198
+ 6,
199
+ 7,
200
+ 8,
201
+ 9,
202
+ 10,
203
+ 11,
204
+ 12,
205
+ 13,
206
+ 14,
207
+ 15
208
+ ],
209
+ "type": "integer"
210
+ },
211
+ "first_frame_image_url": {
212
+ "required": true
213
+ },
214
+ "model": {
215
+ "required": true
216
+ },
217
+ "output_resolution": {
218
+ "enum": [
219
+ "720p",
220
+ "1080p"
221
+ ]
222
+ },
223
+ "prompt": {
224
+ "required": true,
225
+ "min": 1,
226
+ "max": 2500,
227
+ "length": true
228
+ }
229
+ }
230
+ },
231
+ "rules": [
232
+ {
233
+ "when": {
234
+ "model": "kling-v2.1-master-image-to-video"
235
+ },
236
+ "forbidden": [
237
+ "output_resolution",
238
+ "mode",
239
+ "enable_sound"
240
+ ]
241
+ },
242
+ {
243
+ "when": {
244
+ "model": "kling-v2.1-pro"
245
+ },
246
+ "forbidden": [
247
+ "output_resolution",
248
+ "mode",
249
+ "enable_sound"
250
+ ]
251
+ },
252
+ {
253
+ "when": {
254
+ "model": "kling-v2.1-standard"
255
+ },
256
+ "forbidden": [
257
+ "output_resolution",
258
+ "mode",
259
+ "enable_sound"
260
+ ]
261
+ },
262
+ {
263
+ "when": {
264
+ "model": "kling-v2.5-turbo-image-to-video-pro"
265
+ },
266
+ "forbidden": [
267
+ "output_resolution",
268
+ "mode",
269
+ "enable_sound"
270
+ ]
271
+ },
272
+ {
273
+ "when": {
274
+ "model": "kling-v2.6"
275
+ },
276
+ "forbidden": [
277
+ "output_resolution",
278
+ "negative_prompt",
279
+ "cfg_scale"
280
+ ]
281
+ },
282
+ {
283
+ "when": {
284
+ "model": "kling-v3-turbo-image-to-video"
285
+ },
286
+ "forbidden": [
287
+ "mode",
288
+ "enable_sound",
289
+ "aspect_ratio",
290
+ "negative_prompt",
291
+ "cfg_scale",
292
+ "last_frame_image_url"
293
+ ]
294
+ }
295
+ ]
296
+ },
297
+ "motion-control": {
298
+ "models": [
299
+ "kling-3.0"
300
+ ],
301
+ "fields_by_model": {
302
+ "kling-3.0": {
303
+ "background_source": {
304
+ "enum": [
305
+ "video",
306
+ "image"
307
+ ]
308
+ },
309
+ "character_orientation": {
310
+ "enum": [
311
+ "video",
312
+ "image"
313
+ ]
314
+ },
315
+ "model": {
316
+ "required": true
317
+ },
318
+ "output_resolution": {
319
+ "enum": [
320
+ "720p",
321
+ "1080p"
322
+ ]
323
+ },
324
+ "reference_video_url": {
325
+ "required": true
326
+ },
327
+ "source_image_url": {
328
+ "required": true
329
+ }
330
+ }
331
+ }
332
+ },
333
+ "text-to-video": {
334
+ "models": [
335
+ "kling-3.0",
336
+ "kling-v2.1-master-text-to-video",
337
+ "kling-v2.5-turbo-text-to-video-pro",
338
+ "kling-v2.6",
339
+ "kling-v3-turbo-text-to-video"
340
+ ],
341
+ "fields_by_model": {
342
+ "kling-3.0": {
343
+ "aspect_ratio": {
344
+ "enum": [
345
+ "16:9",
346
+ "9:16",
347
+ "1:1"
348
+ ]
349
+ },
350
+ "duration_seconds": {
351
+ "enum": [
352
+ 3,
353
+ 4,
354
+ 5,
355
+ 6,
356
+ 7,
357
+ 8,
358
+ 9,
359
+ 10,
360
+ 11,
361
+ 12,
362
+ 13,
363
+ 14,
364
+ 15
365
+ ],
366
+ "type": "integer"
367
+ },
368
+ "model": {
369
+ "required": true
370
+ },
371
+ "output_resolution": {
372
+ "enum": [
373
+ "720p",
374
+ "1080p",
375
+ "4k"
376
+ ]
377
+ }
378
+ },
379
+ "kling-v2.1-master-text-to-video": {
380
+ "aspect_ratio": {
381
+ "enum": [
382
+ "16:9",
383
+ "9:16",
384
+ "1:1"
385
+ ]
386
+ },
387
+ "duration_seconds": {
388
+ "enum": [
389
+ 5,
390
+ 10
391
+ ],
392
+ "type": "integer"
393
+ },
394
+ "model": {
395
+ "required": true
396
+ }
397
+ },
398
+ "kling-v2.5-turbo-text-to-video-pro": {
399
+ "aspect_ratio": {
400
+ "enum": [
401
+ "16:9",
402
+ "9:16",
403
+ "1:1"
404
+ ]
405
+ },
406
+ "duration_seconds": {
407
+ "enum": [
408
+ 5,
409
+ 10
410
+ ],
411
+ "type": "integer"
412
+ },
413
+ "model": {
414
+ "required": true
415
+ }
416
+ },
417
+ "kling-v2.6": {
418
+ "aspect_ratio": {
419
+ "enum": [
420
+ "16:9",
421
+ "9:16",
422
+ "1:1"
423
+ ]
424
+ },
425
+ "duration_seconds": {
426
+ "enum": [
427
+ 5,
428
+ 10
429
+ ],
430
+ "type": "integer"
431
+ },
432
+ "mode": {
433
+ "enum": [
434
+ "std",
435
+ "pro"
436
+ ]
437
+ },
438
+ "model": {
439
+ "required": true
440
+ },
441
+ "prompt": {
442
+ "required": true,
443
+ "min": 1,
444
+ "max": 2500,
445
+ "length": true
446
+ }
447
+ },
448
+ "kling-v3-turbo-text-to-video": {
449
+ "aspect_ratio": {
450
+ "enum": [
451
+ "16:9",
452
+ "9:16",
453
+ "1:1"
454
+ ]
455
+ },
456
+ "duration_seconds": {
457
+ "enum": [
458
+ 3,
459
+ 4,
460
+ 5,
461
+ 6,
462
+ 7,
463
+ 8,
464
+ 9,
465
+ 10,
466
+ 11,
467
+ 12,
468
+ 13,
469
+ 14,
470
+ 15
471
+ ],
472
+ "type": "integer"
473
+ },
474
+ "model": {
475
+ "required": true
476
+ },
477
+ "output_resolution": {
478
+ "enum": [
479
+ "720p",
480
+ "1080p"
481
+ ]
482
+ },
483
+ "prompt": {
484
+ "required": true,
485
+ "min": 1,
486
+ "max": 2500,
487
+ "length": true
488
+ }
489
+ }
490
+ },
491
+ "rules": [
492
+ {
493
+ "when": {
494
+ "model": "kling-3.0"
495
+ },
496
+ "forbidden": [
497
+ "mode"
498
+ ]
499
+ },
500
+ {
501
+ "when": {
502
+ "model": "kling-v2.1-master-text-to-video"
503
+ },
504
+ "forbidden": [
505
+ "mode"
506
+ ]
507
+ },
508
+ {
509
+ "when": {
510
+ "model": "kling-v2.5-turbo-text-to-video-pro"
511
+ },
512
+ "forbidden": [
513
+ "mode"
514
+ ]
515
+ },
516
+ {
517
+ "when": {
518
+ "model": "kling-v2.6"
519
+ },
520
+ "forbidden": [
521
+ "output_resolution",
522
+ "negative_prompt",
523
+ "cfg_scale",
524
+ "multi_shots",
525
+ "multi_prompt",
526
+ "first_frame_image_url",
527
+ "last_frame_image_url",
528
+ "kling_elements"
529
+ ]
530
+ },
531
+ {
532
+ "when": {
533
+ "model": "kling-v3-turbo-text-to-video"
534
+ },
535
+ "forbidden": [
536
+ "mode",
537
+ "enable_sound",
538
+ "negative_prompt",
539
+ "cfg_scale",
540
+ "multi_shots",
541
+ "multi_prompt",
542
+ "first_frame_image_url",
543
+ "last_frame_image_url",
544
+ "kling_elements"
545
+ ]
546
+ }
547
+ ]
548
+ }
549
+ };
550
+
551
+ // src/resources/text-to-video.ts
7
552
  var ENDPOINT = "/api/v1/kling/text_to_video";
553
+ var V26_MODEL = "kling-v2.6";
554
+ var V3_TURBO_MODEL = "kling-v3-turbo-text-to-video";
555
+ var V3_TURBO_UNSUPPORTED_FIELDS = [
556
+ "enable_sound",
557
+ "negative_prompt",
558
+ "cfg_scale",
559
+ "multi_shots",
560
+ "multi_prompt",
561
+ "first_frame_image_url",
562
+ "last_frame_image_url",
563
+ "kling_elements"
564
+ ];
8
565
  var TextToVideo = class {
9
566
  constructor(http) {
10
567
  this.http = http;
@@ -31,8 +588,12 @@ var TextToVideo = class {
31
588
  * @returns The task creation result with id.
32
589
  */
33
590
  async create(params, options) {
591
+ const body = compactParams(params);
592
+ rejectUnsupportedV3TurboFields(body);
593
+ validateParams(contract["text-to-video"], body);
594
+ validateV26Params(body);
34
595
  return this.http.request("POST", ENDPOINT, {
35
- body: compactParams(params),
596
+ body,
36
597
  ...options
37
598
  });
38
599
  }
@@ -48,11 +609,47 @@ var TextToVideo = class {
48
609
  });
49
610
  }
50
611
  };
612
+ function validateV26Params(body) {
613
+ if (body.model !== V26_MODEL) return;
614
+ if (body.enable_sound === true && body.mode !== "pro") {
615
+ throw new ValidationError(`enable_sound requires mode pro for ${V26_MODEL}`);
616
+ }
617
+ }
618
+ function rejectUnsupportedV3TurboFields(body) {
619
+ if (body.model !== V3_TURBO_MODEL) return;
620
+ const field = V3_TURBO_UNSUPPORTED_FIELDS.find((candidate) => fieldPresent(body, candidate));
621
+ if (field) {
622
+ throw new ValidationError(`${field} is not supported by ${V3_TURBO_MODEL}`);
623
+ }
624
+ }
625
+ function fieldPresent(params, field) {
626
+ if (!(field in params)) return false;
627
+ const value = params[field];
628
+ if (value === false) return true;
629
+ if (Array.isArray(value)) return value.some((item) => presentValue(item));
630
+ return presentValue(value);
631
+ }
632
+ function presentValue(value) {
633
+ if (value === null || value === void 0 || value === false) return false;
634
+ if (value === true) return true;
635
+ if (typeof value === "string") return value.trim() !== "";
636
+ if (Array.isArray(value)) return value.length > 0;
637
+ if (typeof value === "object") return Object.keys(value).length > 0;
638
+ return true;
639
+ }
51
640
 
52
641
  // src/resources/image-to-video.ts
53
- import { compactParams as compactParams2 } from "@runapi.ai/core";
642
+ import { ValidationError as ValidationError2, compactParams as compactParams2, validateParams as validateParams2 } from "@runapi.ai/core";
54
643
  import { pollUntilComplete as pollUntilComplete2 } from "@runapi.ai/core/internal";
55
644
  var ENDPOINT2 = "/api/v1/kling/image_to_video";
645
+ var V26_MODEL2 = "kling-v2.6";
646
+ var V3_TURBO_MODEL2 = "kling-v3-turbo-image-to-video";
647
+ var V3_TURBO_UNSUPPORTED_FIELDS2 = [
648
+ "aspect_ratio",
649
+ "negative_prompt",
650
+ "cfg_scale",
651
+ "last_frame_image_url"
652
+ ];
56
653
  var ImageToVideo = class {
57
654
  constructor(http) {
58
655
  this.http = http;
@@ -79,8 +676,12 @@ var ImageToVideo = class {
79
676
  * @returns The task creation result with id.
80
677
  */
81
678
  async create(params, options) {
679
+ const body = compactParams2(params);
680
+ rejectUnsupportedV3TurboFields2(body);
681
+ validateParams2(contract["image-to-video"], body);
682
+ validateV26Params2(body);
82
683
  return this.http.request("POST", ENDPOINT2, {
83
- body: compactParams2(params),
684
+ body,
84
685
  ...options
85
686
  });
86
687
  }
@@ -96,9 +697,44 @@ var ImageToVideo = class {
96
697
  });
97
698
  }
98
699
  };
700
+ function validateV26Params2(body) {
701
+ if (body.model !== V26_MODEL2) return;
702
+ if (body.enable_sound === true && body.mode !== "pro") {
703
+ throw new ValidationError2(`enable_sound requires mode pro for ${V26_MODEL2}`);
704
+ }
705
+ if (!fieldPresent2(body, "last_frame_image_url")) return;
706
+ if (body.mode !== "pro") {
707
+ throw new ValidationError2(`last_frame_image_url requires mode pro for ${V26_MODEL2}`);
708
+ }
709
+ if (body.duration_seconds !== void 0 && body.duration_seconds !== 5) {
710
+ throw new ValidationError2(`last_frame_image_url requires duration_seconds 5 for ${V26_MODEL2}`);
711
+ }
712
+ }
713
+ function rejectUnsupportedV3TurboFields2(body) {
714
+ if (body.model !== V3_TURBO_MODEL2) return;
715
+ const field = V3_TURBO_UNSUPPORTED_FIELDS2.find((candidate) => fieldPresent2(body, candidate));
716
+ if (field) {
717
+ throw new ValidationError2(`${field} is not supported by ${V3_TURBO_MODEL2}`);
718
+ }
719
+ }
720
+ function fieldPresent2(params, field) {
721
+ if (!(field in params)) return false;
722
+ const value = params[field];
723
+ if (value === false) return true;
724
+ if (Array.isArray(value)) return value.some((item) => presentValue2(item));
725
+ return presentValue2(value);
726
+ }
727
+ function presentValue2(value) {
728
+ if (value === null || value === void 0 || value === false) return false;
729
+ if (value === true) return true;
730
+ if (typeof value === "string") return value.trim() !== "";
731
+ if (Array.isArray(value)) return value.length > 0;
732
+ if (typeof value === "object") return Object.keys(value).length > 0;
733
+ return true;
734
+ }
99
735
 
100
736
  // src/resources/ai-avatar.ts
101
- import { compactParams as compactParams3 } from "@runapi.ai/core";
737
+ import { compactParams as compactParams3, validateParams as validateParams3 } from "@runapi.ai/core";
102
738
  import { pollUntilComplete as pollUntilComplete3 } from "@runapi.ai/core/internal";
103
739
  var ENDPOINT3 = "/api/v1/kling/ai_avatar";
104
740
  var AiAvatar = class {
@@ -127,8 +763,10 @@ var AiAvatar = class {
127
763
  * @returns The task creation result with id.
128
764
  */
129
765
  async create(params, options) {
766
+ const body = compactParams3(params);
767
+ validateParams3(contract["avatar"], body);
130
768
  return this.http.request("POST", ENDPOINT3, {
131
- body: compactParams3(params),
769
+ body,
132
770
  ...options
133
771
  });
134
772
  }
@@ -146,7 +784,7 @@ var AiAvatar = class {
146
784
  };
147
785
 
148
786
  // src/resources/motion-control.ts
149
- import { compactParams as compactParams4 } from "@runapi.ai/core";
787
+ import { compactParams as compactParams4, validateParams as validateParams4 } from "@runapi.ai/core";
150
788
  import { pollUntilComplete as pollUntilComplete4 } from "@runapi.ai/core/internal";
151
789
  var ENDPOINT4 = "/api/v1/kling/motion_control";
152
790
  var MotionControl = class {
@@ -175,8 +813,10 @@ var MotionControl = class {
175
813
  * @returns The task creation result with id.
176
814
  */
177
815
  async create(params, options) {
816
+ const body = compactParams4(params);
817
+ validateParams4(contract["motion-control"], body);
178
818
  return this.http.request("POST", ENDPOINT4, {
179
- body: compactParams4(params),
819
+ body,
180
820
  ...options
181
821
  });
182
822
  }
@@ -218,7 +858,7 @@ import {
218
858
  AuthenticationError,
219
859
  InsufficientCreditsError,
220
860
  NotFoundError,
221
- ValidationError,
861
+ ValidationError as ValidationError3,
222
862
  RateLimitError,
223
863
  ServiceUnavailableError,
224
864
  NetworkError,
@@ -238,6 +878,6 @@ export {
238
878
  TaskFailedError,
239
879
  TaskTimeoutError,
240
880
  TimeoutError,
241
- ValidationError
881
+ ValidationError3 as ValidationError
242
882
  };
243
883
  //# sourceMappingURL=index.mjs.map