@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.js CHANGED
@@ -41,7 +41,564 @@ var import_core5 = require("@runapi.ai/core");
41
41
  // src/resources/text-to-video.ts
42
42
  var import_core = require("@runapi.ai/core");
43
43
  var import_internal = require("@runapi.ai/core/internal");
44
+
45
+ // src/contract_gen.ts
46
+ var contract = {
47
+ "avatar": {
48
+ "models": [
49
+ "kling-ai-avatar-pro",
50
+ "kling-ai-avatar-standard",
51
+ "kling-ai-avatar-v1-pro",
52
+ "kling-v1-avatar-standard"
53
+ ],
54
+ "fields_by_model": {
55
+ "kling-ai-avatar-pro": {
56
+ "model": {
57
+ "required": true
58
+ },
59
+ "prompt": {
60
+ "required": true
61
+ },
62
+ "source_audio_url": {
63
+ "required": true
64
+ },
65
+ "source_image_url": {
66
+ "required": true
67
+ }
68
+ },
69
+ "kling-ai-avatar-standard": {
70
+ "model": {
71
+ "required": true
72
+ },
73
+ "prompt": {
74
+ "required": true
75
+ },
76
+ "source_audio_url": {
77
+ "required": true
78
+ },
79
+ "source_image_url": {
80
+ "required": true
81
+ }
82
+ },
83
+ "kling-ai-avatar-v1-pro": {
84
+ "model": {
85
+ "required": true
86
+ },
87
+ "prompt": {
88
+ "required": true
89
+ },
90
+ "source_audio_url": {
91
+ "required": true
92
+ },
93
+ "source_image_url": {
94
+ "required": true
95
+ }
96
+ },
97
+ "kling-v1-avatar-standard": {
98
+ "model": {
99
+ "required": true
100
+ },
101
+ "prompt": {
102
+ "required": true
103
+ },
104
+ "source_audio_url": {
105
+ "required": true
106
+ },
107
+ "source_image_url": {
108
+ "required": true
109
+ }
110
+ }
111
+ }
112
+ },
113
+ "image-to-video": {
114
+ "models": [
115
+ "kling-v2.1-master-image-to-video",
116
+ "kling-v2.1-pro",
117
+ "kling-v2.1-standard",
118
+ "kling-v2.5-turbo-image-to-video-pro",
119
+ "kling-v2.6",
120
+ "kling-v3-turbo-image-to-video"
121
+ ],
122
+ "fields_by_model": {
123
+ "kling-v2.1-master-image-to-video": {
124
+ "duration_seconds": {
125
+ "enum": [
126
+ 5,
127
+ 10
128
+ ],
129
+ "type": "integer"
130
+ },
131
+ "first_frame_image_url": {
132
+ "required": true
133
+ },
134
+ "model": {
135
+ "required": true
136
+ },
137
+ "prompt": {
138
+ "required": true
139
+ }
140
+ },
141
+ "kling-v2.1-pro": {
142
+ "duration_seconds": {
143
+ "enum": [
144
+ 5,
145
+ 10
146
+ ],
147
+ "type": "integer"
148
+ },
149
+ "first_frame_image_url": {
150
+ "required": true
151
+ },
152
+ "model": {
153
+ "required": true
154
+ },
155
+ "prompt": {
156
+ "required": true
157
+ }
158
+ },
159
+ "kling-v2.1-standard": {
160
+ "duration_seconds": {
161
+ "enum": [
162
+ 5,
163
+ 10
164
+ ],
165
+ "type": "integer"
166
+ },
167
+ "first_frame_image_url": {
168
+ "required": true
169
+ },
170
+ "model": {
171
+ "required": true
172
+ },
173
+ "prompt": {
174
+ "required": true
175
+ }
176
+ },
177
+ "kling-v2.5-turbo-image-to-video-pro": {
178
+ "duration_seconds": {
179
+ "enum": [
180
+ 5,
181
+ 10
182
+ ],
183
+ "type": "integer"
184
+ },
185
+ "first_frame_image_url": {
186
+ "required": true
187
+ },
188
+ "model": {
189
+ "required": true
190
+ },
191
+ "prompt": {
192
+ "required": true
193
+ }
194
+ },
195
+ "kling-v2.6": {
196
+ "aspect_ratio": {
197
+ "enum": [
198
+ "16:9",
199
+ "9:16",
200
+ "1:1"
201
+ ]
202
+ },
203
+ "duration_seconds": {
204
+ "enum": [
205
+ 5,
206
+ 10
207
+ ],
208
+ "type": "integer"
209
+ },
210
+ "first_frame_image_url": {
211
+ "required": true
212
+ },
213
+ "mode": {
214
+ "enum": [
215
+ "std",
216
+ "pro"
217
+ ]
218
+ },
219
+ "model": {
220
+ "required": true
221
+ },
222
+ "prompt": {
223
+ "required": true,
224
+ "min": 1,
225
+ "max": 2500,
226
+ "length": true
227
+ }
228
+ },
229
+ "kling-v3-turbo-image-to-video": {
230
+ "duration_seconds": {
231
+ "enum": [
232
+ 3,
233
+ 4,
234
+ 5,
235
+ 6,
236
+ 7,
237
+ 8,
238
+ 9,
239
+ 10,
240
+ 11,
241
+ 12,
242
+ 13,
243
+ 14,
244
+ 15
245
+ ],
246
+ "type": "integer"
247
+ },
248
+ "first_frame_image_url": {
249
+ "required": true
250
+ },
251
+ "model": {
252
+ "required": true
253
+ },
254
+ "output_resolution": {
255
+ "enum": [
256
+ "720p",
257
+ "1080p"
258
+ ]
259
+ },
260
+ "prompt": {
261
+ "required": true,
262
+ "min": 1,
263
+ "max": 2500,
264
+ "length": true
265
+ }
266
+ }
267
+ },
268
+ "rules": [
269
+ {
270
+ "when": {
271
+ "model": "kling-v2.1-master-image-to-video"
272
+ },
273
+ "forbidden": [
274
+ "output_resolution",
275
+ "mode",
276
+ "enable_sound"
277
+ ]
278
+ },
279
+ {
280
+ "when": {
281
+ "model": "kling-v2.1-pro"
282
+ },
283
+ "forbidden": [
284
+ "output_resolution",
285
+ "mode",
286
+ "enable_sound"
287
+ ]
288
+ },
289
+ {
290
+ "when": {
291
+ "model": "kling-v2.1-standard"
292
+ },
293
+ "forbidden": [
294
+ "output_resolution",
295
+ "mode",
296
+ "enable_sound"
297
+ ]
298
+ },
299
+ {
300
+ "when": {
301
+ "model": "kling-v2.5-turbo-image-to-video-pro"
302
+ },
303
+ "forbidden": [
304
+ "output_resolution",
305
+ "mode",
306
+ "enable_sound"
307
+ ]
308
+ },
309
+ {
310
+ "when": {
311
+ "model": "kling-v2.6"
312
+ },
313
+ "forbidden": [
314
+ "output_resolution",
315
+ "negative_prompt",
316
+ "cfg_scale"
317
+ ]
318
+ },
319
+ {
320
+ "when": {
321
+ "model": "kling-v3-turbo-image-to-video"
322
+ },
323
+ "forbidden": [
324
+ "mode",
325
+ "enable_sound",
326
+ "aspect_ratio",
327
+ "negative_prompt",
328
+ "cfg_scale",
329
+ "last_frame_image_url"
330
+ ]
331
+ }
332
+ ]
333
+ },
334
+ "motion-control": {
335
+ "models": [
336
+ "kling-3.0"
337
+ ],
338
+ "fields_by_model": {
339
+ "kling-3.0": {
340
+ "background_source": {
341
+ "enum": [
342
+ "video",
343
+ "image"
344
+ ]
345
+ },
346
+ "character_orientation": {
347
+ "enum": [
348
+ "video",
349
+ "image"
350
+ ]
351
+ },
352
+ "model": {
353
+ "required": true
354
+ },
355
+ "output_resolution": {
356
+ "enum": [
357
+ "720p",
358
+ "1080p"
359
+ ]
360
+ },
361
+ "reference_video_url": {
362
+ "required": true
363
+ },
364
+ "source_image_url": {
365
+ "required": true
366
+ }
367
+ }
368
+ }
369
+ },
370
+ "text-to-video": {
371
+ "models": [
372
+ "kling-3.0",
373
+ "kling-v2.1-master-text-to-video",
374
+ "kling-v2.5-turbo-text-to-video-pro",
375
+ "kling-v2.6",
376
+ "kling-v3-turbo-text-to-video"
377
+ ],
378
+ "fields_by_model": {
379
+ "kling-3.0": {
380
+ "aspect_ratio": {
381
+ "enum": [
382
+ "16:9",
383
+ "9:16",
384
+ "1:1"
385
+ ]
386
+ },
387
+ "duration_seconds": {
388
+ "enum": [
389
+ 3,
390
+ 4,
391
+ 5,
392
+ 6,
393
+ 7,
394
+ 8,
395
+ 9,
396
+ 10,
397
+ 11,
398
+ 12,
399
+ 13,
400
+ 14,
401
+ 15
402
+ ],
403
+ "type": "integer"
404
+ },
405
+ "model": {
406
+ "required": true
407
+ },
408
+ "output_resolution": {
409
+ "enum": [
410
+ "720p",
411
+ "1080p",
412
+ "4k"
413
+ ]
414
+ }
415
+ },
416
+ "kling-v2.1-master-text-to-video": {
417
+ "aspect_ratio": {
418
+ "enum": [
419
+ "16:9",
420
+ "9:16",
421
+ "1:1"
422
+ ]
423
+ },
424
+ "duration_seconds": {
425
+ "enum": [
426
+ 5,
427
+ 10
428
+ ],
429
+ "type": "integer"
430
+ },
431
+ "model": {
432
+ "required": true
433
+ }
434
+ },
435
+ "kling-v2.5-turbo-text-to-video-pro": {
436
+ "aspect_ratio": {
437
+ "enum": [
438
+ "16:9",
439
+ "9:16",
440
+ "1:1"
441
+ ]
442
+ },
443
+ "duration_seconds": {
444
+ "enum": [
445
+ 5,
446
+ 10
447
+ ],
448
+ "type": "integer"
449
+ },
450
+ "model": {
451
+ "required": true
452
+ }
453
+ },
454
+ "kling-v2.6": {
455
+ "aspect_ratio": {
456
+ "enum": [
457
+ "16:9",
458
+ "9:16",
459
+ "1:1"
460
+ ]
461
+ },
462
+ "duration_seconds": {
463
+ "enum": [
464
+ 5,
465
+ 10
466
+ ],
467
+ "type": "integer"
468
+ },
469
+ "mode": {
470
+ "enum": [
471
+ "std",
472
+ "pro"
473
+ ]
474
+ },
475
+ "model": {
476
+ "required": true
477
+ },
478
+ "prompt": {
479
+ "required": true,
480
+ "min": 1,
481
+ "max": 2500,
482
+ "length": true
483
+ }
484
+ },
485
+ "kling-v3-turbo-text-to-video": {
486
+ "aspect_ratio": {
487
+ "enum": [
488
+ "16:9",
489
+ "9:16",
490
+ "1:1"
491
+ ]
492
+ },
493
+ "duration_seconds": {
494
+ "enum": [
495
+ 3,
496
+ 4,
497
+ 5,
498
+ 6,
499
+ 7,
500
+ 8,
501
+ 9,
502
+ 10,
503
+ 11,
504
+ 12,
505
+ 13,
506
+ 14,
507
+ 15
508
+ ],
509
+ "type": "integer"
510
+ },
511
+ "model": {
512
+ "required": true
513
+ },
514
+ "output_resolution": {
515
+ "enum": [
516
+ "720p",
517
+ "1080p"
518
+ ]
519
+ },
520
+ "prompt": {
521
+ "required": true,
522
+ "min": 1,
523
+ "max": 2500,
524
+ "length": true
525
+ }
526
+ }
527
+ },
528
+ "rules": [
529
+ {
530
+ "when": {
531
+ "model": "kling-3.0"
532
+ },
533
+ "forbidden": [
534
+ "mode"
535
+ ]
536
+ },
537
+ {
538
+ "when": {
539
+ "model": "kling-v2.1-master-text-to-video"
540
+ },
541
+ "forbidden": [
542
+ "mode"
543
+ ]
544
+ },
545
+ {
546
+ "when": {
547
+ "model": "kling-v2.5-turbo-text-to-video-pro"
548
+ },
549
+ "forbidden": [
550
+ "mode"
551
+ ]
552
+ },
553
+ {
554
+ "when": {
555
+ "model": "kling-v2.6"
556
+ },
557
+ "forbidden": [
558
+ "output_resolution",
559
+ "negative_prompt",
560
+ "cfg_scale",
561
+ "multi_shots",
562
+ "multi_prompt",
563
+ "first_frame_image_url",
564
+ "last_frame_image_url",
565
+ "kling_elements"
566
+ ]
567
+ },
568
+ {
569
+ "when": {
570
+ "model": "kling-v3-turbo-text-to-video"
571
+ },
572
+ "forbidden": [
573
+ "mode",
574
+ "enable_sound",
575
+ "negative_prompt",
576
+ "cfg_scale",
577
+ "multi_shots",
578
+ "multi_prompt",
579
+ "first_frame_image_url",
580
+ "last_frame_image_url",
581
+ "kling_elements"
582
+ ]
583
+ }
584
+ ]
585
+ }
586
+ };
587
+
588
+ // src/resources/text-to-video.ts
44
589
  var ENDPOINT = "/api/v1/kling/text_to_video";
