@ai-sdk/klingai 3.0.0 → 3.0.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/klingai
2
2
 
3
+ ## 3.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 99fbed8: feat: normalize provider specific model options type names and ensure they are exported
8
+
9
+ ## 3.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - c43aeb2: feat (provider/klingai): add text-to-video and image-to-video support
14
+
3
15
  ## 3.0.0
4
16
 
5
17
  ### Major Changes
package/README.md CHANGED
@@ -26,33 +26,73 @@ You can import the default provider instance `klingai` from `@ai-sdk/klingai`:
26
26
  import { klingai } from '@ai-sdk/klingai';
27
27
  ```
28
28
 
29
- ## Video Generation Example
29
+ ## Video Models
30
+
31
+ This provider currently supports three video generation modes: text-to-video, image-to-video, and motion control.
32
+
33
+ > **Note:** Not all options are supported by every model version and mode combination. See the [KlingAI Capability Map](https://app.klingai.com/global/dev/document-api/apiReference/model/skillsMap) for detailed compatibility.
34
+
35
+ ### Text-to-Video
36
+
37
+ Generate video from a text prompt.
38
+
39
+ Available models: `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`
30
40
 
31
41
  ```ts
32
42
  import { klingai } from '@ai-sdk/klingai';
33
43
  import { experimental_generateVideo } from 'ai';
34
44
 
35
45
  const { videos } = await experimental_generateVideo({
36
- model: klingai.video('kling-v2.6-motion-control'),
46
+ model: klingai.video('kling-v2.6-t2v'),
47
+ prompt: 'A chicken flying into the sunset in the style of 90s anime.',
48
+ aspectRatio: '16:9',
49
+ duration: 5,
50
+ providerOptions: {
51
+ klingai: {
52
+ mode: 'std',
53
+ },
54
+ },
55
+ });
56
+ ```
57
+
58
+ ### Image-to-Video
59
+
60
+ Generate video from a start frame image, with optional end frame control.
61
+
62
+ Available models: `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`
63
+
64
+ ```ts
65
+ import { klingai } from '@ai-sdk/klingai';
66
+ import { experimental_generateVideo } from 'ai';
67
+
68
+ const { videos } = await experimental_generateVideo({
69
+ model: klingai.video('kling-v2.6-i2v'),
37
70
  prompt: {
38
- image: 'https://example.com/character.png',
39
- text: 'The character performs a smooth dance move',
71
+ image: 'https://example.com/start-frame.png',
72
+ text: 'The cat slowly turns its head and blinks',
40
73
  },
74
+ duration: 5,
41
75
  providerOptions: {
42
76
  klingai: {
43
- videoUrl: 'https://example.com/reference-motion.mp4',
44
- characterOrientation: 'image',
45
- mode: 'std',
77
+ // Pro mode required for start+end frame control
78
+ mode: 'pro',
79
+ // Optional: end frame image
80
+ imageTail: 'https://example.com/end-frame.png',
46
81
  },
47
82
  },
48
83
  });
49
84
  ```
50
85
 
51
- ## Additional Options
86
+ ### Motion Control
87
+
88
+ Generate video using a reference motion video.
52
89
 
53
- Use `providerOptions.klingai` to configure motion control options:
90
+ Available models: `kling-v2.6-motion-control`
54
91
 
55
92
  ```ts
