@acedatacloud/sdk 2026.716.0 → 2026.718.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/README.md CHANGED
@@ -113,8 +113,8 @@ try {
113
113
  ```typescript
114
114
  const client = new AceDataCloud({
115
115
  apiToken: 'your-token',
116
- baseUrl: 'https://api.acedata.cloud',
117
- platformBaseUrl: 'https://platform.acedata.cloud',
116
+ baseURL: 'https://x402.acedata.cloud',
117
+ platformBaseURL: 'https://platform.acedata.cloud',
118
118
  timeout: 300000, // ms
119
119
  maxRetries: 2,
120
120
  });
package/dist/index.d.mts CHANGED
@@ -554,30 +554,52 @@ declare class Veo {
554
554
 
555
555
  /** Kling-specific video generation resources. */
556
556
 
557
- type KlingModel = 'kling-v1' | 'kling-v1-6' | 'kling-v2-master' | 'kling-v2-1-master' | 'kling-v2-5-turbo' | 'kling-v2-6' | 'kling-v3' | 'kling-v3-omni' | 'kling-video-o1' | (string & {});
557
+ declare const KLING_MODELS: readonly ["kling-v1", "kling-v1-6", "kling-v2-master", "kling-v2-1-master", "kling-v2-5-turbo", "kling-v2-6", "kling-v3", "kling-v3-omni", "kling-o1"];
558
+ type KlingModel = (typeof KLING_MODELS)[number];
559
+ interface KlingCameraControl {
560
+ type: 'simple' | 'down_back' | 'forward_up' | 'left_turn_forward' | 'right_turn_forward';
561
+ config?: {
562
+ horizontal?: number;
563
+ vertical?: number;
564
+ pan?: number;
565
+ tilt?: number;
566
+ roll?: number;
567
+ zoom?: number;
568
+ };
569
+ }
570
+ interface KlingReferenceImage {
571
+ imageUrl: string;
572
+ type?: 'first_frame' | 'end_frame';
573
+ }
574
+ interface KlingReferenceVideo {
575
+ videoUrl: string;
576
+ referType?: 'base' | 'feature';
577
+ keepOriginalSound?: 'yes' | 'no';
578
+ }
579
+ interface KlingGenerateOptions {
580
+ action: 'text2video' | 'image2video' | 'extend';
581
+ mode?: 'std' | 'pro' | '4k';
582
+ model: KlingModel;
583
+ prompt?: string;
584
+ duration?: number;
585
+ generateAudio?: boolean;
586
+ videoId?: string;
587
+ cfgScale?: number;
588
+ aspectRatio?: '16:9' | '9:16' | '1:1';
589
+ callbackUrl?: string;
590
+ async?: boolean;
591
+ timeout?: number;
592
+ endImageUrl?: string;
593
+ cameraControl?: KlingCameraControl;
594
+ imageList?: KlingReferenceImage[];
595
+ videoList?: KlingReferenceVideo[];
596
+ negativePrompt?: string;
597
+ startImageUrl?: string;
598
+ }
558
599
  declare class Kling {
559
600
  private transport;
560
601
  constructor(transport: Transport);
561
- generate(opts: {
562
- action: 'text2video' | 'image2video' | 'extend';
563
- mode?: 'std' | 'pro' | '4k';
564
- model?: KlingModel;
565
- prompt?: string;
566
- duration?: 5 | 10;
567
- generateAudio?: boolean;
568
- videoId?: string;
569
- cfgScale?: number;
570
- aspectRatio?: '16:9' | '9:16' | '1:1';
571
- callbackUrl?: string;
572
- async?: boolean;
573
- endImageUrl?: string;
574
- cameraControl?: string;
575
- elementList?: unknown[];
576
- videoList?: unknown[];
577
- negativePrompt?: string;
578
- startImageUrl?: string;
579
- [key: string]: unknown;
580
- }): Promise<Record<string, unknown>>;
602
+ generate(opts: KlingGenerateOptions): Promise<Record<string, unknown>>;
581
603
  motion(opts: {
582
604
  mode: 'std' | 'pro';
583
605
  imageUrl: string;
@@ -587,7 +609,6 @@ declare class Kling {
587
609
  prompt?: string;
588
610
  callbackUrl?: string;
589
611
  async?: boolean;
590
- [key: string]: unknown;
591
612
  }): Promise<Record<string, unknown>>;
592
613
  }
593
614
 
@@ -712,4 +733,4 @@ declare class AceDataCloud {
712
733
  constructor(opts?: AceDataCloudOptions);
713
734
  }
714
735
 
715
- export { APIError, AceDataCloud, AceDataCloudError, type AceDataCloudOptions, type AiChatModel, type AudioProvider, AuthenticationError, type GlmModel, type ImageProvider, InsufficientBalanceError, type KlingModel, ModerationError, type PaymentHandler, type PaymentHandlerContext, type PaymentHandlerResult, type PaymentRequiredBody, type PaymentRequirement, RateLimitError, ResourceDisabledError, TaskHandle, type TaskHandleOptions, TimeoutError, TokenMismatchError, TransportError, ValidationError, type VeoModel, type VideoProvider };
736
+ export { APIError, AceDataCloud, AceDataCloudError, type AceDataCloudOptions, type AiChatModel, type AudioProvider, AuthenticationError, type GlmModel, type ImageProvider, InsufficientBalanceError, type KlingCameraControl, type KlingGenerateOptions, type KlingModel, type KlingReferenceImage, type KlingReferenceVideo, ModerationError, type PaymentHandler, type PaymentHandlerContext, type PaymentHandlerResult, type PaymentRequiredBody, type PaymentRequirement, RateLimitError, ResourceDisabledError, TaskHandle, type TaskHandleOptions, TimeoutError, TokenMismatchError, TransportError, ValidationError, type VeoModel, type VideoProvider };
package/dist/index.d.ts CHANGED
@@ -554,30 +554,52 @@ declare class Veo {
554
554
 
555
555
  /** Kling-specific video generation resources. */
556
556
 
557
- type KlingModel = 'kling-v1' | 'kling-v1-6' | 'kling-v2-master' | 'kling-v2-1-master' | 'kling-v2-5-turbo' | 'kling-v2-6' | 'kling-v3' | 'kling-v3-omni' | 'kling-video-o1' | (string & {});
557
+ declare const KLING_MODELS: readonly ["kling-v1", "kling-v1-6", "kling-v2-master", "kling-v2-1-master", "kling-v2-5-turbo", "kling-v2-6", "kling-v3", "kling-v3-omni", "kling-o1"];
558
+ type KlingModel = (typeof KLING_MODELS)[number];
559
+ interface KlingCameraControl {
560
+ type: 'simple' | 'down_back' | 'forward_up' | 'left_turn_forward' | 'right_turn_forward';
561
+ config?: {
562
+ horizontal?: number;
563
+ vertical?: number;
564
+ pan?: number;
565
+ tilt?: number;
566
+ roll?: number;
567
+ zoom?: number;
568
+ };
569
+ }
570
+ interface KlingReferenceImage {
571
+ imageUrl: string;
572
+ type?: 'first_frame' | 'end_frame';
573
+ }
574
+ interface KlingReferenceVideo {
575
+ videoUrl: string;
576
+ referType?: 'base' | 'feature';
577
+ keepOriginalSound?: 'yes' | 'no';
578
+ }
579
+ interface KlingGenerateOptions {
580
+ action: 'text2video' | 'image2video' | 'extend';
581
+ mode?: 'std' | 'pro' | '4k';
582
+ model: KlingModel;
583
+ prompt?: string;
584
+ duration?: number;
585
+ generateAudio?: boolean;
586
+ videoId?: string;
587
+ cfgScale?: number;
588
+ aspectRatio?: '16:9' | '9:16' | '1:1';
589
+ callbackUrl?: string;
590
+ async?: boolean;
591
+ timeout?: number;
592
+ endImageUrl?: string;
593
+ cameraControl?: KlingCameraControl;
594
+ imageList?: KlingReferenceImage[];
595
+ videoList?: KlingReferenceVideo[];
596
+ negativePrompt?: string;
597
+ startImageUrl?: string;
598
+ }
558
599
  declare class Kling {
559
600
  private transport;
560
601
  constructor(transport: Transport);
561
- generate(opts: {
562
- action: 'text2video' | 'image2video' | 'extend';
563
- mode?: 'std' | 'pro' | '4k';
564
- model?: KlingModel;
565
- prompt?: string;
566
- duration?: 5 | 10;
567
- generateAudio?: boolean;
568
- videoId?: string;
569
- cfgScale?: number;
570
- aspectRatio?: '16:9' | '9:16' | '1:1';
571
- callbackUrl?: string;
572
- async?: boolean;
573
- endImageUrl?: string;
574
- cameraControl?: string;
575
- elementList?: unknown[];
576
- videoList?: unknown[];
577
- negativePrompt?: string;
578
- startImageUrl?: string;
579
- [key: string]: unknown;
580
- }): Promise<Record<string, unknown>>;
602
+ generate(opts: KlingGenerateOptions): Promise<Record<string, unknown>>;
581
603
  motion(opts: {
582
604
  mode: 'std' | 'pro';
583
605
  imageUrl: string;
@@ -587,7 +609,6 @@ declare class Kling {
587
609
  prompt?: string;
588
610
  callbackUrl?: string;
589
611
  async?: boolean;
590
- [key: string]: unknown;
591
612
  }): Promise<Record<string, unknown>>;
592
613
  }
593
614
 
@@ -712,4 +733,4 @@ declare class AceDataCloud {
712
733
  constructor(opts?: AceDataCloudOptions);
713
734
  }
714
735
 
715
- export { APIError, AceDataCloud, AceDataCloudError, type AceDataCloudOptions, type AiChatModel, type AudioProvider, AuthenticationError, type GlmModel, type ImageProvider, InsufficientBalanceError, type KlingModel, ModerationError, type PaymentHandler, type PaymentHandlerContext, type PaymentHandlerResult, type PaymentRequiredBody, type PaymentRequirement, RateLimitError, ResourceDisabledError, TaskHandle, type TaskHandleOptions, TimeoutError, TokenMismatchError, TransportError, ValidationError, type VeoModel, type VideoProvider };
736
+ export { APIError, AceDataCloud, AceDataCloudError, type AceDataCloudOptions, type AiChatModel, type AudioProvider, AuthenticationError, type GlmModel, type ImageProvider, InsufficientBalanceError, type KlingCameraControl, type KlingGenerateOptions, type KlingModel, type KlingReferenceImage, type KlingReferenceVideo, ModerationError, type PaymentHandler, type PaymentHandlerContext, type PaymentHandlerResult, type PaymentRequiredBody, type PaymentRequirement, RateLimitError, ResourceDisabledError, TaskHandle, type TaskHandleOptions, TimeoutError, TokenMismatchError, TransportError, ValidationError, type VeoModel, type VideoProvider };
package/dist/index.js CHANGED
@@ -163,6 +163,16 @@ function backoffDelay(attempt) {
163
163
  function sleep(ms) {
164
164
  return new Promise((resolve) => setTimeout(resolve, ms));
165
165
  }
166
+ function isAbortError(error) {
167
+ return typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
168
+ }
169
+ function timeoutError(error) {
170
+ return new TimeoutError({
171
+ message: `Request timed out${error instanceof Error && error.message ? `: ${error.message}` : ""}`,
172
+ statusCode: 0,
173
+ code: "timeout"
174
+ });
175
+ }
166
176
  var Transport = class {
167
177
  baseURL;
168
178
  platformBaseURL;
@@ -179,7 +189,7 @@ var Transport = class {
179
189
  code: "no_token"
180
190
  });
181
191
  }
182
- this.baseURL = (opts.baseURL ?? "https://api.acedata.cloud").replace(/\/+$/, "");
192
+ this.baseURL = (opts.baseURL ?? "https://x402.acedata.cloud").replace(/\/+$/, "");
183
193
  this.platformBaseURL = (opts.platformBaseURL ?? "https://platform.acedata.cloud").replace(/\/+$/, "");
184
194
  this.timeout = opts.timeout ?? 3e5;
185
195
  this.maxRetries = opts.maxRetries ?? 2;
@@ -207,7 +217,8 @@ var Transport = class {
207
217
  let lastError = null;
208
218
  let paymentAttempted = false;
209
219
  let extraHeaders = {};
210
- for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
220
+ let attempt = 0;
221
+ while (true) {
211
222
  const controller = new AbortController();
212
223
  const timer = setTimeout(() => controller.abort(), timeoutMs);
213
224
  try {
@@ -226,14 +237,17 @@ var Transport = class {
226
237
  } catch {
227
238
  throw mapError(402, { error: { code: "invalid_402", message: text } });
228
239
  }
229
- if (!body.accepts?.length) {
240
+ if (!body || typeof body !== "object" || !Array.isArray(body.accepts) || !body.accepts.length || !body.accepts.every(
241
+ (requirement) => requirement !== null && typeof requirement === "object"
242
+ )) {
230
243
  throw mapError(402, { error: { code: "invalid_402", message: "No payment requirements" } });
231
244
  }
245
+ const paymentRequired = body;
232
246
  const result = await this.paymentHandler({
233
247
  url,
234
248
  method,
235
249
  body: opts.json,
236
- accepts: body.accepts
250
+ accepts: paymentRequired.accepts
237
251
  });
238
252
  extraHeaders = { ...extraHeaders, ...result.headers };
239
253
  paymentAttempted = true;
@@ -247,8 +261,9 @@ var Transport = class {
247
261
  } catch {
248
262
  body = { error: { code: "unknown", message: text } };
249
263
  }
250
- if (RETRY_STATUS_CODES.has(resp.status) && attempt < this.maxRetries) {
264
+ if (!paymentAttempted && RETRY_STATUS_CODES.has(resp.status) && attempt < this.maxRetries) {
251
265
  await sleep(backoffDelay(attempt) * 1e3);
266
+ attempt += 1;
252
267
  continue;
253
268
  }
254
269
  throw mapError(resp.status, body);
@@ -257,57 +272,117 @@ var Transport = class {
257
272
  } catch (err) {
258
273
  clearTimeout(timer);
259
274
  if (err instanceof APIError) throw err;
260
- lastError = err;
261
- if (attempt < this.maxRetries) {
275
+ if (isAbortError(err)) {
276
+ lastError = timeoutError(err);
277
+ } else {
278
+ lastError = err;
279
+ }
280
+ if (!paymentAttempted && attempt < this.maxRetries) {
262
281
  await sleep(backoffDelay(attempt) * 1e3);
282
+ attempt += 1;
263
283
  continue;
264
284
  }
285
+ throw lastError;
265
286
  }
266
287
  }
267
- throw lastError ?? new TransportError("Request failed after retries");
268
288
  }
269
289
  async *requestStream(method, path2, opts = {}) {
270
290
  const url = `${this.baseURL}${path2}`;
271
291
  const headers = { ...this.headers, accept: "text/event-stream" };
272
- const controller = new AbortController();
273
- const timer = setTimeout(() => controller.abort(), opts.timeout ?? this.timeout);
274
- try {
275
- const resp = await fetch(url, {
276
- method,
277
- headers,
278
- body: opts.json ? JSON.stringify(opts.json) : void 0,
279
- signal: controller.signal
280
- });
281
- if (resp.status >= 400) {
282
- const text = await resp.text();
283
- let body;
292
+ let paymentAttempted = false;
293
+ let extraHeaders = {};
294
+ while (true) {
295
+ const controller = new AbortController();
296
+ const timeoutMs = opts.timeout ?? this.timeout;
297
+ const connectionTimer = setTimeout(() => controller.abort(), timeoutMs);
298
+ try {
299
+ let resp;
284
300
  try {
285
- body = JSON.parse(text);
286
- } catch {
287
- body = { error: { code: "unknown", message: text } };
301
+ resp = await fetch(url, {
302
+ method,
303
+ headers: { ...headers, ...extraHeaders },
304
+ body: opts.json ? JSON.stringify(opts.json) : void 0,
305
+ signal: controller.signal
306
+ });
307
+ } catch (error) {
308
+ if (isAbortError(error)) throw timeoutError(error);
309
+ throw error;
310
+ } finally {
311
+ clearTimeout(connectionTimer);
288
312
  }
289
- throw mapError(resp.status, body);
290
- }
291
- if (!resp.body) throw new TransportError("No response body for stream");
292
- const reader = resp.body.getReader();
293
- const decoder = new TextDecoder();
294
- let buffer = "";
295
- while (true) {
296
- const { done, value } = await reader.read();
297
- if (done) break;
298
- buffer += decoder.decode(value, { stream: true });
299
- const lines = buffer.split("\n");
300
- buffer = lines.pop() ?? "";
301
- for (const line of lines) {
302
- if (line.startsWith("data: ")) {
303
- const data = line.slice(6);
304
- if (data === "[DONE]") return;
305
- yield data;
313
+ if (resp.status === 402 && this.paymentHandler && !paymentAttempted) {
314
+ const text = await resp.text();
315
+ let body;
316
+ try {
317
+ body = JSON.parse(text);
318
+ } catch {
319
+ throw mapError(402, { error: { code: "invalid_402", message: text } });
320
+ }
321
+ if (!body || typeof body !== "object" || !Array.isArray(body.accepts) || !body.accepts.length || !body.accepts.every(
322
+ (requirement) => requirement !== null && typeof requirement === "object"
323
+ )) {
324
+ throw mapError(402, { error: { code: "invalid_402", message: "No payment requirements" } });
306
325
  }
326
+ const paymentRequired = body;
327
+ const result = await this.paymentHandler({
328
+ url,
329
+ method,
330
+ body: opts.json,
331
+ accepts: paymentRequired.accepts
332
+ });
333
+ extraHeaders = { ...extraHeaders, ...result.headers };
334
+ paymentAttempted = true;
335
+ continue;
307
336
  }
337
+ if (resp.status >= 400) {
338
+ const text = await resp.text();
339
+ let body;
340
+ try {
341
+ body = JSON.parse(text);
342
+ } catch {
343
+ body = { error: { code: "unknown", message: text } };
344
+ }
345
+ throw mapError(resp.status, body);
346
+ }
347
+ if (!resp.body) throw new TransportError("No response body for stream");
348
+ const reader = resp.body.getReader();
349
+ const decoder = new TextDecoder();
350
+ let buffer = "";
351
+ try {
352
+ while (true) {
353
+ const idleTimer = setTimeout(() => controller.abort(), timeoutMs);
354
+ let result;
355
+ try {
356
+ result = await reader.read();
357
+ } catch (error) {
358
+ if (isAbortError(error)) throw timeoutError(error);
359
+ throw error;
360
+ } finally {
361
+ clearTimeout(idleTimer);
362
+ }
363
+ const { done, value } = result;
364
+ if (done) break;
365
+ buffer += decoder.decode(value, { stream: true });
366
+ const lines = buffer.split("\n");
367
+ buffer = lines.pop() ?? "";
368
+ for (const line of lines) {
369
+ if (line.startsWith("data: ")) {
370
+ const data = line.slice(6);
371
+ if (data === "[DONE]") return;
372
+ yield data;
373
+ }
374
+ }
375
+ }
376
+ } finally {
377
+ try {
378
+ await reader.cancel();
379
+ } catch {
380
+ }
381
+ }
382
+ return;
383
+ } finally {
384
+ clearTimeout(connectionTimer);
308
385
  }
309
- } finally {
310
- clearTimeout(timer);
311
386
  }
312
387
  }
313
388
  async upload(path2, fileData, filename, opts = {}) {
@@ -327,12 +402,18 @@ var Transport = class {
327
402
  const controller = new AbortController();
328
403
  const timer = setTimeout(() => controller.abort(), opts.timeout ?? this.timeout);
329
404
  try {
330
- const resp = await fetch(url, {
331
- method: "POST",
332
- headers: authHeaders,
333
- body,
334
- signal: controller.signal
335
- });
405
+ let resp;
406
+ try {
407
+ resp = await fetch(url, {
408
+ method: "POST",
409
+ headers: authHeaders,
410
+ body,
411
+ signal: controller.signal
412
+ });
413
+ } catch (error) {
414
+ if (isAbortError(error)) throw timeoutError(error);
415
+ throw error;
416
+ }
336
417
  clearTimeout(timer);
337
418
  if (resp.status >= 400) {
338
419
  const text = await resp.text();
@@ -904,12 +985,148 @@ var Veo = class {
904
985
  };
905
986
 
906
987
  // src/resources/kling.ts
988
+ var KLING_MODELS = [
989
+ "kling-v1",
990
+ "kling-v1-6",
991
+ "kling-v2-master",
992
+ "kling-v2-1-master",
993
+ "kling-v2-5-turbo",
994
+ "kling-v2-6",
995
+ "kling-v3",
996
+ "kling-v3-omni",
997
+ "kling-o1"
998
+ ];
999
+ function isHttpUrl(value) {
1000
+ try {
1001
+ const url = new URL(value);
1002
+ return url.protocol === "http:" || url.protocol === "https:";
1003
+ } catch {
1004
+ return false;
1005
+ }
1006
+ }
1007
+ function validateGenerateOptions(opts) {
1008
+ if (!KLING_MODELS.includes(opts.model)) {
1009
+ throw new Error(`model must be one of: ${KLING_MODELS.join(", ")}`);
1010
+ }
1011
+ const isV3 = opts.model === "kling-v3" || opts.model === "kling-v3-omni";
1012
+ const hasReferences = Boolean(opts.imageList?.length || opts.videoList?.length);
1013
+ if (opts.imageList !== void 0 && opts.imageList.length === 0) {
1014
+ throw new Error("imageList must be non-empty or omitted");
1015
+ }
1016
+ if (opts.videoList !== void 0 && opts.videoList.length === 0) {
1017
+ throw new Error("videoList must be non-empty or omitted");
1018
+ }
1019
+ if ((opts.action === "text2video" || opts.action === "image2video") && !opts.prompt) {
1020
+ throw new Error("prompt is required for text2video and image2video");
1021
+ }
1022
+ if (opts.action === "image2video" && !opts.startImageUrl) {
1023
+ throw new Error("startImageUrl is required for image2video");
1024
+ }
1025
+ if (opts.action === "extend" && !opts.videoId) {
1026
+ throw new Error("videoId is required for extend");
1027
+ }
1028
+ if (opts.endImageUrl && !opts.startImageUrl) {
1029
+ throw new Error("startImageUrl is required with endImageUrl");
1030
+ }
1031
+ if (opts.startImageUrl && !isHttpUrl(opts.startImageUrl)) {
1032
+ throw new Error("startImageUrl must be an HTTP URL");
1033
+ }
1034
+ if (opts.endImageUrl && !isHttpUrl(opts.endImageUrl)) {
1035
+ throw new Error("endImageUrl must be an HTTP URL");
1036
+ }
1037
+ if (opts.callbackUrl && !isHttpUrl(opts.callbackUrl)) {
1038
+ throw new Error("callbackUrl must be an HTTP URL");
1039
+ }
1040
+ if (opts.cfgScale !== void 0 && (opts.cfgScale < 0 || opts.cfgScale > 1)) {
1041
+ throw new Error("cfgScale must be between 0 and 1");
1042
+ }
1043
+ if (opts.duration !== void 0 && !Number.isInteger(opts.duration)) {
1044
+ throw new Error("duration must be an integer");
1045
+ }
1046
+ if (isV3 && opts.duration !== void 0 && (opts.duration < 3 || opts.duration > 15)) {
1047
+ throw new Error("Kling V3 duration must be between 3 and 15 seconds");
1048
+ }
1049
+ if (!isV3 && opts.model !== "kling-o1" && opts.duration !== void 0 && ![5, 10].includes(opts.duration)) {
1050
+ throw new Error("This Kling model supports only 5- or 10-second generation");
1051
+ }
1052
+ if (opts.model === "kling-o1" && opts.duration !== void 0 && opts.duration !== 5) {
1053
+ throw new Error("kling-o1 supports only 5-second generation");
1054
+ }
1055
+ if (opts.model === "kling-o1" && opts.mode !== void 0 && !["std", "pro"].includes(opts.mode)) {
1056
+ throw new Error("kling-o1 supports only std and pro modes");
1057
+ }
1058
+ if (opts.mode === "4k" && !isV3) {
1059
+ throw new Error("4k mode requires kling-v3 or kling-v3-omni");
1060
+ }
1061
+ if (opts.action === "extend" && !["kling-v1", "kling-v1-6", "kling-v2-5-turbo"].includes(opts.model)) {
1062
+ throw new Error("extend requires kling-v1, kling-v1-6, or kling-v2-5-turbo");
1063
+ }
1064
+ if (opts.action === "extend" && hasReferences) {
1065
+ throw new Error("imageList and videoList are not supported with extend");
1066
+ }
1067
+ if (hasReferences && opts.model !== "kling-o1" && opts.model !== "kling-v3-omni") {
1068
+ throw new Error("Omni references require kling-o1 or kling-v3-omni");
1069
+ }
1070
+ if (hasReferences && opts.mode === "4k") {
1071
+ throw new Error("4k cannot be combined with Omni references");
1072
+ }
1073
+ if ((opts.model === "kling-o1" || hasReferences) && (opts.negativePrompt !== void 0 || opts.cameraControl !== void 0 || opts.cfgScale !== void 0)) {
1074
+ throw new Error("Kling O1 and Omni references do not support negativePrompt, cameraControl, or cfgScale");
1075
+ }
1076
+ if (opts.model === "kling-o1" && opts.generateAudio) {
1077
+ throw new Error("kling-o1 does not support generateAudio");
1078
+ }
1079
+ if (opts.generateAudio && !isV3 && opts.model !== "kling-v2-6") {
1080
+ throw new Error("generateAudio requires a V3 model or kling-v2-6 pro mode");
1081
+ }
1082
+ if (opts.generateAudio && opts.model === "kling-v2-6" && opts.mode !== "pro") {
1083
+ throw new Error("kling-v2-6 supports generateAudio only in pro mode");
1084
+ }
1085
+ if (opts.generateAudio && opts.videoList?.length) {
1086
+ throw new Error("generateAudio cannot be used with videoList");
1087
+ }
1088
+ if (opts.videoList && (opts.videoList.length === 0 || opts.videoList.length > 1)) {
1089
+ throw new Error("videoList must contain exactly one reference video");
1090
+ }
1091
+ for (const image of opts.imageList ?? []) {
1092
+ if (!isHttpUrl(image.imageUrl)) throw new Error("Every reference image requires an HTTP imageUrl");
1093
+ if (image.type !== void 0 && !["first_frame", "end_frame"].includes(image.type)) {
1094
+ throw new Error("Reference image type must be first_frame or end_frame");
1095
+ }
1096
+ }
1097
+ for (const video of opts.videoList ?? []) {
1098
+ if (!isHttpUrl(video.videoUrl)) throw new Error("Every reference video requires an HTTP videoUrl");
1099
+ if (video.referType !== void 0 && !["base", "feature"].includes(video.referType)) {
1100
+ throw new Error("Reference video referType must be base or feature");
1101
+ }
1102
+ if (video.keepOriginalSound !== void 0 && !["yes", "no"].includes(video.keepOriginalSound)) {
1103
+ throw new Error("Reference video keepOriginalSound must be yes or no");
1104
+ }
1105
+ }
1106
+ const firstFrames = Number(Boolean(opts.startImageUrl)) + (opts.imageList ?? []).filter((item) => item.type === "first_frame").length;
1107
+ const endFrames = Number(Boolean(opts.endImageUrl)) + (opts.imageList ?? []).filter((item) => item.type === "end_frame").length;
1108
+ if (firstFrames > 1 || endFrames > 1) {
1109
+ throw new Error("Only one first frame and one end frame are allowed");
1110
+ }
1111
+ if (endFrames > 0 && firstFrames === 0) {
1112
+ throw new Error("A first frame is required with an end frame");
1113
+ }
1114
+ if ((opts.videoList?.[0]?.referType ?? "base") === "base" && opts.videoList?.length && (firstFrames > 0 || endFrames > 0)) {
1115
+ throw new Error("A base reference video cannot be combined with first or end frames");
1116
+ }
1117
+ const imageCount = (opts.imageList?.length ?? 0) + Number(Boolean(opts.startImageUrl)) + Number(Boolean(opts.endImageUrl));
1118
+ const imageLimit = opts.videoList?.length ? 4 : 7;
1119
+ if (imageCount > imageLimit) {
1120
+ throw new Error(`Reference images cannot exceed ${imageLimit} for this request`);
1121
+ }
1122
+ }
907
1123
  var Kling = class {
908
1124
  constructor(transport) {
909
1125
  this.transport = transport;
910
1126
  }
911
1127
  transport;
912
1128
  async generate(opts) {
1129
+ validateGenerateOptions(opts);
913
1130
  const {
914
1131
  action,
915
1132
  mode,
@@ -921,15 +1138,16 @@ var Kling = class {
921
1138
  cfgScale,
922
1139
  aspectRatio,
923
1140
  callbackUrl,
1141
+ async: asyncMode,
1142
+ timeout,
924
1143
  endImageUrl,
925
1144
  cameraControl,
926
- elementList,
1145
+ imageList,
927
1146
  videoList,
928
1147
  negativePrompt,
929
- startImageUrl,
930
- ...rest
1148
+ startImageUrl
931
1149
  } = opts;
932
- const body = { action, ...rest };
1150
+ const body = { action };
933
1151
  if (mode !== void 0) body.mode = mode;
934
1152
  if (model !== void 0) body.model = model;
935
1153
  if (prompt !== void 0) body.prompt = prompt;
@@ -939,26 +1157,46 @@ var Kling = class {
939
1157
  if (cfgScale !== void 0) body.cfg_scale = cfgScale;
940
1158
  if (aspectRatio !== void 0) body.aspect_ratio = aspectRatio;
941
1159
  if (callbackUrl !== void 0) body.callback_url = callbackUrl;
1160
+ if (asyncMode !== void 0) body.async = asyncMode;
1161
+ if (timeout !== void 0) body.timeout = timeout;
942
1162
  if (endImageUrl !== void 0) body.end_image_url = endImageUrl;
943
1163
  if (cameraControl !== void 0) body.camera_control = cameraControl;
944
- if (elementList !== void 0) body.element_list = elementList;
945
- if (videoList !== void 0) body.video_list = videoList;
1164
+ if (imageList !== void 0) {
1165
+ body.image_list = imageList.map(({ imageUrl, type }) => ({ image_url: imageUrl, ...type ? { type } : {} }));
1166
+ }
1167
+ if (videoList !== void 0) {
1168
+ body.video_list = videoList.map(({ videoUrl, referType, keepOriginalSound }) => ({
1169
+ video_url: videoUrl,
1170
+ ...referType ? { refer_type: referType } : {},
1171
+ ...keepOriginalSound ? { keep_original_sound: keepOriginalSound } : {}
1172
+ }));
1173
+ }
946
1174
  if (negativePrompt !== void 0) body.negative_prompt = negativePrompt;
947
1175
  if (startImageUrl !== void 0) body.start_image_url = startImageUrl;
948
1176
  return this.transport.request("POST", "/kling/videos", { json: body });
949
1177
  }
950
1178
  async motion(opts) {
951
- const { mode, imageUrl, videoUrl, characterOrientation, keepOriginalSound, prompt, callbackUrl, ...rest } = opts;
1179
+ const { mode, imageUrl, videoUrl, characterOrientation, keepOriginalSound, prompt, callbackUrl } = opts;
1180
+ if (!["std", "pro"].includes(mode)) throw new Error("mode must be std or pro");
1181
+ if (!isHttpUrl(imageUrl)) throw new Error("imageUrl must be an HTTP URL");
1182
+ if (!isHttpUrl(videoUrl)) throw new Error("videoUrl must be an HTTP URL");
1183
+ if (!["image", "video"].includes(characterOrientation)) {
1184
+ throw new Error("characterOrientation must be image or video");
1185
+ }
1186
+ if (keepOriginalSound !== void 0 && !["yes", "no"].includes(keepOriginalSound)) {
1187
+ throw new Error("keepOriginalSound must be yes or no");
1188
+ }
1189
+ if (callbackUrl && !isHttpUrl(callbackUrl)) throw new Error("callbackUrl must be an HTTP URL");
952
1190
  const body = {
953
1191
  mode,
954
1192
  image_url: imageUrl,
955
1193
  video_url: videoUrl,
956
- character_orientation: characterOrientation,
957
- ...rest
1194
+ character_orientation: characterOrientation
958
1195
  };
959
1196
  if (keepOriginalSound !== void 0) body.keep_original_sound = keepOriginalSound;
960
1197
  if (prompt !== void 0) body.prompt = prompt;
961
1198
  if (callbackUrl !== void 0) body.callback_url = callbackUrl;
1199
+ if (opts.async !== void 0) body.async = opts.async;
962
1200
  return this.transport.request("POST", "/kling/motion", { json: body });
963
1201
  }
964
1202
  };