590
+ var V26_MODEL = "kling-v2.6";
591
+ var V3_TURBO_MODEL = "kling-v3-turbo-text-to-video";
592
+ var V3_TURBO_UNSUPPORTED_FIELDS = [
593
+ "enable_sound",
594
+ "negative_prompt",
595
+ "cfg_scale",
596
+ "multi_shots",
597
+ "multi_prompt",
598
+ "first_frame_image_url",
599
+ "last_frame_image_url",
600
+ "kling_elements"
601
+ ];
45
602
  var TextToVideo = class {
46
603
  constructor(http) {
47
604
  this.http = http;
@@ -68,8 +625,12 @@ var TextToVideo = class {
68
625
  * @returns The task creation result with id.
69
626
  */
70
627
  async create(params, options) {
628
+ const body = (0, import_core.compactParams)(params);
629
+ rejectUnsupportedV3TurboFields(body);
630
+ (0, import_core.validateParams)(contract["text-to-video"], body);
631
+ validateV26Params(body);
71
632
  return this.http.request("POST", ENDPOINT, {
72
- body: (0, import_core.compactParams)(params),
633
+ body,
73
634
  ...options
74
635
  });
75
636
  }
@@ -85,11 +646,47 @@ var TextToVideo = class {
85
646
  });
86
647
  }
87
648
  };