93
+ import { klingai } from '@ai-sdk/klingai';
94
+ import { experimental_generateVideo } from 'ai';
95
+
56
96
  const { videos } = await experimental_generateVideo({
57
97
  model: klingai.video('kling-v2.6-motion-control'),
58
98
  prompt: {
@@ -62,17 +102,36 @@ const { videos } = await experimental_generateVideo({
62
102
  providerOptions: {
63
103
  klingai: {
64
104
  videoUrl: 'https://example.com/reference-motion.mp4',
65
- characterOrientation: 'video',
66
- mode: 'pro',
67
- keepOriginalSound: 'yes',
68
- watermarkEnabled: true,
69
- pollIntervalMs: 10000,
70
- pollTimeoutMs: 600000,
105
+ characterOrientation: 'image',
106
+ mode: 'std',
71
107
  },
72
108
  },
73
109
  });
74
110
  ```
75
111
 
112
+ ## Provider Options
113
+
114
+ Use `providerOptions.klingai` to configure video generation. Options vary by mode:
115
+
116
+ | Option | T2V | I2V | Motion Control | Description |
117
+ | ---------------------- | ----------------- | ----------------- | ----------------- | ------------------------------- |
118
+ | `mode` | `'std'` / `'pro'` | `'std'` / `'pro'` | `'std'` / `'pro'` | Generation quality mode |
119
+ | `negativePrompt` | Yes | Yes | — | What to avoid (max 2500 chars) |
120
+ | `sound` | V2.6+ pro only | V2.6+ pro only | — | `'on'` / `'off'` for audio |
121
+ | `cfgScale` | Yes (V1.x) | Yes (V1.x) | — | Prompt adherence [0, 1] |
122
+ | `cameraControl` | Yes | Yes | — | Camera movement presets |
123
+ | `imageTail` | — | Pro mode | — | End frame image (URL or base64) |
124
+ | `staticMask` | — | Yes | — | Static brush mask |
125
+ | `dynamicMasks` | — | Yes | — | Dynamic brush configs |
126
+ | `videoUrl` | — | — | Required | Reference motion video URL |
127
+ | `characterOrientation` | — | — | Required | `'image'` or `'video'` |
128
+ | `keepOriginalSound` | — | — | Yes | `'yes'` / `'no'` |
129
+ | `watermarkEnabled` | — | — | Yes | Enable watermark |
130
+ | `pollIntervalMs` | Yes | Yes | Yes | Poll interval (default: 5000ms) |
131
+ | `pollTimeoutMs` | Yes | Yes | Yes | Max wait (default: 600000ms) |
132
+
133
+ See the [KlingAI Capability Map](https://app.klingai.com/global/dev/document-api/apiReference/model/skillsMap) for which features each model version supports.
134
+
76
135
  ## Authentication
77
136
 
78
137
  Kling AI uses access key / secret key authentication. Set the following environment variables:
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ProviderV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
 
4
- type KlingAIVideoModelId = 'kling-v2.6-motion-control' | (string & {});
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-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-v2.6-motion-control' | (string & {});
5
5
 
6
6
  interface KlingAIProviderSettings {
7
7
  /**
@@ -47,7 +47,85 @@ declare function createKlingAI(options?: KlingAIProviderSettings): KlingAIProvid
47
47
  */
48
48
  declare const klingai: KlingAIProvider;
49
49
 
50
- type KlingAIVideoProviderOptions = {
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;
51
129
  /**
52
130
  * URL of the reference video. The character actions in the generated video
53
131
  * are consistent with the reference video.
@@ -55,7 +133,7 @@ type KlingAIVideoProviderOptions = {
55
133
  * Supports .mp4/.mov, max 100MB, side lengths 340px–3850px,
56
134
  * duration 3–30 seconds (depends on `characterOrientation`).
57
135
  */
58
- videoUrl: string;
136
+ videoUrl?: string | null;
59
137
  /**
60
138
  * Orientation of the characters in the generated video.
61
139
  *
@@ -64,14 +142,7 @@ type KlingAIVideoProviderOptions = {
64
142
  * - `'video'`: Same orientation as the person in the video.
65
143
  * Reference video duration max 30 seconds.
66
144
  */
67
- characterOrientation: 'image' | 'video';
68
- /**
69
- * Video generation mode.
70
- *
71
- * - `'std'`: Standard mode — cost-effective.
72
- * - `'pro'`: Professional mode — higher quality but longer generation time.
73
- */
74
- mode: 'std' | 'pro';
145
+ characterOrientation?: 'image' | 'video' | null;
75
146
  /**
76
147
  * Whether to keep the original sound of the reference video.
77
148
  * Default: `'yes'`.
@@ -81,17 +152,7 @@ type KlingAIVideoProviderOptions = {
81
152
  * Whether to generate watermarked results simultaneously.
82
153
  */
83
154
  watermarkEnabled?: boolean | null;
84
- /**
85
- * Polling interval in milliseconds for checking task status.
86
- * Default: 5000 (5 seconds).
87
- */
88
- pollIntervalMs?: number | null;
89
- /**
90
- * Maximum time in milliseconds to wait for video generation.
91
- * Default: 600000 (10 minutes).
92
- */
93
- pollTimeoutMs?: number | null;
94
155
  [key: string]: unknown;
95
156
  };
96
157
 
97
- export { type KlingAIProvider, type KlingAIProviderSettings, type KlingAIVideoModelId, type KlingAIVideoProviderOptions, createKlingAI, klingai };
158
+ export { type KlingAIProvider, type KlingAIProviderSettings, type KlingAIVideoModelId, type KlingAIVideoModelOptions, type KlingAIVideoModelOptions as KlingAIVideoProviderOptions, createKlingAI, klingai };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ProviderV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
 
4
- type KlingAIVideoModelId = 'kling-v2.6-motion-control' | (string & {});
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-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-v2.6-motion-control' | (string & {});
5
5
 
6
6
  interface KlingAIProviderSettings {
7
7
  /**
@@ -47,7 +47,85 @@ declare function createKlingAI(options?: KlingAIProviderSettings): KlingAIProvid
47
47
  */
48
48
  declare const klingai: KlingAIProvider;
49
49
 
50
- type KlingAIVideoProviderOptions = {
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;
51
129
  /**
52
130
  * URL of the reference video. The character actions in the generated video
53
131
  * are consistent with the reference video.
@@ -55,7 +133,7 @@ type KlingAIVideoProviderOptions = {
55
133
  * Supports .mp4/.mov, max 100MB, side lengths 340px–3850px,
56
134
  * duration 3–30 seconds (depends on `characterOrientation`).
57
135
  */
58
- videoUrl: string;
136
+ videoUrl?: string | null;
59
137
  /**
60
138
  * Orientation of the characters in the generated video.
61
139
  *
@@ -64,14 +142,7 @@ type KlingAIVideoProviderOptions = {
64
142
  * - `'video'`: Same orientation as the person in the video.
65
143
  * Reference video duration max 30 seconds.
66
144
  */
67
- characterOrientation: 'image' | 'video';
68
- /**
69
- * Video generation mode.
70
- *
71
- * - `'std'`: Standard mode — cost-effective.
72
- * - `'pro'`: Professional mode — higher quality but longer generation time.
73
- */
74
- mode: 'std' | 'pro';
145
+ characterOrientation?: 'image' | 'video' | null;
75
146
  /**
76
147
  * Whether to keep the original sound of the reference video.
77
148
  * Default: `'yes'`.
@@ -81,17 +152,7 @@ type KlingAIVideoProviderOptions = {
81
152
  * Whether to generate watermarked results simultaneously.
82
153
  */
83
154
  watermarkEnabled?: boolean | null;
84
- /**
85
- * Polling interval in milliseconds for checking task status.
86
- * Default: 5000 (5 seconds).
87
- */
88
- pollIntervalMs?: number | null;
89
- /**
90
- * Maximum time in milliseconds to wait for video generation.
91
- * Default: 600000 (10 minutes).
92
- */
93
- pollTimeoutMs?: number | null;
94
155
  [key: string]: unknown;
95
156
  };
96
157
 
97
- export { type KlingAIProvider, type KlingAIProviderSettings, type KlingAIVideoModelId, type KlingAIVideoProviderOptions, createKlingAI, klingai };
158
+ export { type KlingAIProvider, type KlingAIProviderSettings, type KlingAIVideoModelId, type KlingAIVideoModelOptions, type KlingAIVideoModelOptions as KlingAIVideoProviderOptions, createKlingAI, klingai };