getaiapi 1.3.1 → 2.0.1

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
@@ -26,9 +26,577 @@ import {
26
26
  submit,
27
27
  submitAndPoll,
28
28
  uploadAsset
29
- } from "./chunk-CN4FJ4FW.js";
29
+ } from "./chunk-H6MMJNJX.js";
30
30
 
31
- // src/configure.ts
31
+ // src/providers/kling/errors.ts
32
+ var KlingError = class extends Error {
33
+ code;
34
+ constructor(code, message) {
35
+ super(message);
36
+ this.name = "KlingError";
37
+ this.code = code;
38
+ }
39
+ };
40
+ var KlingAuthError = class extends KlingError {
41
+ constructor(message = "Missing Kling credentials. Call kling.configure() or set KLING_ACCESS_KEY + KLING_SECRET_KEY.") {
42
+ super("AUTH_ERROR", message);
43
+ this.name = "KlingAuthError";
44
+ }
45
+ };
46
+ var KlingRateLimitError = class extends KlingError {
47
+ retryAfterMs;
48
+ bodyCode;
49
+ detail;
50
+ constructor(retryAfterMs, bodyCode, detail) {
51
+ const msg = detail ? `Kling 429 (code ${bodyCode ?? "unknown"}): ${detail}. Retry after ${retryAfterMs}ms.` : `Rate limited by Kling. Retry after ${retryAfterMs}ms.`;
52
+ super("RATE_LIMIT", msg);
53
+ this.name = "KlingRateLimitError";
54
+ this.retryAfterMs = retryAfterMs;
55
+ this.bodyCode = bodyCode;
56
+ this.detail = detail ?? "Rate limited";
57
+ }
58
+ };
59
+ var KlingApiError = class extends KlingError {
60
+ statusCode;
61
+ raw;
62
+ constructor(endpoint, statusCode, raw) {
63
+ super("API_ERROR", `Kling API error ${statusCode} on ${endpoint}.`);
64
+ this.name = "KlingApiError";
65
+ this.statusCode = statusCode;
66
+ this.raw = raw;
67
+ }
68
+ };
69
+ var KlingTimeoutError = class extends KlingError {
70
+ timeoutMs;
71
+ constructor(timeoutMs) {
72
+ super("TIMEOUT", `Kling task timed out after ${timeoutMs}ms.`);
73
+ this.name = "KlingTimeoutError";
74
+ this.timeoutMs = timeoutMs;
75
+ }
76
+ };
77
+ var KlingTaskFailedError = class extends KlingError {
78
+ taskId;
79
+ constructor(taskId, message) {
80
+ super("TASK_FAILED", `Kling task ${taskId} failed: ${message}`);
81
+ this.name = "KlingTaskFailedError";
82
+ this.taskId = taskId;
83
+ }
84
+ };
85
+
86
+ // src/providers/kling/auth.ts
87
+ import { createHmac } from "crypto";
88
+ function generateJwt(accessKey, secretKey) {
89
+ const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" })).toString("base64url");
90
+ const now = Math.floor(Date.now() / 1e3);
91
+ const payload = Buffer.from(JSON.stringify({
92
+ iss: accessKey,
93
+ exp: now + 1800,
94
+ nbf: now - 5
95
+ })).toString("base64url");
96
+ const signature = createHmac("sha256", secretKey).update(`${header}.${payload}`).digest("base64url");
97
+ return `${header}.${payload}.${signature}`;
98
+ }
99
+ function buildAuthHeaders(accessKey, secretKey) {
100
+ return {
101
+ Authorization: `Bearer ${generateJwt(accessKey, secretKey)}`,
102
+ "Content-Type": "application/json"
103
+ };
104
+ }
105
+
106
+ // src/providers/kling/client.ts
107
+ var API_BASE = "https://api-singapore.klingai.com";
108
+ var DEFAULT_FETCH_TIMEOUT_MS = 3e4;
109
+ var DEFAULT_POLL_TIMEOUT_MS = 3e5;
110
+ var DEFAULT_POLL_INTERVAL_MS = 2e3;
111
+ var POLL_BACKOFF_MULTIPLIER = 1.5;
112
+ var MAX_POLL_INTERVAL_MS = 1e4;
113
+ var SYNC_ENDPOINTS = /* @__PURE__ */ new Set(["v1/audio/tts", "v1/videos/image-recognize", "v1/videos/identify-face"]);
114
+ function cleanBase64(value) {
115
+ if (typeof value === "string" && value.startsWith("data:")) {
116
+ return value.split(",")[1] ?? value;
117
+ }
118
+ if (Array.isArray(value)) {
119
+ return value.map(cleanBase64);
120
+ }
121
+ if (value !== null && typeof value === "object") {
122
+ const result = {};
123
+ for (const [k, v] of Object.entries(value)) {
124
+ result[k] = cleanBase64(v);
125
+ }
126
+ return result;
127
+ }
128
+ return value;
129
+ }
130
+ var KlingClient = class {
131
+ accessKey = null;
132
+ secretKey = null;
133
+ fetchTimeoutMs = DEFAULT_FETCH_TIMEOUT_MS;
134
+ /** Update credentials and settings. */
135
+ configure(config) {
136
+ this.accessKey = config.accessKey;
137
+ this.secretKey = config.secretKey;
138
+ if (config.fetchTimeoutMs !== void 0) {
139
+ this.fetchTimeoutMs = config.fetchTimeoutMs;
140
+ }
141
+ }
142
+ resolveAuth() {
143
+ if (this.accessKey && this.secretKey) {
144
+ return { accessKey: this.accessKey, secretKey: this.secretKey };
145
+ }
146
+ const ak = process.env.KLING_ACCESS_KEY?.trim();
147
+ const sk = process.env.KLING_SECRET_KEY?.trim();
148
+ if (ak && sk) return { accessKey: ak, secretKey: sk };
149
+ throw new KlingAuthError();
150
+ }
151
+ // ── HTTP ─────────────────────────────────────────────────────────────────
152
+ async handleErrors(response, endpoint) {
153
+ if (response.ok) return;
154
+ let raw;
155
+ try {
156
+ raw = await response.json();
157
+ } catch {
158
+ raw = await response.text().catch(() => null);
159
+ }
160
+ console.error(`[kling] ${response.status} on ${endpoint}:`, JSON.stringify(raw));
161
+ if (response.status === 401) throw new KlingAuthError("Kling returned 401 Unauthorized.");
162
+ if (response.status === 429) {
163
+ const body = raw;
164
+ const code = body?.code;
165
+ const message = body?.message ?? "Rate limited";
166
+ const retryAfter = response.headers.get("retry-after");
167
+ throw new KlingRateLimitError(
168
+ retryAfter ? parseInt(retryAfter, 10) * 1e3 : 6e4,
169
+ code,
170
+ message
171
+ );
172
+ }
173
+ throw new KlingApiError(endpoint, response.status, raw);
174
+ }
175
+ handleBodyErrors(json, endpoint) {
176
+ if (json.code === 0) return;
177
+ console.error(`[kling] body error on ${endpoint}: code=${json.code} message=${json.message}`);
178
+ if (json.code >= 1e3 && json.code <= 1004) {
179
+ throw new KlingAuthError(`Kling auth error code ${json.code}: ${json.message}`);
180
+ }
181
+ if (json.code >= 1100 && json.code <= 1102 || json.code >= 1302 && json.code <= 1304) {
182
+ throw new KlingRateLimitError(5e3, json.code, json.message);
183
+ }
184
+ throw new KlingApiError(endpoint, json.code, json);
185
+ }
186
+ async httpSubmit(endpoint, body) {
187
+ const auth = this.resolveAuth();
188
+ const url = `${API_BASE}/${endpoint}`;
189
+ const response = await fetch(url, {
190
+ method: "POST",
191
+ headers: buildAuthHeaders(auth.accessKey, auth.secretKey),
192
+ body: JSON.stringify(body),
193
+ signal: AbortSignal.timeout(this.fetchTimeoutMs)
194
+ });
195
+ await this.handleErrors(response, endpoint);
196
+ const json = await response.json();
197
+ this.handleBodyErrors(json, endpoint);
198
+ return json;
199
+ }
200
+ async httpGet(endpoint, params) {
201
+ const auth = this.resolveAuth();
202
+ const qs = new URLSearchParams(params).toString();
203
+ const url = `${API_BASE}/${endpoint}?${qs}`;
204
+ const response = await fetch(url, {
205
+ headers: buildAuthHeaders(auth.accessKey, auth.secretKey),
206
+ signal: AbortSignal.timeout(this.fetchTimeoutMs)
207
+ });
208
+ await this.handleErrors(response, endpoint);
209
+ const json = await response.json();
210
+ this.handleBodyErrors(json, endpoint);
211
+ return json;
212
+ }
213
+ async httpPoll(endpoint, taskId) {
214
+ const auth = this.resolveAuth();
215
+ const url = `${API_BASE}/${endpoint}/${taskId}`;
216
+ const response = await fetch(url, {
217
+ headers: buildAuthHeaders(auth.accessKey, auth.secretKey),
218
+ signal: AbortSignal.timeout(this.fetchTimeoutMs)
219
+ });
220
+ await this.handleErrors(response, endpoint);
221
+ const json = await response.json();
222
+ this.handleBodyErrors(json, endpoint);
223
+ return json;
224
+ }
225
+ // ── Account ──────────────────────────────────────────────────────────────
226
+ async accountCosts(input) {
227
+ const params = {
228
+ start_time: String(input.start_time),
229
+ end_time: String(input.end_time)
230
+ };
231
+ if (input.resource_pack_name !== void 0) {
232
+ params.resource_pack_name = input.resource_pack_name;
233
+ }
234
+ const json = await this.httpGet("account/costs", params);
235
+ const data = json.data;
236
+ return {
237
+ resource_pack_subscribe_infos: data.resource_pack_subscribe_infos ?? []
238
+ };
239
+ }
240
+ // ── Execute ──────────────────────────────────────────────────────────────
241
+ async execute(endpoint, defaults, input, extractor, sync) {
242
+ const { timeout, pollInterval, options, ...params } = input;
243
+ const timeoutMs = timeout ?? DEFAULT_POLL_TIMEOUT_MS;
244
+ const initialIntervalMs = pollInterval ?? DEFAULT_POLL_INTERVAL_MS;
245
+ const body = { ...params };
246
+ if (options && typeof options === "object") {
247
+ for (const [key, val] of Object.entries(options)) {
248
+ if (!(key in body)) body[key] = val;
249
+ }
250
+ }
251
+ for (const [key, val] of Object.entries(defaults)) {
252
+ if (!(key in body)) body[key] = val;
253
+ }
254
+ const cleanedBody = cleanBase64(body);
255
+ const submitResult = await this.httpSubmit(endpoint, cleanedBody);
256
+ const isSyncEndpoint = sync ?? SYNC_ENDPOINTS.has(endpoint);
257
+ if (isSyncEndpoint) {
258
+ return extractor(submitResult.data);
259
+ }
260
+ const taskId = submitResult.data.task_id;
261
+ const deadline = Date.now() + timeoutMs;
262
+ let intervalMs = initialIntervalMs;
263
+ while (Date.now() < deadline) {
264
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
265
+ intervalMs = Math.min(intervalMs * POLL_BACKOFF_MULTIPLIER, MAX_POLL_INTERVAL_MS);
266
+ const pollResult = await this.httpPoll(endpoint, taskId);
267
+ const status = pollResult.data.task_status;
268
+ if (status === "failed") {
269
+ throw new KlingTaskFailedError(taskId, pollResult.data.task_status_msg ?? "Unknown error");
270
+ }
271
+ if (status === "succeed") {
272
+ return extractor(pollResult.data);
273
+ }
274
+ }
275
+ throw new KlingTimeoutError(timeoutMs);
276
+ }
277
+ };
278
+
279
+ // src/providers/kling/extract.ts
280
+ function extractVideos(data) {
281
+ const taskResult = data.task_result;
282
+ const videos = taskResult?.videos ?? [];
283
+ return { task_id: data.task_id, videos };
284
+ }
285
+ function extractImages(data) {
286
+ const taskResult = data.task_result;
287
+ const images = taskResult?.images ?? [];
288
+ return { task_id: data.task_id, images };
289
+ }
290
+ function extractAudios(data) {
291
+ const taskResult = data.task_result;
292
+ const rawAudios = taskResult?.audios ?? [];
293
+ const audios = rawAudios.map((a) => ({
294
+ id: a.id,
295
+ url: a.url ?? a.url_mp3 ?? a.url_wav ?? "",
296
+ url_mp3: a.url_mp3,
297
+ url_wav: a.url_wav,
298
+ duration: a.duration ?? a.duration_mp3,
299
+ duration_mp3: a.duration_mp3,
300
+ duration_wav: a.duration_wav
301
+ }));
302
+ return { task_id: data.task_id, audios };
303
+ }
304
+ function extractJson(data) {
305
+ return { task_id: data.task_id, data: data.task_result ?? data };
306
+ }
307
+ function extractFace(data) {
308
+ return {
309
+ session_id: data.session_id,
310
+ face_data: data.face_data ?? []
311
+ };
312
+ }
313
+ function extractMultiShot(data) {
314
+ const taskResult = data.task_result;
315
+ const rawImages = taskResult?.images ?? [];
316
+ const images = rawImages.map((img, i) => ({
317
+ index: img.index ?? i,
318
+ url_1: img.url_1,
319
+ url_2: img.url_2,
320
+ url_3: img.url_3
321
+ }));
322
+ return { task_id: data.task_id, images };
323
+ }
324
+ function extractVoices(data) {
325
+ const taskResult = data.task_result;
326
+ const voices = taskResult?.voices ?? [];
327
+ return { task_id: data.task_id, voices };
328
+ }
329
+ function extractVideoAudio(data) {
330
+ const taskResult = data.task_result;
331
+ const videos = taskResult?.videos ?? [];
332
+ const rawAudios = taskResult?.audios ?? [];
333
+ const audios = rawAudios.map((a) => ({
334
+ id: a.id,
335
+ url_mp3: a.url_mp3,
336
+ url_wav: a.url_wav,
337
+ duration_mp3: a.duration_mp3,
338
+ duration_wav: a.duration_wav
339
+ }));
340
+ return { task_id: data.task_id, videos, audios };
341
+ }
342
+
343
+ // src/providers/kling/models.ts
344
+ function createModels(client) {
345
+ return {
346
+ // ── text2video (9 models) ──────────────────────────────────────────────
347
+ textToVideoV1Standard(input) {
348
+ return client.execute("v1/videos/text2video", { model_name: "kling-v1", mode: "std" }, input, extractVideos);
349
+ },
350
+ textToVideoV1_6Pro(input) {
351
+ return client.execute("v1/videos/text2video", { model_name: "kling-v1-6", mode: "pro" }, input, extractVideos);
352
+ },
353
+ textToVideoV1_6Standard(input) {
354
+ return client.execute("v1/videos/text2video", { model_name: "kling-v1-6", mode: "std" }, input, extractVideos);
355
+ },
356
+ textToVideoV2Master(input) {
357
+ return client.execute("v1/videos/text2video", { model_name: "kling-v2-master" }, input, extractVideos);
358
+ },
359
+ textToVideoV2_1Master(input) {
360
+ return client.execute("v1/videos/text2video", { model_name: "kling-v2-1-master" }, input, extractVideos);
361
+ },
362
+ textToVideoV2_5TurboPro(input) {
363
+ return client.execute("v1/videos/text2video", { model_name: "kling-v2-5-turbo", mode: "pro" }, input, extractVideos);
364
+ },
365
+ textToVideoV2_6Pro(input) {
366
+ return client.execute("v1/videos/text2video", { model_name: "kling-v2-6", mode: "pro" }, input, extractVideos);
367
+ },
368
+ textToVideoV3Pro(input) {
369
+ return client.execute("v1/videos/text2video", { model_name: "kling-v3", mode: "pro" }, input, extractVideos);
370
+ },
371
+ textToVideoV3Standard(input) {
372
+ return client.execute("v1/videos/text2video", { model_name: "kling-v3", mode: "std" }, input, extractVideos);
373
+ },
374
+ // ── image2video (13 models) ────────────────────────────────────────────
375
+ imageToVideoV1Standard(input) {
376
+ return client.execute("v1/videos/image2video", { model_name: "kling-v1", mode: "std" }, input, extractVideos);
377
+ },
378
+ imageToVideoV1_5Pro(input) {
379
+ return client.execute("v1/videos/image2video", { model_name: "kling-v1-5", mode: "pro" }, input, extractVideos);
380
+ },
381
+ imageToVideoV1_6Pro(input) {
382
+ return client.execute("v1/videos/image2video", { model_name: "kling-v1-6", mode: "pro" }, input, extractVideos);
383
+ },
384
+ imageToVideoV1_6Standard(input) {
385
+ return client.execute("v1/videos/image2video", { model_name: "kling-v1-6", mode: "std" }, input, extractVideos);
386
+ },
387
+ imageToVideoV2Master(input) {
388
+ return client.execute("v1/videos/image2video", { model_name: "kling-v2-master" }, input, extractVideos);
389
+ },
390
+ imageToVideoV2_1Master(input) {
391
+ return client.execute("v1/videos/image2video", { model_name: "kling-v2-1-master" }, input, extractVideos);
392
+ },
393
+ imageToVideoV2_1Pro(input) {
394
+ return client.execute("v1/videos/image2video", { model_name: "kling-v2-1", mode: "pro" }, input, extractVideos);
395
+ },
396
+ imageToVideoV2_1Standard(input) {
397
+ return client.execute("v1/videos/image2video", { model_name: "kling-v2-1", mode: "std" }, input, extractVideos);
398
+ },
399
+ imageToVideoV2_5TurboPro(input) {
400
+ return client.execute("v1/videos/image2video", { model_name: "kling-v2-5-turbo", mode: "pro" }, input, extractVideos);
401
+ },
402
+ imageToVideoV2_5TurboStandard(input) {
403
+ return client.execute("v1/videos/image2video", { model_name: "kling-v2-5-turbo", mode: "std" }, input, extractVideos);
404
+ },
405
+ imageToVideoV2_6Pro(input) {
406
+ return client.execute("v1/videos/image2video", { model_name: "kling-v2-6", mode: "pro" }, input, extractVideos);
407
+ },
408
+ imageToVideoV3Pro(input) {
409
+ return client.execute("v1/videos/image2video", { model_name: "kling-v3", mode: "pro" }, input, extractVideos);
410
+ },
411
+ imageToVideoV3Standard(input) {
412
+ return client.execute("v1/videos/image2video", { model_name: "kling-v3", mode: "std" }, input, extractVideos);
413
+ },
414
+ // ── omni-video (17 models) ─────────────────────────────────────────────
415
+ omniVideoO1ImageToVideo(input) {
416
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1" }, input, extractVideos);
417
+ },
418
+ omniVideoO1ReferenceToVideo(input) {
419
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1" }, input, extractVideos);
420
+ },
421
+ omniVideoO1StandardImageToVideo(input) {
422
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1", mode: "std" }, input, extractVideos);
423
+ },
424
+ omniVideoO1StandardReferenceToVideo(input) {
425
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1", mode: "std" }, input, extractVideos);
426
+ },
427
+ omniVideoO1StandardVideoEdit(input) {
428
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1", mode: "std" }, input, extractVideos);
429
+ },
430
+ omniVideoO1StandardVideoReference(input) {
431
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1", mode: "std" }, input, extractVideos);
432
+ },
433
+ omniVideoO1VideoEdit(input) {
434
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1" }, input, extractVideos);
435
+ },
436
+ omniVideoO1VideoReference(input) {
437
+ return client.execute("v1/videos/omni-video", { model_name: "kling-video-o1" }, input, extractVideos);
438
+ },
439
+ omniVideoO3ProImageToVideo(input) {
440
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "pro" }, input, extractVideos);
441
+ },
442
+ omniVideoO3ProReferenceToVideo(input) {
443
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "pro" }, input, extractVideos);
444
+ },
445
+ omniVideoO3ProTextToVideo(input) {
446
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "pro" }, input, extractVideos);
447
+ },
448
+ omniVideoO3ProVideoEdit(input) {
449
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "pro" }, input, extractVideos);
450
+ },
451
+ omniVideoO3ProVideoReference(input) {
452
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "pro" }, input, extractVideos);
453
+ },
454
+ omniVideoO3StandardReferenceToVideo(input) {
455
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "std" }, input, extractVideos);
456
+ },
457
+ omniVideoO3StandardTextToVideo(input) {
458
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "std" }, input, extractVideos);
459
+ },
460
+ omniVideoO3StandardVideoEdit(input) {
461
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "std" }, input, extractVideos);
462
+ },
463
+ omniVideoO3StandardVideoReference(input) {
464
+ return client.execute("v1/videos/omni-video", { model_name: "kling-v3-omni", mode: "std" }, input, extractVideos);
465
+ },
466
+ // ── images/generations (2 models) ──────────────────────────────────────
467
+ imageV3TextToImage(input) {
468
+ return client.execute("v1/images/generations", { model_name: "kling-v3" }, input, extractImages);
469
+ },
470
+ imageV3ImageToImage(input) {
471
+ return client.execute("v1/images/generations", { model_name: "kling-v3" }, input, extractImages);
472
+ },
473
+ // ── images/omni-image (3 models) ───────────────────────────────────────
474
+ imageO1(input) {
475
+ return client.execute("v1/images/omni-image", { model_name: "kling-image-o1" }, input, extractImages);
476
+ },
477
+ imageO3TextToImage(input) {
478
+ return client.execute("v1/images/omni-image", { model_name: "kling-v3-omni" }, input, extractImages);
479
+ },
480
+ imageO3ImageToImage(input) {
481
+ return client.execute("v1/images/omni-image", { model_name: "kling-v3-omni" }, input, extractImages);
482
+ },
483
+ // ── virtual-try-on (1 model) ───────────────────────────────────────────
484
+ virtualTryOn(input) {
485
+ return client.execute("v1/images/kolors-virtual-try-on", { model_name: "kolors-virtual-try-on-v1-5" }, input, extractImages);
486
+ },
487
+ // ── avatar (4 models) ──────────────────────────────────────────────────
488
+ avatarV2Pro(input) {
489
+ return client.execute("v1/videos/avatar/image2video", { mode: "pro" }, input, extractVideos);
490
+ },
491
+ avatarV2Standard(input) {
492
+ return client.execute("v1/videos/avatar/image2video", { mode: "std" }, input, extractVideos);
493
+ },
494
+ avatarV1Pro(input) {
495
+ return client.execute("v1/videos/avatar/image2video", { mode: "pro" }, input, extractVideos);
496
+ },
497
+ avatarV1Standard(input) {
498
+ return client.execute("v1/videos/avatar/image2video", { mode: "std" }, input, extractVideos);
499
+ },
500
+ // ── lip-sync (2 models) ────────────────────────────────────────────────
501
+ lipSyncAudioToVideo(input) {
502
+ return client.execute("v1/videos/advanced-lip-sync", {}, input, extractVideos);
503
+ },
504
+ lipSyncTextToVideo(input) {
505
+ return client.execute("v1/videos/advanced-lip-sync", {}, input, extractVideos);
506
+ },
507
+ // ── effects (4 models) ─────────────────────────────────────────────────
508
+ effectsV1Standard(input) {
509
+ return client.execute("v1/videos/effects", {}, input, extractVideos);
510
+ },
511
+ effectsV1_5Pro(input) {
512
+ return client.execute("v1/videos/effects", {}, input, extractVideos);
513
+ },
514
+ effectsV1_6Pro(input) {
515
+ return client.execute("v1/videos/effects", {}, input, extractVideos);
516
+ },
517
+ effectsV1_6Standard(input) {
518
+ return client.execute("v1/videos/effects", {}, input, extractVideos);
519
+ },
520
+ // ── motion-control (4 models) ──────────────────────────────────────────
521
+ motionControlV2_6Pro(input) {
522
+ return client.execute("v1/videos/motion-control", { model_name: "kling-v2-6", mode: "pro" }, input, extractVideos);
523
+ },
524
+ motionControlV2_6Standard(input) {
525
+ return client.execute("v1/videos/motion-control", { model_name: "kling-v2-6", mode: "std" }, input, extractVideos);
526
+ },
527
+ motionControlV3Pro(input) {
528
+ return client.execute("v1/videos/motion-control", { model_name: "kling-v3", mode: "pro" }, input, extractVideos);
529
+ },
530
+ motionControlV3Standard(input) {
531
+ return client.execute("v1/videos/motion-control", { model_name: "kling-v3", mode: "std" }, input, extractVideos);
532
+ },
533
+ // ── tts (1 model, sync) ────────────────────────────────────────────────
534
+ tts(input) {
535
+ return client.execute("v1/audio/tts", {}, input, extractAudios, true);
536
+ },
537
+ // ── video-to-audio (1 model) ───────────────────────────────────────────
538
+ videoToAudio(input) {
539
+ return client.execute("v1/audio/video-to-audio", {}, input, extractVideoAudio);
540
+ },
541
+ // ── text-to-audio (1 model) ────────────────────────────────────────────
542
+ textToAudio(input) {
543
+ return client.execute("v1/audio/text-to-audio", {}, input, extractAudios);
544
+ },
545
+ // ── create-voice (1 model) ─────────────────────────────────────────────
546
+ createVoice(input) {
547
+ return client.execute("v1/general/custom-voices", {}, input, extractVoices);
548
+ },
549
+ // ── multi-shot (1 model) ───────────────────────────────────────────────
550
+ multiShot(input) {
551
+ return client.execute("v1/general/ai-multi-shot", {}, input, extractMultiShot);
552
+ },
553
+ // ── reference-to-image (1 model) ───────────────────────────────────────
554
+ referenceToImage(input) {
555
+ return client.execute("v1/images/multi-image2image", { model_name: "kling-v2-1" }, input, extractImages);
556
+ },
557
+ // ── expand-image (1 model) ─────────────────────────────────────────────
558
+ expandImage(input) {
559
+ return client.execute("v1/images/editing/expand", {}, input, extractImages);
560
+ },
561
+ // ── extend-video (1 model) ─────────────────────────────────────────────
562
+ extendVideo(input) {
563
+ return client.execute("v1/videos/video-extend", {}, input, extractVideos);
564
+ },
565
+ // ── identify-face (1 model) ────────────────────────────────────────────
566
+ identifyFace(input) {
567
+ return client.execute("v1/videos/identify-face", {}, input, extractFace, true);
568
+ },
569
+ // ── image-recognize (1 model, sync) ────────────────────────────────────
570
+ imageRecognize(input) {
571
+ return client.execute("v1/videos/image-recognize", {}, input, extractJson, true);
572
+ },
573
+ // ── reference-to-video (1 model) ──────────────────────────────────────
574
+ referenceToVideo(input) {
575
+ return client.execute("v1/videos/multi-image2video", { model_name: "kling-v1-6" }, input, extractVideos);
576
+ },
577
+ // ── account ───────────────────────────────────────────────────────────
578
+ accountCosts(input) {
579
+ return client.accountCosts(input);
580
+ }
581
+ };
582
+ }
583
+
584
+ // src/providers/kling/index.ts
585
+ function createClient(config) {
586
+ const client = new KlingClient();
587
+ client.configure(config);
588
+ return {
589
+ configure: (c) => client.configure(c),
590
+ ...createModels(client)
591
+ };
592
+ }
593
+ var defaultClient = new KlingClient();
594
+ var kling = {
595
+ configure: (config) => defaultClient.configure(config),
596
+ ...createModels(defaultClient)
597
+ };
598
+
599
+ // deprecated/src/configure.ts
32
600
  function configure(options) {
33
601
  if (options.keys) {
34
602
  configureAuth(options.keys);
@@ -43,6 +611,13 @@ function configure(options) {
43
611
  export {
44
612
  AuthError,
45
613
  GetAIApiError,
614
+ KlingApiError,
615
+ KlingAuthError,
616
+ KlingClient,
617
+ KlingError,
618
+ KlingRateLimitError,
619
+ KlingTaskFailedError,
620
+ KlingTimeoutError,
46
621
  ModelNotFoundError,
47
622
  NoProviderError,
48
623
  ProviderError,
@@ -55,9 +630,12 @@ export {
55
630
  configureAuth,
56
631
  configureFetch,
57
632
  configureStorage,
633
+ createClient,
58
634
  deleteAsset,
59
635
  deriveCategory,
60
636
  generate,
637
+ generateJwt,
638
+ kling,
61
639
  klingAdapter,
62
640
  listModels,
63
641
  loadRegistry,