649
+ function validateV26Params(body) {
650
+ if (body.model !== V26_MODEL) return;
651
+ if (body.enable_sound === true && body.mode !== "pro") {
652
+ throw new import_core.ValidationError(`enable_sound requires mode pro for ${V26_MODEL}`);
653
+ }
654
+ }
655
+ function rejectUnsupportedV3TurboFields(body) {
656
+ if (body.model !== V3_TURBO_MODEL) return;
657
+ const field = V3_TURBO_UNSUPPORTED_FIELDS.find((candidate) => fieldPresent(body, candidate));
658
+ if (field) {
659
+ throw new import_core.ValidationError(`${field} is not supported by ${V3_TURBO_MODEL}`);
660
+ }
661
+ }
662
+ function fieldPresent(params, field) {
663
+ if (!(field in params)) return false;
664
+ const value = params[field];
665
+ if (value === false) return true;
666
+ if (Array.isArray(value)) return value.some((item) => presentValue(item));
667
+ return presentValue(value);
668
+ }
669
+ function presentValue(value) {
670
+ if (value === null || value === void 0 || value === false) return false;
671
+ if (value === true) return true;
672
+ if (typeof value === "string") return value.trim() !== "";
673
+ if (Array.isArray(value)) return value.length > 0;
674
+ if (typeof value === "object") return Object.keys(value).length > 0;
675
+ return true;
676
+ }
88
677
 
