@ai-sdk/klingai 4.0.0-beta.5 → 4.0.0-beta.52

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AISDKError,
3
- type Experimental_VideoModelV4,
4
3
  NoSuchModelError,
4
+ type Experimental_VideoModelV4,
5
5
  type SharedV4Warning,
6
6
  } from '@ai-sdk/provider';
7
7
  import {
@@ -9,17 +9,19 @@ import {
9
9
  convertUint8ArrayToBase64,
10
10
  createJsonResponseHandler,
11
11
  delay,
12
- type FetchFunction,
13
12
  getFromApi,
14
- lazySchema,
15
13
  parseProviderOptions,
16
14
  postJsonToApi,
17
- type Resolvable,
18
15
  resolve,
19
- zodSchema,
16
+ type FetchFunction,
17
+ type Resolvable,
20
18
  } from '@ai-sdk/provider-utils';
21
19
  import { z } from 'zod/v4';
22
20
  import { klingaiFailedResponseHandler } from './klingai-error';
21
+ import {
22
+ klingaiVideoModelOptionsSchema,
23
+ type KlingAIVideoModelOptions,
24
+ } from './klingai-video-model-options';
23
25
  import type { KlingAIVideoModelId } from './klingai-video-settings';
24
26
 
25
27
  type KlingAIVideoMode = 't2v' | 'i2v' | 'motion-control';
@@ -59,283 +61,6 @@ function getApiModelName(modelId: string, mode: KlingAIVideoMode): string {
59
61
  return baseName.replace(/\.0$/, '').replace(/\./g, '-');
60
62
  }
61
63
 
62
- /**
63
- * Provider-specific options for KlingAI video generation.
64
- *
65
- * Not all options are supported by every model version and video mode (T2V, I2V,
66
- * motion control). See the KlingAI capability map for detailed compatibility:
67
- * https://app.klingai.com/global/dev/document-api/apiReference/model/skillsMap
68
- */
69
- export type KlingAIVideoModelOptions = {
70
- /**
71
- * Video generation mode.
72
- *
73
- * - `'std'`: Standard mode — cost-effective.
74
- * - `'pro'`: Professional mode — higher quality but longer generation time.
75
- */
76
- mode?: 'std' | 'pro' | null;
77
-
78
- /**
79
- * Polling interval in milliseconds for checking task status.
80
- * Default: 5000 (5 seconds).
81
- */
82
- pollIntervalMs?: number | null;
83
-
84
- /**
85
- * Maximum time in milliseconds to wait for video generation.
86
- * Default: 600000 (10 minutes).
87
- */
88
- pollTimeoutMs?: number | null;
89
-
90
- // --- T2V and I2V options ---
91
-
92
- /**
93
- * Negative text prompt to specify what to avoid.
94
- * Cannot exceed 2500 characters.
95
- */
96
- negativePrompt?: string | null;
97
-
98
- /**
99
- * Whether to generate sound simultaneously when generating videos.
100
- * Only V2.6 and subsequent versions support this parameter,
101
- * and requires `mode: 'pro'`.
102
- */
103
- sound?: 'on' | 'off' | null;
104
-
105
- /**
106
- * Flexibility in video generation. The higher the value, the lower the
107
- * model's flexibility, and the stronger the relevance to the user's prompt.
108
- * Value range: [0, 1]. Kling-v2.x models do not support this parameter.
109
- */
110
- cfgScale?: number | null;
111
-
112
- /**
113
- * Camera movement control. If not specified, the model will intelligently
114
- * match based on the input text/images.
115
- */
116
- cameraControl?: {
117
- type:
118
- | 'simple'
119
- | 'down_back'
120
- | 'forward_up'
121
- | 'right_turn_forward'
122
- | 'left_turn_forward';
123
- config?: {
124
- horizontal?: number | null;
125
- vertical?: number | null;
126
- pan?: number | null;
127
- tilt?: number | null;
128
- roll?: number | null;
129
- zoom?: number | null;
130
- } | null;
131
- } | null;
132
-
133
- // --- I2V-specific options ---
134
-
135
- /**
136
- * End frame image for I2V start+end frame control.
137
- * Supports image URL or raw base64-encoded image data.
138
- * Requires `mode: 'pro'` for most models.
139
- */
140
- imageTail?: string | null;
141
-
142
- /**
143
- * Static brush mask image for I2V motion brush.
144
- * Supports image URL or raw base64-encoded image data.
145
- */
146
- staticMask?: string | null;
147
-
148
- /**
149
- * Dynamic brush configurations for I2V motion brush.
150
- * Up to 6 groups, each with a mask and motion trajectories.
151
- */
152
- dynamicMasks?: Array<{
153
- mask: string;
154
- trajectories: Array<{ x: number; y: number }>;
155
- }> | null;
156
-
157
- // --- v3.0 multi-shot options (T2V and I2V) ---
158
-
159
- /**
160
- * Enable multi-shot video generation (Kling v3.0+).
161
- * When true, the video is split into up to 6 storyboard shots
162
- * with individual prompts and durations.
163
- *
164
- * When multiShot is true with shotType 'customize', multiPrompt is required.
165
- * When multiShot is true, the main prompt parameter is ignored by the API.
166
- */
167
- multiShot?: boolean | null;
168
-
169
- /**
170
- * Storyboard method for multi-shot video generation (Kling v3.0+).
171
- * Required when multiShot is true.
172
- *
173
- * - `'customize'`: User-defined shots via multiPrompt.
174
- * - `'intelligence'`: Model auto-segments based on the main prompt.
175
- */
176
- shotType?: 'customize' | 'intelligence' | null;
177
-
178
- /**
179
- * Per-shot details for multi-shot video generation (Kling v3.0+).
180
- * Required when multiShot is true and shotType is 'customize'.
181
- *
182
- * Up to 6 shots. Each shot has an index, prompt (max 512 chars),
183
- * and duration in seconds. Shot durations must sum to the total duration.
184
- */
185
- multiPrompt?: Array<{
186
- index: number;
187
- prompt: string;
188
- duration: string;
189
- }> | null;
190
-
191
- // --- v3.0 element control (I2V and Motion Control) ---
192
-
193
- /**
194
- * Reference elements for element control (Kling v3.0+).
195
- * Supports video character elements and multi-image elements.
196
- *
197
- * - I2V: Up to 3 reference elements. Cannot coexist with voiceList.
198
- * - Motion Control: Currently only 1 element supported.
199
- * When referencing an element, the generated video can only
200
- * refer to the orientation of the person in the video.
201
- */
202
- elementList?: Array<{
203
- element_id: number;
204
- }> | null;
205
-
206
- // --- v3.0 voice control (T2V and I2V) ---
207
-
208
- /**
209
- * Voice references for voice control (Kling v3.0+).
210
- * Up to 2 voice references. Referenced via `<<<voice_1>>>` template
211
- * syntax in the prompt.
212
- *
213
- * When voiceList is used and the prompt references voice IDs,
214
- * sound must be set to 'on'.
215
- * Cannot coexist with elementList on the I2V endpoint.
216
- */
217
- voiceList?: Array<{
218
- voice_id: string;
219
- }> | null;
220
-
221
- // --- Shared options ---
222
-
223
- /**
224
- * Whether to generate watermarked results simultaneously.
225
- */
226
- watermarkEnabled?: boolean | null;
227
-
228
- // --- Motion-control-specific options ---
229
-
230
- /**
231
- * URL of the reference video. The character actions in the generated video
232
- * are consistent with the reference video.
233
- *
234
- * Supports .mp4/.mov, max 100MB, side lengths 340px–3850px,
235
- * duration 3–30 seconds (depends on `characterOrientation`).
236
- */
237
- videoUrl?: string | null;
238
-
239
- /**
240
- * Orientation of the characters in the generated video.
241
- *
242
- * - `'image'`: Same orientation as the person in the image.
243
- * Reference video duration max 10 seconds.
244
- * - `'video'`: Same orientation as the person in the video.
245
- * Reference video duration max 30 seconds.
246
- */
247
- characterOrientation?: 'image' | 'video' | null;
248
-
249
- /**
250
- * Whether to keep the original sound of the reference video.
251
- * Default: `'yes'`.
252
- */
253
- keepOriginalSound?: 'yes' | 'no' | null;
254
-
255
- [key: string]: unknown; // For passthrough
256
- };
257
-
258
- const klingaiVideoModelOptionsSchema = lazySchema(() =>
259
- zodSchema(
260
- z
261
- .object({
262
- mode: z.enum(['std', 'pro']).nullish(),
263
- pollIntervalMs: z.number().positive().nullish(),
264
- pollTimeoutMs: z.number().positive().nullish(),
265
- // T2V and I2V
266
- negativePrompt: z.string().nullish(),
267
- sound: z.enum(['on', 'off']).nullish(),
268
- cfgScale: z.number().nullish(),
269
- cameraControl: z
270
- .object({
271
- type: z.enum([
272
- 'simple',
273
- 'down_back',
274
- 'forward_up',
275
- 'right_turn_forward',
276
- 'left_turn_forward',
277
- ]),
278
- config: z
279
- .object({
280
- horizontal: z.number().nullish(),
281
- vertical: z.number().nullish(),
282
- pan: z.number().nullish(),
283
- tilt: z.number().nullish(),
284
- roll: z.number().nullish(),
285
- zoom: z.number().nullish(),
286
- })
287
- .nullish(),
288
- })
289
- .nullish(),
290
- // v3.0 multi-shot
291
- multiShot: z.boolean().nullish(),
292
- shotType: z.enum(['customize', 'intelligence']).nullish(),
293
- multiPrompt: z
294
- .array(
295
- z.object({
296
- index: z.number(),
297
- prompt: z.string(),
298
- duration: z.string(),
299
- }),
300
- )
301
- .nullish(),
302
- // v3.0 element control (I2V)
303
- elementList: z
304
- .array(
305
- z.object({
306
- element_id: z.number(),
307
- }),
308
- )
309
- .nullish(),
310
- // v3.0 voice control
311
- voiceList: z
312
- .array(
313
- z.object({
314
- voice_id: z.string(),
315
- }),
316
- )
317
- .nullish(),
318
- // I2V-specific
319
- imageTail: z.string().nullish(),
320
- staticMask: z.string().nullish(),
321
- dynamicMasks: z
322
- .array(
323
- z.object({
324
- mask: z.string(),
325
- trajectories: z.array(z.object({ x: z.number(), y: z.number() })),
326
- }),
327
- )
328
- .nullish(),
329
- // Motion-control-specific
330
- videoUrl: z.string().nullish(),
331
- characterOrientation: z.enum(['image', 'video']).nullish(),
332
- keepOriginalSound: z.enum(['yes', 'no']).nullish(),
333
- watermarkEnabled: z.boolean().nullish(),
334
- })
335
- .passthrough(),
336
- ),
337
- );
338
-
339
64
  /**
340
65
  * Known provider option keys that are handled explicitly and should not be
341
66
  * passed through to the API body.
@@ -594,8 +319,14 @@ export class KlingAIVideoModel implements Experimental_VideoModelV4 {
594
319
  body.negative_prompt = klingaiOptions.negativePrompt;
595
320
  }
596
321
 
597
- if (klingaiOptions?.sound != null) {
598
- body.sound = klingaiOptions.sound;
322
+ const sound =
323
+ options.generateAudio != null
324
+ ? options.generateAudio
325
+ ? 'on'
326
+ : 'off'
327
+ : klingaiOptions?.sound;
328
+ if (sound != null) {
329
+ body.sound = sound;
599
330
  }
600
331
 
601
332
  if (klingaiOptions?.cfgScale != null) {
@@ -692,8 +423,14 @@ export class KlingAIVideoModel implements Experimental_VideoModelV4 {
692
423
  body.negative_prompt = klingaiOptions.negativePrompt;
693
424
  }
694
425
 
695
- if (klingaiOptions?.sound != null) {
696
- body.sound = klingaiOptions.sound;
426
+ const sound =
427
+ options.generateAudio != null
428
+ ? options.generateAudio
429
+ ? 'on'
430
+ : 'off'
431
+ : klingaiOptions?.sound;
432
+ if (sound != null) {
433
+ body.sound = sound;
697
434
  }
698
435
 
699
436
  if (klingaiOptions?.cfgScale != null) {
package/src/version.ts CHANGED
@@ -1,3 +1,6 @@
1
- declare const __PACKAGE_VERSION__: string;
2
-
3
- export const VERSION = __PACKAGE_VERSION__;
1
+ // Version string of this package injected at build time.
2
+ declare const __PACKAGE_VERSION__: string | undefined;
3
+ export const VERSION: string =
4
+ typeof __PACKAGE_VERSION__ !== 'undefined'
5
+ ? __PACKAGE_VERSION__
6
+ : '0.0.0-test';
package/dist/index.d.mts DELETED
@@ -1,211 +0,0 @@
1
- import { ProviderV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
-
4
- type KlingAIVideoModelId = 'kling-v1-t2v' | 'kling-v1.6-t2v' | 'kling-v2-master-t2v' | 'kling-v2.1-master-t2v' | 'kling-v2.5-turbo-t2v' | 'kling-v2.6-t2v' | 'kling-v3.0-t2v' | 'kling-v1-i2v' | 'kling-v1.5-i2v' | 'kling-v1.6-i2v' | 'kling-v2-master-i2v' | 'kling-v2.1-i2v' | 'kling-v2.1-master-i2v' | 'kling-v2.5-turbo-i2v' | 'kling-v2.6-i2v' | 'kling-v3.0-i2v' | 'kling-v2.6-motion-control' | 'kling-v3.0-motion-control' | (string & {});
5
-
6
- interface KlingAIProviderSettings {
7
- /**
8
- * KlingAI Access key. Default value is taken from the `KLINGAI_ACCESS_KEY`
9
- * environment variable.
10
- */
11
- accessKey?: string;
12
- /**
13
- * KlingAI Secret key. Default value is taken from the `KLINGAI_SECRET_KEY`
14
- * environment variable.
15
- */
16
- secretKey?: string;
17
- /**
18
- * Base URL for the API calls.
19
- */
20
- baseURL?: string;
21
- /**
22
- * Custom headers to include in the requests.
23
- */
24
- headers?: Record<string, string>;
25
- /**
26
- * Custom fetch implementation. You can use it as a middleware to intercept
27
- * requests, or to provide a custom fetch implementation for e.g. testing.
28
- */
29
- fetch?: FetchFunction;
30
- }
31
- interface KlingAIProvider extends ProviderV4 {
32
- /**
33
- * Creates a model for video generation.
34
- */
35
- video(modelId: KlingAIVideoModelId): Experimental_VideoModelV4;
36
- /**
37
- * Creates a model for video generation.
38
- */
39
- videoModel(modelId: KlingAIVideoModelId): Experimental_VideoModelV4;
40
- }
41
- /**
42
- * Create a KlingAI provider instance.
43
- */
44
- declare function createKlingAI(options?: KlingAIProviderSettings): KlingAIProvider;
45
- /**
46
- * Default KlingAI provider instance.
47
- */
48
- declare const klingai: KlingAIProvider;
49
-
50
- /**
51
- * Provider-specific options for KlingAI video generation.
52
- *
53
- * Not all options are supported by every model version and video mode (T2V, I2V,
54
- * motion control). See the KlingAI capability map for detailed compatibility:
55
- * https://app.klingai.com/global/dev/document-api/apiReference/model/skillsMap
56
- */
57
- type KlingAIVideoModelOptions = {
58
- /**
59
- * Video generation mode.
60
- *
61
- * - `'std'`: Standard mode — cost-effective.
62
- * - `'pro'`: Professional mode — higher quality but longer generation time.
63
- */
64
- mode?: 'std' | 'pro' | null;
65
- /**
66
- * Polling interval in milliseconds for checking task status.
67
- * Default: 5000 (5 seconds).
68
- */
69
- pollIntervalMs?: number | null;
70
- /**
71
- * Maximum time in milliseconds to wait for video generation.
72
- * Default: 600000 (10 minutes).
73
- */
74
- pollTimeoutMs?: number | null;
75
- /**
76
- * Negative text prompt to specify what to avoid.
77
- * Cannot exceed 2500 characters.
78
- */
79
- negativePrompt?: string | null;
80
- /**
81
- * Whether to generate sound simultaneously when generating videos.
82
- * Only V2.6 and subsequent versions support this parameter,
83
- * and requires `mode: 'pro'`.
84
- */
85
- sound?: 'on' | 'off' | null;
86
- /**
87
- * Flexibility in video generation. The higher the value, the lower the
88
- * model's flexibility, and the stronger the relevance to the user's prompt.
89
- * Value range: [0, 1]. Kling-v2.x models do not support this parameter.
90
- */
91
- cfgScale?: number | null;
92
- /**
93
- * Camera movement control. If not specified, the model will intelligently
94
- * match based on the input text/images.
95
- */
96
- cameraControl?: {
97
- type: 'simple' | 'down_back' | 'forward_up' | 'right_turn_forward' | 'left_turn_forward';
98
- config?: {
99
- horizontal?: number | null;
100
- vertical?: number | null;
101
- pan?: number | null;
102
- tilt?: number | null;
103
- roll?: number | null;
104
- zoom?: number | null;
105
- } | null;
106
- } | null;
107
- /**
108
- * End frame image for I2V start+end frame control.
109
- * Supports image URL or raw base64-encoded image data.
110
- * Requires `mode: 'pro'` for most models.
111
- */
112
- imageTail?: string | null;
113
- /**
114
- * Static brush mask image for I2V motion brush.
115
- * Supports image URL or raw base64-encoded image data.
116
- */
117
- staticMask?: string | null;
118
- /**
119
- * Dynamic brush configurations for I2V motion brush.
120
- * Up to 6 groups, each with a mask and motion trajectories.
121
- */
122
- dynamicMasks?: Array<{
123
- mask: string;
124
- trajectories: Array<{
125
- x: number;
126
- y: number;
127
- }>;
128
- }> | null;
129
- /**
130
- * Enable multi-shot video generation (Kling v3.0+).
131
- * When true, the video is split into up to 6 storyboard shots
132
- * with individual prompts and durations.
133
- *
134
- * When multiShot is true with shotType 'customize', multiPrompt is required.
135
- * When multiShot is true, the main prompt parameter is ignored by the API.
136
- */
137
- multiShot?: boolean | null;
138
- /**
139
- * Storyboard method for multi-shot video generation (Kling v3.0+).
140
- * Required when multiShot is true.
141
- *
142
- * - `'customize'`: User-defined shots via multiPrompt.
143
- * - `'intelligence'`: Model auto-segments based on the main prompt.
144
- */
145
- shotType?: 'customize' | 'intelligence' | null;
146
- /**
147
- * Per-shot details for multi-shot video generation (Kling v3.0+).
148
- * Required when multiShot is true and shotType is 'customize'.
149
- *
150
- * Up to 6 shots. Each shot has an index, prompt (max 512 chars),
151
- * and duration in seconds. Shot durations must sum to the total duration.
152
- */
153
- multiPrompt?: Array<{
154
- index: number;
155
- prompt: string;
156
- duration: string;
157
- }> | null;
158
- /**
159
- * Reference elements for element control (Kling v3.0+).
160
- * Supports video character elements and multi-image elements.
161
- *
162
- * - I2V: Up to 3 reference elements. Cannot coexist with voiceList.
163
- * - Motion Control: Currently only 1 element supported.
164
- * When referencing an element, the generated video can only
165
- * refer to the orientation of the person in the video.
166
- */
167
- elementList?: Array<{
168
- element_id: number;
169
- }> | null;
170
- /**
171
- * Voice references for voice control (Kling v3.0+).
172
- * Up to 2 voice references. Referenced via `<<<voice_1>>>` template
173
- * syntax in the prompt.
174
- *
175
- * When voiceList is used and the prompt references voice IDs,
176
- * sound must be set to 'on'.
177
- * Cannot coexist with elementList on the I2V endpoint.
178
- */
179
- voiceList?: Array<{
180
- voice_id: string;
181
- }> | null;
182
- /**
183
- * Whether to generate watermarked results simultaneously.
184
- */
185
- watermarkEnabled?: boolean | null;
186
- /**
187
- * URL of the reference video. The character actions in the generated video
188
- * are consistent with the reference video.
189
- *
190
- * Supports .mp4/.mov, max 100MB, side lengths 340px–3850px,
191
- * duration 3–30 seconds (depends on `characterOrientation`).
192
- */
193
- videoUrl?: string | null;
194
- /**
195
- * Orientation of the characters in the generated video.
196
- *
197
- * - `'image'`: Same orientation as the person in the image.
198
- * Reference video duration max 10 seconds.
199
- * - `'video'`: Same orientation as the person in the video.
200
- * Reference video duration max 30 seconds.
201
- */
202
- characterOrientation?: 'image' | 'video' | null;
203
- /**
204
- * Whether to keep the original sound of the reference video.
205
- * Default: `'yes'`.
206
- */
207
- keepOriginalSound?: 'yes' | 'no' | null;
208
- [key: string]: unknown;
209
- };
210
-
211
- export { type KlingAIProvider, type KlingAIProviderSettings, type KlingAIVideoModelId, type KlingAIVideoModelOptions, type KlingAIVideoModelOptions as KlingAIVideoProviderOptions, createKlingAI, klingai };