@mynthio/sdk 0.0.53 → 0.0.54

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",
@@ -400,6 +410,24 @@ const AVAILABLE_VIDEO_MODELS = [
400
410
  audio: true,
401
411
  inputs: ["first_frame"],
402
412
  maxInputs: 1
413
+ },
414
+ {
415
+ id: "xai/grok-imagine-video-1.5-lite",
416
+ label: "Grok Imagine Video 1.5 Lite",
417
+ resolutions: [
418
+ "480p",
419
+ "720p",
420
+ "1080p"
421
+ ],
422
+ defaultResolution: "480p",
423
+ duration: {
424
+ default: 6,
425
+ min: 1,
426
+ max: 15
427
+ },
428
+ audio: true,
429
+ inputs: ["first_frame"],
430
+ maxInputs: 1
403
431
  }
404
432
  ];
405
433
  //#endregion
@@ -431,6 +459,50 @@ var MynthAPIError = class extends Error {
431
459
  this.taskId = taskId;
432
460
  }
433
461
  };
462
+ /**
463
+ * Sent as `X-Mynth-Client` on creates so Mynth can count SDK traffic. The API
464
+ * only records it, never checks it. The build inlines the package version.
465
+ */
466
+ const SDK_CLIENT = `sdk/0.0.54`;
467
+ /**
468
+ * Waits before each retry of a create that failed in transit or with a 5xx.
469
+ * The retry sends the same `Idempotency-Key`, so Mynth returns the task the
470
+ * first attempt made, if it made one, instead of creating and charging another.
471
+ */
472
+ const CREATE_RETRY_DELAYS_MS = [500, 2e3];
473
+ /** Statuses a create may answer while the API is restarting or overloaded. */
474
+ const RETRYABLE_STATUSES = /* @__PURE__ */ new Set([
475
+ 500,
476
+ 502,
477
+ 503,
478
+ 504
479
+ ]);
480
+ /** A fresh `Idempotency-Key`: one per logical create, reused by its retries. */
481
+ function createIdempotencyKey() {
482
+ const crypto = globalThis.crypto;
483
+ if (typeof crypto?.randomUUID === "function") return crypto.randomUUID();
484
+ const bytes = /* @__PURE__ */ new Uint8Array(16);
485
+ if (typeof crypto?.getRandomValues === "function") crypto.getRandomValues(bytes);
486
+ else for (let index = 0; index < bytes.length; index++) bytes[index] = Math.floor(Math.random() * 256);
487
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
488
+ }
489
+ function wait(ms, signal) {
490
+ return new Promise((resolve, reject) => {
491
+ if (signal?.aborted) {
492
+ reject(signal.reason);
493
+ return;
494
+ }
495
+ const onAbort = () => {
496
+ clearTimeout(timer);
497
+ reject(signal?.reason);
498
+ };
499
+ const timer = setTimeout(() => {
500
+ signal?.removeEventListener("abort", onAbort);
501
+ resolve();
502
+ }, ms);
503
+ signal?.addEventListener("abort", onAbort, { once: true });
504
+ });
505
+ }
434
506
  function createApiError(data, status) {
435
507
  const body = typeof data === "object" && data !== null ? data : {};
436
508
  const error = typeof body.error === "object" && body.error !== null ? body.error : {};
@@ -477,6 +549,42 @@ var MynthClient = class {
477
549
  if (!response.ok) throw createApiError(await readErrorBody(response), response.status);
478
550
  return await response.json();
479
551
  }
552
+ /**
553
+ * Creates a task. Sends `X-Mynth-Client` and an `Idempotency-Key` (the
554
+ * caller's, or a fresh one), and retries with the same key when the request
555
+ * fails in transit or with a 5xx, so a retry never creates a second task.
556
+ */
557
+ async createTask(path, data, { signal, idempotencyKey = createIdempotencyKey() } = {}) {
558
+ const body = JSON.stringify(data);
559
+ for (let attempt = 0;; attempt++) {
560
+ const delay = CREATE_RETRY_DELAYS_MS[attempt];
561
+ let response;
562
+ try {
563
+ response = await fetch(this.getUrl(path), {
564
+ method: "POST",
565
+ headers: {
566
+ "Content-Type": "application/json",
567
+ "Idempotency-Key": idempotencyKey,
568
+ "X-Mynth-Client": SDK_CLIENT,
569
+ ...this.getAuthHeaders()
570
+ },
571
+ body,
572
+ ...signal ? { signal } : {}
573
+ });
574
+ } catch (error) {
575
+ if (signal?.aborted || delay === void 0) throw error;
576
+ await wait(delay, signal);
577
+ continue;
578
+ }
579
+ if (response.ok) return await response.json();
580
+ if (RETRYABLE_STATUSES.has(response.status) && delay !== void 0) {
581
+ await response.body?.cancel();
582
+ await wait(delay, signal);
583
+ continue;
584
+ }
585
+ throw createApiError(await readErrorBody(response), response.status);
586
+ }
587
+ }
480
588
  async get(path, { headers, accessToken, auth, signal } = {}) {
481
589
  const response = await fetch(this.getUrl(path), {
482
590
  headers: {
@@ -1015,13 +1123,16 @@ var MynthImage = class {
1015
1123
  async generateAsync(request, options = {}) {
1016
1124
  return this.createGenerationTask(request, options);
1017
1125
  }
1018
- async createGenerationTask(request, { signal }) {
1126
+ async createGenerationTask(request, { signal, idempotencyKey }) {
1019
1127
  const inputs = await resolveInputs(this.client, request.inputs, { signal });
1020
- const data = (await this.client.post(GENERATE_IMAGE_PATH, {
1128
+ const data = (await this.client.createTask(GENERATE_IMAGE_PATH, {
1021
1129
  ...request,
1022
1130
  inputs,
1023
1131
  destination: request.destination ?? this.defaultDestination
1024
- }, { signal })).data;
1132
+ }, {
1133
+ signal,
1134
+ idempotencyKey
1135
+ })).data;
1025
1136
  return new TaskAsync(data.task_id, {
1026
1137
  client: this.client,
1027
1138
  pat: data.public_access_token,
@@ -1088,7 +1199,7 @@ var MynthImage = class {
1088
1199
  async createRateTask(request) {
1089
1200
  const url = await this.resolveUrlOrFile(request);
1090
1201
  const { file: _, url: __, ...rest } = request;
1091
- const data = (await this.client.post(RATE_IMAGE_PATH, {
1202
+ const data = (await this.client.createTask(RATE_IMAGE_PATH, {
1092
1203
  ...rest,
1093
1204
  url
1094
1205
  })).data;
@@ -1133,7 +1244,7 @@ var MynthImage = class {
1133
1244
  }
1134
1245
  async createAltTask(request) {
1135
1246
  const url = await this.resolveUrlOrFile(request);
1136
- const data = (await this.client.post(ALT_IMAGE_PATH, { url })).data;
1247
+ const data = (await this.client.createTask(ALT_IMAGE_PATH, { url })).data;
1137
1248
  return new TaskAsync(data.task_id, {
1138
1249
  client: this.client,
1139
1250
  resultFactory: (taskData) => toImageAltResult(completedTaskFromData(taskData, "Image alt"))
@@ -1167,7 +1278,7 @@ var MynthImage = class {
1167
1278
  async createReviewTask(request) {
1168
1279
  const url = await this.resolveUrlOrFile(request);
1169
1280
  const { file: _, url: __, ...rest } = request;
1170
- const data = (await this.client.post(REVIEW_IMAGE_PATH, {
1281
+ const data = (await this.client.createTask(REVIEW_IMAGE_PATH, {
1171
1282
  ...rest,
1172
1283
  url
1173
1284
  })).data;
@@ -1216,7 +1327,7 @@ var MynthImage = class {
1216
1327
  async createRemoveBackgroundTask(request) {
1217
1328
  const url = await this.resolveUrlOrFile(request);
1218
1329
  const { file: _, url: __, ...rest } = request;
1219
- const data = (await this.client.post(REMOVE_BACKGROUND_IMAGE_PATH, {
1330
+ const data = (await this.client.createTask(REMOVE_BACKGROUND_IMAGE_PATH, {
1220
1331
  ...rest,
1221
1332
  url,
1222
1333
  destination: request.destination ?? this.defaultDestination
@@ -1270,7 +1381,7 @@ var MynthImage = class {
1270
1381
  async createUpscaleTask(request) {
1271
1382
  const url = await this.resolveUrlOrFile(request);
1272
1383
  const { file: _, url: __, ...rest } = request;
1273
- const data = (await this.client.post(UPSCALE_IMAGE_PATH, {
1384
+ const data = (await this.client.createTask(UPSCALE_IMAGE_PATH, {
1274
1385
  ...rest,
1275
1386
  url,
1276
1387
  destination: request.destination ?? this.defaultDestination
@@ -1414,7 +1525,7 @@ var MynthVideo = class {
1414
1525
  } : rest;
1415
1526
  }
1416
1527
  async createGenerationTask(request) {
1417
- const data = (await this.client.post(GENERATE_VIDEO_PATH, await this.toRequestBody(request))).data;
1528
+ const data = (await this.client.createTask(GENERATE_VIDEO_PATH, await this.toRequestBody(request))).data;
1418
1529
  return new TaskAsync(data.task_id, {
1419
1530
  client: this.client,
1420
1531
  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" | "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.54",
4
4
  "description": "Official Mynth SDK for image generation and analysis",
5
5
  "keywords": [
6
6
  "ai",