89
678
  // src/resources/image-to-video.ts
90
679
  var import_core2 = require("@runapi.ai/core");
91
680
  var import_internal2 = require("@runapi.ai/core/internal");
92
681
  var ENDPOINT2 = "/api/v1/kling/image_to_video";
682
+ var V26_MODEL2 = "kling-v2.6";
683
+ var V3_TURBO_MODEL2 = "kling-v3-turbo-image-to-video";
684
+ var V3_TURBO_UNSUPPORTED_FIELDS2 = [
685
+ "aspect_ratio",
686
+ "negative_prompt",
687
+ "cfg_scale",
688
+ "last_frame_image_url"
689
+ ];
93
690
  var ImageToVideo = class {
94
691
  constructor(http) {
95
692
  this.http = http;
@@ -116,8 +713,12 @@ var ImageToVideo = class {
116
713
  * @returns The task creation result with id.
117
714
  */
118
715
  async create(params, options) {
716
+ const body = (0, import_core2.compactParams)(params);
717
+ rejectUnsupportedV3TurboFields2(body);
718
+ (0, import_core2.validateParams)(contract["image-to-video"], body);
719
+ validateV26Params2(body);
119
720
  return this.http.request("POST", ENDPOINT2, {
120
- body: (0, import_core2.compactParams)(params),
721
+ body,
121
722
  ...options
122
723
  });
123
724
  }
@@ -133,6 +734,41 @@ var ImageToVideo = class {
133
734
  });
134
735
  }
135
736
  };
