@mynthio/sdk 0.0.53 → 0.0.55

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
@@ -640,6 +640,7 @@ Current model IDs include:
640
640
  - `auto`
641
641
  - `alibaba/qwen-image-2.0`
642
642
  - `alibaba/qwen-image-2.0-pro`
643
+ - `alibaba/qwen-image-2.1-pro`
643
644
  - `alibaba/qwen-image-2.1-turbo`
644
645
  - `alibaba/qwen-image-3.0`
645
646
  - `alibaba/qwen-image-3.0-pro`
@@ -658,6 +659,7 @@ Current model IDs include:
658
659
  - `google/gemini-3.1-flash-lite-image`
659
660
  - `google/gemini-3.1-flash-image`
660
661
  - `google/gemini-3-pro-image-preview`
662
+ - `google/gemini-nano-banana-2.1`
661
663
  - `imagineart/imagineart-1.5-pro`
662
664
  - `imagineart/imagineart-2.0`
663
665
  - `ideogram/ideogram-4.5`
@@ -822,12 +824,13 @@ console.log(model);
822
824
  // }
823
825
  ```
824
826
 
825
- | Model | Resolutions | Duration (s) | Inputs |
826
- | ------------------------------ | ----------------- | ---------------- | ----------------------- |
827
- | `bytedance/seedance-2.0-mini` | 480p, 720p | 4–15 (default 5) | first frame, last frame |
828
- | `google/gemini-omni-flash-1.1` | 720p, 1080p, 4k | 3–10 (default 8) | first frame, last frame |
829
- | `prunaai/p-video` | 720p, 1080p | 1–10 (default 5) | first frame |
830
- | `xai/grok-imagine-video-1.5` | 480p, 720p, 1080p | 1–15 (default 8) | first frame |
827
+ | Model | Resolutions | Duration (s) | Inputs |
828
+ | --------------------------------- | ----------------- | ---------------- | ----------------------- |
829
+ | `bytedance/seedance-2.0-mini` | 480p, 720p | 4–15 (default 5) | first frame, last frame |
830
+ | `google/gemini-omni-flash-1.1` | 720p, 1080p, 4k | 3–10 (default 8) | first frame, last frame |
831
+ | `prunaai/p-video` | 720p, 1080p | 1–10 (default 5) | first frame |
832
+ | `xai/grok-imagine-video-1.5` | 480p, 720p, 1080p | 1–15 (default 8) | first frame |
833
+ | `xai/grok-imagine-video-1.5-lite` | 480p, 720p, 1080p | 1–15 (default 6) | first frame |
831
834
 
832
835
  Each of these supports generated audio.
833
836
 
package/dist/index.d.ts CHANGED
@@ -45,6 +45,14 @@ declare class MynthClient {
45
45
  getAuthHeaders(override?: Pick<MynthClientRequestOptions, "accessToken" | "auth">): Record<string, string>;
46
46
  getUrl(path: string): string;
47
47
  post<DataType>(path: string, data: unknown, { signal }?: Pick<MynthClientRequestOptions, "signal">): Promise<DataType>;
48
+ /**
49
+ * Creates a task. Sends `X-Mynth-Client` and an `Idempotency-Key` (the
50
+ * caller's, or a fresh one), and retries with the same key when the request
51
+ * fails in transit or with a 5xx, so a retry never creates a second task.
52
+ */
53
+ createTask<DataType>(path: string, data: unknown, { signal, idempotencyKey }?: Pick<MynthClientRequestOptions, "signal"> & {
54
+ idempotencyKey?: string | undefined;
55
+ }): Promise<DataType>;
48
56
  get<DataType>(path: string, { headers, accessToken, auth, signal }?: MynthClientRequestOptions): Promise<{
49
57
  data: DataType;
50
58
  status: number;
@@ -238,6 +246,14 @@ type MynthRequestOptions = {
238
246
  * created keeps running on Mynth.
239
247
  */
240
248
  signal?: AbortSignal | undefined;
249
+ /**
250
+ * Sent as the `Idempotency-Key` header of the create. By default every call
251
+ * gets a fresh key, which the SDK reuses when it retries a create that failed
252
+ * in transit or with a 5xx, so a retry never creates or charges a second
253
+ * task. Pass your own to make your retries of the same logical request safe
254
+ * too: the same key with the same request returns the original task.
255
+ */
256
+ idempotencyKey?: string | undefined;
241
257
  };
242
258
  type MynthModel = MynthSDKTypes.Model;
243
259
  type MynthModelPricing = MynthSDKTypes.ModelPricing;
package/dist/index.js CHANGED
@@ -39,6 +39,11 @@ const AVAILABLE_MODELS = [
39
39
  label: "Qwen Image 2.0 Pro",
40
40
  capabilities: ["inputs"]
41
41
  },
42
+ {
43
+ id: "alibaba/qwen-image-2.1-pro",
44
+ label: "Qwen Image 2.1 Pro",
45
+ capabilities: ["inputs"]
46
+ },
42
47
  {
43
48
  id: "alibaba/qwen-image-2.1-turbo",
44
49
  label: "Qwen Image 2.1 Turbo",
@@ -259,6 +264,11 @@ const AVAILABLE_MODELS = [
259
264
  label: "Nano Banana Pro",
260
265
  capabilities: ["inputs", "4k"]
261
266
  },
267
+ {
268
+ id: "google/gemini-nano-banana-2.1",
269
+ label: "Gemini Nano Banana 2.1",
270
+ capabilities: ["inputs", "4k"]
271
+ },
262
272
  {
263
273
  id: "imagineart/imagineart-1.5-pro",
264
274
  label: "ImagineArt 1.5 Pro",
@@ -289,6 +299,26 @@ const AVAILABLE_MODELS = [
289
299
  label: "GPT Image 2.5 Sunburst",
290
300
  capabilities: ["inputs"]
291
301
  },
302
+ {
303
+ id: "openai/gpt-image-2.6-flare",
304
+ label: "GPT Image 2.6 Flare",
305
+ capabilities: ["inputs"]
306
+ },
307
+ {
308
+ id: "openai/gpt-image-2.6-sunburst",
309
+ label: "GPT Image 2.6 Sunburst",
310
+ capabilities: ["inputs"]
311
+ },
312
+ {
313
+ id: "openai/gpt-image-flare",
314
+ label: "GPT Image Flare",
315
+ capabilities: ["inputs"]
316
+ },
317
+ {
318
+ id: "openai/gpt-image-sunburst",
319
+ label: "GPT Image Sunburst",
320
+ capabilities: ["inputs"]
321
+ },
292
322
  {
293
323
  id: "wan/wan2.6-image",
294
324
  label: "Wan 2.6 Image",
@@ -400,6 +430,24 @@ const AVAILABLE_VIDEO_MODELS = [
400
430
  audio: true,
401
431
  inputs: ["first_frame"],
402
432
  maxInputs: 1
433
+ },
434
+ {
435
+ id: "xai/grok-imagine-video-1.5-lite",
436
+ label: "Grok Imagine Video 1.5 Lite",
437
+ resolutions: [
438
+ "480p",
439
+ "720p",
440
+ "1080p"
441
+ ],
442
+ defaultResolution: "480p",
443
+ duration: {
444
+ default: 6,
445
+ min: 1,
446
+ max: 15
447
+ },
448
+ audio: true,
449
+ inputs: ["first_frame"],
450
+ maxInputs: 1
403
451
  }
404
452
  ];
405
453
  //#endregion
@@ -431,6 +479,50 @@ var MynthAPIError = class extends Error {
431
479
  this.taskId = taskId;
432
480
  }
433
481
  };
482
+ /**
483
+ * Sent as `X-Mynth-Client` on creates so Mynth can count SDK traffic. The API
484
+ * only records it, never checks it. The build inlines the package version.
485
+ */
486
+ const SDK_CLIENT = `sdk/0.0.55`;
487
+ /**
488
+ * Waits before each retry of a create that failed in transit or with a 5xx.
489
+ * The retry sends the same `Idempotency-Key`, so Mynth returns the task the
490
+ * first attempt made, if it made one, instead of creating and charging another.
491
+ */
492
+ const CREATE_RETRY_DELAYS_MS = [500, 2e3];
493
+ /** Statuses a create may answer while the API is restarting or overloaded. */
494
+ const RETRYABLE_STATUSES = /* @__PURE__ */ new Set([
495
+ 500,
496
+ 502,
497
+ 503,
498
+ 504
499
+ ]);
500
+ /** A fresh `Idempotency-Key`: one per logical create, reused by its retries. */
501
+ function createIdempotencyKey() {
502
+ const crypto = globalThis.crypto;
503
+ if (typeof crypto?.randomUUID === "function") return crypto.randomUUID();
504
+ const bytes = /* @__PURE__ */ new Uint8Array(16);
505
+ if (typeof crypto?.getRandomValues === "function") crypto.getRandomValues(bytes);
506
+ else for (let index = 0; index < bytes.length; index++) bytes[index] = Math.floor(Math.random() * 256);
507
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
508
+ }
509
+ function wait(ms, signal) {
510
+ return new Promise((resolve, reject) => {
511
+ if (signal?.aborted) {
512
+ reject(signal.reason);
513
+ return;
514
+ }
515
+ const onAbort = () => {
516
+ clearTimeout(timer);
517
+ reject(signal?.reason);
518
+ };
519
+ const timer = setTimeout(() => {
520
+ signal?.removeEventListener("abort", onAbort);
521
+ resolve();
522
+ }, ms);
523
+ signal?.addEventListener("abort", onAbort, { once: true });
524
+ });
525
+ }
434
526
  function createApiError(data, status) {
435
527
  const body = typeof data === "object" && data !== null ? data : {};
436
528
  const error = typeof body.error === "object" && body.error !== null ? body.error : {};
@@ -477,6 +569,42 @@ var MynthClient = class {
477
569
  if (!response.ok) throw createApiError(await readErrorBody(response), response.status);
478
570
  return await response.json();
479
571
  }
572
+ /**
573
+ * Creates a task. Sends `X-Mynth-Client` and an `Idempotency-Key` (the
574
+ * caller's, or a fresh one), and retries with the same key when the request
575
+ * fails in transit or with a 5xx, so a retry never creates a second task.
576
+ */
577
+ async createTask(path, data, { signal, idempotencyKey = createIdempotencyKey() } = {}) {
578
+ const body = JSON.stringify(data);
579
+ for (let attempt = 0;; attempt++) {
580
+ const delay = CREATE_RETRY_DELAYS_MS[attempt];
581
+ let response;
582
+ try {
583
+ response = await fetch(this.getUrl(path), {
584
+ method: "POST",
585
+ headers: {
586
+ "Content-Type": "application/json",
587
+ "Idempotency-Key": idempotencyKey,
588
+ "X-Mynth-Client": SDK_CLIENT,
589
+ ...this.getAuthHeaders()
590
+ },
591
+ body,
592
+ ...signal ? { signal } : {}
593
+ });
594
+ } catch (error) {
595
+ if (signal?.aborted || delay === void 0) throw error;
596
+ await wait(delay, signal);
597
+ continue;
598
+ }
599
+ if (response.ok) return await response.json();
600
+ if (RETRYABLE_STATUSES.has(response.status) && delay !== void 0) {
601
+ await response.body?.cancel();
602
+ await wait(delay, signal);
603
+ continue;
604
+ }
605
+ throw createApiError(await readErrorBody(response), response.status);
606
+ }
607
+ }
480
608
  async get(path, { headers, accessToken, auth, signal } = {}) {
481
609
  const response = await fetch(this.getUrl(path), {
482
610
  headers: {
@@ -1015,13 +1143,16 @@ var MynthImage = class {
1015
1143
  async generateAsync(request, options = {}) {
1016
1144
  return this.createGenerationTask(request, options);
1017
1145
  }
1018
- async createGenerationTask(request, { signal }) {
1146
+ async createGenerationTask(request, { signal, idempotencyKey }) {
1019
1147
  const inputs = await resolveInputs(this.client, request.inputs, { signal });
1020
- const data = (await this.client.post(GENERATE_IMAGE_PATH, {
1148
+ const data = (await this.client.createTask(GENERATE_IMAGE_PATH, {
1021
1149
  ...request,
1022
1150
  inputs,
1023
1151
  destination: request.destination ?? this.defaultDestination
1024
- }, { signal })).data;
1152
+ }, {
1153
+ signal,
1154
+ idempotencyKey
1155
+ })).data;
1025
1156
  return new TaskAsync(data.task_id, {
1026
1157
  client: this.client,
1027
1158
  pat: data.public_access_token,
@@ -1088,7 +1219,7 @@ var MynthImage = class {
1088
1219
  async createRateTask(request) {
1089
1220
  const url = await this.resolveUrlOrFile(request);
1090
1221
  const { file: _, url: __, ...rest } = request;
1091
- const data = (await this.client.post(RATE_IMAGE_PATH, {
1222
+ const data = (await this.client.createTask(RATE_IMAGE_PATH, {
1092
1223
  ...rest,
1093
1224
  url
1094
1225
  })).data;
@@ -1133,7 +1264,7 @@ var MynthImage = class {
1133
1264
  }
1134
1265
  async createAltTask(request) {
1135
1266
  const url = await this.resolveUrlOrFile(request);
1136
- const data = (await this.client.post(ALT_IMAGE_PATH, { url })).data;
1267
+ const data = (await this.client.createTask(ALT_IMAGE_PATH, { url })).data;
1137
1268
  return new TaskAsync(data.task_id, {
1138
1269
  client: this.client,
1139
1270
  resultFactory: (taskData) => toImageAltResult(completedTaskFromData(taskData, "Image alt"))
@@ -1167,7 +1298,7 @@ var MynthImage = class {
1167
1298
  async createReviewTask(request) {
1168
1299
  const url = await this.resolveUrlOrFile(request);
1169
1300
  const { file: _, url: __, ...rest } = request;
1170
- const data = (await this.client.post(REVIEW_IMAGE_PATH, {
1301
+ const data = (await this.client.createTask(REVIEW_IMAGE_PATH, {
1171
1302
  ...rest,
1172
1303
  url
1173
1304
  })).data;
@@ -1216,7 +1347,7 @@ var MynthImage = class {
1216
1347
  async createRemoveBackgroundTask(request) {
1217
1348
  const url = await this.resolveUrlOrFile(request);
1218
1349
  const { file: _, url: __, ...rest } = request;
1219
- const data = (await this.client.post(REMOVE_BACKGROUND_IMAGE_PATH, {
1350
+ const data = (await this.client.createTask(REMOVE_BACKGROUND_IMAGE_PATH, {
1220
1351
  ...rest,
1221
1352
  url,
1222
1353
  destination: request.destination ?? this.defaultDestination
@@ -1270,7 +1401,7 @@ var MynthImage = class {
1270
1401
  async createUpscaleTask(request) {
1271
1402
  const url = await this.resolveUrlOrFile(request);
1272
1403
  const { file: _, url: __, ...rest } = request;
1273
- const data = (await this.client.post(UPSCALE_IMAGE_PATH, {
1404
+ const data = (await this.client.createTask(UPSCALE_IMAGE_PATH, {
1274
1405
  ...rest,
1275
1406
  url,
1276
1407
  destination: request.destination ?? this.defaultDestination
@@ -1414,7 +1545,7 @@ var MynthVideo = class {
1414
1545
  } : rest;
1415
1546
  }
1416
1547
  async createGenerationTask(request) {
1417
- const data = (await this.client.post(GENERATE_VIDEO_PATH, await this.toRequestBody(request))).data;
1548
+ const data = (await this.client.createTask(GENERATE_VIDEO_PATH, await this.toRequestBody(request))).data;
1418
1549
  return new TaskAsync(data.task_id, {
1419
1550
  client: this.client,
1420
1551
  pat: data.public_access_token,
@@ -187,7 +187,7 @@ declare namespace MynthSDKTypes {
187
187
  };
188
188
  type Model = ImageModel | VideoModel;
189
189
  type ModelsListResponse = ApiResponse<Model[]>;
190
- type ImageGenerationModelId = "alibaba/qwen-image-2.0" | "alibaba/qwen-image-2.0-pro" | "alibaba/qwen-image-2.1-turbo" | "alibaba/qwen-image-3.0" | "alibaba/qwen-image-3.0-pro" | "bytedance/seedream-5.0-lite" | "bytedance/seedream-pro" | "bytedance/seedream-v5-flash" | "black-forest-labs/flux.1-dev" | "black-forest-labs/flux-1-schnell" | "black-forest-labs/flux.2-dev" | "black-forest-labs/flux.2-pro" | "black-forest-labs/flux.2-flex" | "black-forest-labs/flux.2-max" | "black-forest-labs/flux.2-klein-4b" | "black-forest-labs/flux-3" | "black-forest-labs/flux-3-klein" | "bria/fibo-edit-1.5" | "bria/fibo-generate-1.5" | "circlestone-labs/anima" | "goofy-ai/prefect-pony-xl-lora" | "google/gemini-3.1-flash-lite-image" | "google/gemini-3.1-flash-image" | "google/gemini-3-pro-image-preview" | "imagineart/imagineart-1.5-pro" | "imagineart/imagineart-2.0" | "ideogram/ideogram-4.5" | "klingai/kling-image-3.0" | "klingai/kling-image-o3" | "krea/krea-2-turbo" | "krea/krea-2-medium" | "krea/krea-2-large" | "luma/uni-1" | "luma/uni-1-max" | "meta/muse-image" | "microsoft/mai-image-2.6" | "microsoft/mai-image-2.6-flash" | "minimax/h3" | "openai/gpt-image-2" | "openai/gpt-image-2.5-flare" | "openai/gpt-image-2.5-sunburst" | "tongyi-mai/z-image" | "tongyi-mai/z-image-turbo" | "john6666/bismuth-illustrious-mix" | "maxfeifei8/one-obsession" | "purplesmartai/pony-diffusion-v6-xl" | "recraft/recraft-v4" | "recraft/recraft-v4.1-flash" | "recraft/recraft-v4-pro" | "reve/reve" | "reve/reve-remix" | "sourceful/riverflow-2.0-pro" | "wan/wan2.6-image" | "wan/wan2.7-image" | "wan/wan2.7-image-pro" | "xai/grok-imagine-image" | "xai/grok-imagine-image-2.0" | "xai/grok-imagine-image-quality";
190
+ type ImageGenerationModelId = "alibaba/qwen-image-2.0" | "alibaba/qwen-image-2.0-pro" | "alibaba/qwen-image-2.1-pro" | "alibaba/qwen-image-2.1-turbo" | "alibaba/qwen-image-3.0" | "alibaba/qwen-image-3.0-pro" | "bytedance/seedream-5.0-lite" | "bytedance/seedream-pro" | "bytedance/seedream-v5-flash" | "black-forest-labs/flux.1-dev" | "black-forest-labs/flux-1-schnell" | "black-forest-labs/flux.2-dev" | "black-forest-labs/flux.2-pro" | "black-forest-labs/flux.2-flex" | "black-forest-labs/flux.2-max" | "black-forest-labs/flux.2-klein-4b" | "black-forest-labs/flux-3" | "black-forest-labs/flux-3-klein" | "bria/fibo-edit-1.5" | "bria/fibo-generate-1.5" | "circlestone-labs/anima" | "goofy-ai/prefect-pony-xl-lora" | "google/gemini-3.1-flash-lite-image" | "google/gemini-3.1-flash-image" | "google/gemini-3-pro-image-preview" | "google/gemini-nano-banana-2.1" | "imagineart/imagineart-1.5-pro" | "imagineart/imagineart-2.0" | "ideogram/ideogram-4.5" | "klingai/kling-image-3.0" | "klingai/kling-image-o3" | "krea/krea-2-turbo" | "krea/krea-2-medium" | "krea/krea-2-large" | "luma/uni-1" | "luma/uni-1-max" | "meta/muse-image" | "microsoft/mai-image-2.6" | "microsoft/mai-image-2.6-flash" | "minimax/h3" | "openai/gpt-image-2" | "openai/gpt-image-2.5-flare" | "openai/gpt-image-2.5-sunburst" | "openai/gpt-image-2.6-flare" | "openai/gpt-image-2.6-sunburst" | "openai/gpt-image-flare" | "openai/gpt-image-sunburst" | "tongyi-mai/z-image" | "tongyi-mai/z-image-turbo" | "john6666/bismuth-illustrious-mix" | "maxfeifei8/one-obsession" | "purplesmartai/pony-diffusion-v6-xl" | "recraft/recraft-v4" | "recraft/recraft-v4.1-flash" | "recraft/recraft-v4-pro" | "reve/reve" | "reve/reve-remix" | "sourceful/riverflow-2.0-pro" | "wan/wan2.6-image" | "wan/wan2.7-image" | "wan/wan2.7-image-pro" | "xai/grok-imagine-image" | "xai/grok-imagine-image-2.0" | "xai/grok-imagine-image-quality";
191
191
  type ImageGenerationModel = ImageGenerationModelId | "auto";
192
192
  type GenerateImageOptionsIn = {
193
193
  prompt: string;
@@ -481,7 +481,7 @@ declare namespace MynthSDKTypes {
481
481
  type ImageUpscaleTaskResult = {
482
482
  image: ImageUpscaleResultImage;
483
483
  };
484
- type VideoGenerationModelId = "bytedance/seedance-2.0-mini" | "google/gemini-omni-flash-1.1" | "prunaai/p-video" | "xai/grok-imagine-video-1.5";
484
+ type VideoGenerationModelId = "bytedance/seedance-2.0-mini" | "google/gemini-omni-flash-1.1" | "prunaai/p-video" | "xai/grok-imagine-video-1.5" | "xai/grok-imagine-video-1.5-lite";
485
485
  type VideoGenerationModel = VideoGenerationModelId;
486
486
  type VideoGenerationRequestResolution = "480p" | "720p" | "1080p" | "4k";
487
487
  type VideoGenerationRequestSizeShape = "auto" | "square" | "portrait" | "landscape" | "portrait_tall" | "landscape_wide" | ImageGenerationRequestAspectRatio;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mynthio/sdk",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "Official Mynth SDK for image generation and analysis",
5
5
  "keywords": [
6
6
  "ai",