@ai-sdk/klingai 3.0.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/CHANGELOG.md +7 -0
- package/LICENSE +13 -0
- package/README.md +98 -0
- package/dist/index.d.mts +97 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +426 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +417 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +72 -0
- package/src/index.ts +7 -0
- package/src/klingai-auth.ts +75 -0
- package/src/klingai-error.ts +14 -0
- package/src/klingai-provider.ts +116 -0
- package/src/klingai-video-model.ts +467 -0
- package/src/klingai-video-settings.ts +1 -0
- package/src/version.ts +3 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# AI SDK - Kling AI Provider
|
|
2
|
+
|
|
3
|
+
The **Kling AI provider** for the [AI SDK](https://ai-sdk.dev/docs) contains video model support for the [Kling AI API](https://app.klingai.com/global/dev/document-api/quickStart/productIntroduction/overview).
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
The Kling AI provider is available in the `@ai-sdk/klingai` module. You can install it with:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i @ai-sdk/klingai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Skill for Coding Agents
|
|
14
|
+
|
|
15
|
+
If you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
npx skills add vercel/ai
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Provider Instance
|
|
22
|
+
|
|
23
|
+
You can import the default provider instance `klingai` from `@ai-sdk/klingai`:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { klingai } from '@ai-sdk/klingai';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Video Generation Example
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { klingai } from '@ai-sdk/klingai';
|
|
33
|
+
import { experimental_generateVideo } from 'ai';
|
|
34
|
+
|
|
35
|
+
const { videos } = await experimental_generateVideo({
|
|
36
|
+
model: klingai.video('kling-v2.6-motion-control'),
|
|
37
|
+
prompt: {
|
|
38
|
+
image: 'https://example.com/character.png',
|
|
39
|
+
text: 'The character performs a smooth dance move',
|
|
40
|
+
},
|
|
41
|
+
providerOptions: {
|
|
42
|
+
klingai: {
|
|
43
|
+
videoUrl: 'https://example.com/reference-motion.mp4',
|
|
44
|
+
characterOrientation: 'image',
|
|
45
|
+
mode: 'std',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Additional Options
|
|
52
|
+
|
|
53
|
+
Use `providerOptions.klingai` to configure motion control options:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const { videos } = await experimental_generateVideo({
|
|
57
|
+
model: klingai.video('kling-v2.6-motion-control'),
|
|
58
|
+
prompt: {
|
|
59
|
+
image: 'https://example.com/character.png',
|
|
60
|
+
text: 'The character performs a smooth dance move',
|
|
61
|
+
},
|
|
62
|
+
providerOptions: {
|
|
63
|
+
klingai: {
|
|
64
|
+
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,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Authentication
|
|
77
|
+
|
|
78
|
+
Kling AI uses access key / secret key authentication. Set the following environment variables:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
KLINGAI_ACCESS_KEY=your-access-key
|
|
82
|
+
KLINGAI_SECRET_KEY=your-secret-key
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Or pass them directly:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { createKlingAI } from '@ai-sdk/klingai';
|
|
89
|
+
|
|
90
|
+
const klingai = createKlingAI({
|
|
91
|
+
accessKey: 'your-access-key',
|
|
92
|
+
secretKey: 'your-secret-key',
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Documentation
|
|
97
|
+
|
|
98
|
+
Please check out the [Kling AI API documentation](https://app.klingai.com/global/dev/document-api/quickStart/productIntroduction/overview) for more information.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ProviderV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
type KlingAIVideoModelId = 'kling-v2.6-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 ProviderV3 {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a model for video generation.
|
|
34
|
+
*/
|
|
35
|
+
video(modelId: KlingAIVideoModelId): Experimental_VideoModelV3;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a model for video generation.
|
|
38
|
+
*/
|
|
39
|
+
videoModel(modelId: KlingAIVideoModelId): Experimental_VideoModelV3;
|
|
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
|
+
type KlingAIVideoProviderOptions = {
|
|
51
|
+
/**
|
|
52
|
+
* URL of the reference video. The character actions in the generated video
|
|
53
|
+
* are consistent with the reference video.
|
|
54
|
+
*
|
|
55
|
+
* Supports .mp4/.mov, max 100MB, side lengths 340px–3850px,
|
|
56
|
+
* duration 3–30 seconds (depends on `characterOrientation`).
|
|
57
|
+
*/
|
|
58
|
+
videoUrl: string;
|
|
59
|
+
/**
|
|
60
|
+
* Orientation of the characters in the generated video.
|
|
61
|
+
*
|
|
62
|
+
* - `'image'`: Same orientation as the person in the image.
|
|
63
|
+
* Reference video duration max 10 seconds.
|
|
64
|
+
* - `'video'`: Same orientation as the person in the video.
|
|
65
|
+
* Reference video duration max 30 seconds.
|
|
66
|
+
*/
|
|
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';
|
|
75
|
+
/**
|
|
76
|
+
* Whether to keep the original sound of the reference video.
|
|
77
|
+
* Default: `'yes'`.
|
|
78
|
+
*/
|
|
79
|
+
keepOriginalSound?: 'yes' | 'no' | null;
|
|
80
|
+
/**
|
|
81
|
+
* Whether to generate watermarked results simultaneously.
|
|
82
|
+
*/
|
|
83
|
+
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
|
+
[key: string]: unknown;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { type KlingAIProvider, type KlingAIProviderSettings, type KlingAIVideoModelId, type KlingAIVideoProviderOptions, createKlingAI, klingai };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ProviderV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
type KlingAIVideoModelId = 'kling-v2.6-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 ProviderV3 {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a model for video generation.
|
|
34
|
+
*/
|
|
35
|
+
video(modelId: KlingAIVideoModelId): Experimental_VideoModelV3;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a model for video generation.
|
|
38
|
+
*/
|
|
39
|
+
videoModel(modelId: KlingAIVideoModelId): Experimental_VideoModelV3;
|
|
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
|
+
type KlingAIVideoProviderOptions = {
|
|
51
|
+
/**
|
|
52
|
+
* URL of the reference video. The character actions in the generated video
|
|
53
|
+
* are consistent with the reference video.
|
|
54
|
+
*
|
|
55
|
+
* Supports .mp4/.mov, max 100MB, side lengths 340px–3850px,
|
|
56
|
+
* duration 3–30 seconds (depends on `characterOrientation`).
|
|
57
|
+
*/
|
|
58
|
+
videoUrl: string;
|
|
59
|
+
/**
|
|
60
|
+
* Orientation of the characters in the generated video.
|
|
61
|
+
*
|
|
62
|
+
* - `'image'`: Same orientation as the person in the image.
|
|
63
|
+
* Reference video duration max 10 seconds.
|
|
64
|
+
* - `'video'`: Same orientation as the person in the video.
|
|
65
|
+
* Reference video duration max 30 seconds.
|
|
66
|
+
*/
|
|
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';
|
|
75
|
+
/**
|
|
76
|
+
* Whether to keep the original sound of the reference video.
|
|
77
|
+
* Default: `'yes'`.
|
|
78
|
+
*/
|
|
79
|
+
keepOriginalSound?: 'yes' | 'no' | null;
|
|
80
|
+
/**
|
|
81
|
+
* Whether to generate watermarked results simultaneously.
|
|
82
|
+
*/
|
|
83
|
+
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
|
+
[key: string]: unknown;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { type KlingAIProvider, type KlingAIProviderSettings, type KlingAIVideoModelId, type KlingAIVideoProviderOptions, createKlingAI, klingai };
|