737
+ function validateV26Params2(body) {
738
+ if (body.model !== V26_MODEL2) return;
739
+ if (body.enable_sound === true && body.mode !== "pro") {
740
+ throw new import_core2.ValidationError(`enable_sound requires mode pro for ${V26_MODEL2}`);
741
+ }
742
+ if (!fieldPresent2(body, "last_frame_image_url")) return;
743
+ if (body.mode !== "pro") {
744
+ throw new import_core2.ValidationError(`last_frame_image_url requires mode pro for ${V26_MODEL2}`);
745
+ }
746
+ if (body.duration_seconds !== void 0 && body.duration_seconds !== 5) {
747
+ throw new import_core2.ValidationError(`last_frame_image_url requires duration_seconds 5 for ${V26_MODEL2}`);
748
+ }
749
+ }
750
+ function rejectUnsupportedV3TurboFields2(body) {
751
+ if (body.model !== V3_TURBO_MODEL2) return;
752
+ const field = V3_TURBO_UNSUPPORTED_FIELDS2.find((candidate) => fieldPresent2(body, candidate));
753
+ if (field) {
754
+ throw new import_core2.ValidationError(`${field} is not supported by ${V3_TURBO_MODEL2}`);
755
+ }
756
+ }
757
+ function fieldPresent2(params, field) {
758
+ if (!(field in params)) return false;
759
+ const value = params[field];
760
+ if (value === false) return true;
761
+ if (Array.isArray(value)) return value.some((item) => presentValue2(item));
762
+ return presentValue2(value);
763
+ }
764
+ function presentValue2(value) {
765
+ if (value === null || value === void 0 || value === false) return false;
766
+ if (value === true) return true;
767
+ if (typeof value === "string") return value.trim() !== "";
768
+ if (Array.isArray(value)) return value.length > 0;
769
+ if (typeof value === "object") return Object.keys(value).length > 0;
770
+ return true;
771
+ }
136
772
 
137
773
  // src/resources/ai-avatar.ts
138
774
  var import_core3 = require("@runapi.ai/core");
@@ -164,8 +800,10 @@ var AiAvatar = class {
164
800
  * @returns The task creation result with id.
165
801
  */
166
802
  async create(params, options) {
803
+ const body = (0, import_core3.compactParams)(params);
804
+ (0, import_core3.validateParams)(contract["avatar"], body);
167
805
  return this.http.request("POST", ENDPOINT3, {
168
- body: (0, import_core3.compactParams)(params),
806
+ body,
169
807
  ...options
170
808
  });
171
809
  }
@@ -212,8 +850,10 @@ var MotionControl = class {
212
850
  * @returns The task creation result with id.
213
851
  */
214
852
  async create(params, options) {
853
+ const body = (0, import_core4.compactParams)(params);
854
+ (0, import_core4.validateParams)(contract["motion-control"], body);
215
855
  return this.http.request("POST", ENDPOINT4, {
216
- body: (0, import_core4.compactParams)(params),
856
+ body,
217
857
  ...options
218
858
  });
219
859
  }