@mynthio/sdk 0.0.52 → 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,8 @@ 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`
644
+ - `alibaba/qwen-image-2.1-turbo`
643
645
  - `alibaba/qwen-image-3.0`
644
646
  - `alibaba/qwen-image-3.0-pro`
645
647
  - `bytedance/seedream-5.0-lite`
@@ -657,6 +659,7 @@ Current model IDs include:
657
659
  - `google/gemini-3.1-flash-lite-image`
658
660
  - `google/gemini-3.1-flash-image`
659
661
  - `google/gemini-3-pro-image-preview`
662
+ - `google/gemini-nano-banana-2.1`
660
663
  - `imagineart/imagineart-1.5-pro`
661
664
  - `imagineart/imagineart-2.0`
662
665
  - `ideogram/ideogram-4.5`
@@ -821,12 +824,13 @@ console.log(model);
821
824
  // }
822
825
  ```
823
826
 
824
- | Model | Resolutions | Duration (s) | Inputs |
825
- | ------------------------------ | ----------------- | ---------------- | ----------------------- |
826
- | `bytedance/seedance-2.0-mini` | 480p, 720p | 4–15 (default 5) | first frame, last frame |
827
- | `google/gemini-omni-flash-1.1` | 720p, 1080p, 4k | 3–10 (default 8) | first frame, last frame |
828
- | `prunaai/p-video` | 720p, 1080p | 1–10 (default 5) | first frame |
829
- | `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 |
830
834
 
831
835
  Each of these supports generated audio.
832
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,16 @@ 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
+ },
47
+ {
48
+ id: "alibaba/qwen-image-2.1-turbo",
49
+ label: "Qwen Image 2.1 Turbo",
50
+ capabilities: ["inputs"]
51
+ },
42
52
  {
43
53
  id: "alibaba/qwen-image-3.0",
44
54
  label: "Qwen Image 3.0",
@@ -114,6 +124,11 @@ const AVAILABLE_MODELS = [
114
124
  label: "FLUX.3",
115
125
  capabilities: ["inputs", "4k"]
116
126
  },
127
+ {
128
+ id: "black-forest-labs/flux-3-klein",
129
+ label: "FLUX.3 Klein",
130
+ capabilities: ["inputs", "4k"]
131
+ },
117
132
  {
118
133
  id: "bria/fibo-edit-1.5",
119
134
  label: "FIBO Edit 1.5",
@@ -249,6 +264,11 @@ const AVAILABLE_MODELS = [
249
264
  label: "Nano Banana Pro",
250
265
  capabilities: ["inputs", "4k"]
251
266
  },
267
+ {
268
+ id: "google/gemini-nano-banana-2.1",
269
+ label: "Gemini Nano Banana 2.1",
270
+ capabilities: ["inputs", "4k"]
271
+ },
252
272
  {
253
273
  id: "imagineart/imagineart-1.5-pro",
254
274
  label: "ImagineArt 1.5 Pro",
@@ -390,6 +410,24 @@ const AVAILABLE_VIDEO_MODELS = [
390
410
  audio: true,
391
411
  inputs: ["first_frame"],
392
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
393
431
  }
394
432
  ];
395
433
  //#endregion
@@ -421,6 +459,50 @@ var MynthAPIError = class extends Error {
421
459
  this.taskId = taskId;
422
460
  }
423
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
+ }
424
506
  function createApiError(data, status) {
425
507
  const body = typeof data === "object" && data !== null ? data : {};
426
508
  const error = typeof body.error === "object" && body.error !== null ? body.error : {};
@@ -467,6 +549,42 @@ var MynthClient = class {
467
549
  if (!response.ok) throw createApiError(await readErrorBody(response), response.status);
468
550
  return await response.json();
469
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
+ }
470
588
  async get(path, { headers, accessToken, auth, signal } = {}) {
471
589
  const response = await fetch(this.getUrl(path), {
472
590
  headers: {
@@ -1005,13 +1123,16 @@ var MynthImage = class {
1005
1123
  async generateAsync(request, options = {}) {
1006
1124
  return this.createGenerationTask(request, options);
1007
1125
  }
1008
- async createGenerationTask(request, { signal }) {
1126
+ async createGenerationTask(request, { signal, idempotencyKey }) {
1009
1127
  const inputs = await resolveInputs(this.client, request.inputs, { signal });
1010
- const data = (await this.client.post(GENERATE_IMAGE_PATH, {
1128
+ const data = (await this.client.createTask(GENERATE_IMAGE_PATH, {
1011
1129
  ...request,
1012
1130
  inputs,
1013
1131
  destination: request.destination ?? this.defaultDestination
1014
- }, { signal })).data;
1132
+ }, {
1133
+ signal,
1134
+ idempotencyKey
1135
+ })).data;
1015
1136
  return new TaskAsync(data.task_id, {
1016
1137
  client: this.client,
1017
1138
  pat: data.public_access_token,
@@ -1078,7 +1199,7 @@ var MynthImage = class {
1078
1199
  async createRateTask(request) {
1079
1200
  const url = await this.resolveUrlOrFile(request);
1080
1201
  const { file: _, url: __, ...rest } = request;
1081
- const data = (await this.client.post(RATE_IMAGE_PATH, {
1202
+ const data = (await this.client.createTask(RATE_IMAGE_PATH, {
1082
1203
  ...rest,
1083
1204
  url
1084
1205
  })).data;
@@ -1123,7 +1244,7 @@ var MynthImage = class {
1123
1244
  }
1124
1245
  async createAltTask(request) {
1125
1246
  const url = await this.resolveUrlOrFile(request);
1126
- const data = (await this.client.post(ALT_IMAGE_PATH, { url })).data;
1247
+ const data = (await this.client.createTask(ALT_IMAGE_PATH, { url })).data;
1127
1248
  return new TaskAsync(data.task_id, {
1128
1249
  client: this.client,
1129
1250
  resultFactory: (taskData) => toImageAltResult(completedTaskFromData(taskData, "Image alt"))
@@ -1157,7 +1278,7 @@ var MynthImage = class {
1157
1278
  async createReviewTask(request) {
1158
1279
  const url = await this.resolveUrlOrFile(request);
1159
1280
  const { file: _, url: __, ...rest } = request;
1160
- const data = (await this.client.post(REVIEW_IMAGE_PATH, {
1281
+ const data = (await this.client.createTask(REVIEW_IMAGE_PATH, {
1161
1282
  ...rest,
1162
1283
  url
1163
1284
  })).data;
@@ -1206,7 +1327,7 @@ var MynthImage = class {
1206
1327
  async createRemoveBackgroundTask(request) {
1207
1328
  const url = await this.resolveUrlOrFile(request);
1208
1329
  const { file: _, url: __, ...rest } = request;
1209
- const data = (await this.client.post(REMOVE_BACKGROUND_IMAGE_PATH, {
1330
+ const data = (await this.client.createTask(REMOVE_BACKGROUND_IMAGE_PATH, {
1210
1331
  ...rest,
1211
1332
  url,
1212
1333
  destination: request.destination ?? this.defaultDestination
@@ -1260,7 +1381,7 @@ var MynthImage = class {
1260
1381
  async createUpscaleTask(request) {
1261
1382
  const url = await this.resolveUrlOrFile(request);
1262
1383
  const { file: _, url: __, ...rest } = request;
1263
- const data = (await this.client.post(UPSCALE_IMAGE_PATH, {
1384
+ const data = (await this.client.createTask(UPSCALE_IMAGE_PATH, {
1264
1385
  ...rest,
1265
1386
  url,
1266
1387
  destination: request.destination ?? this.defaultDestination
@@ -1404,7 +1525,7 @@ var MynthVideo = class {
1404
1525
  } : rest;
1405
1526
  }
1406
1527
  async createGenerationTask(request) {
1407
- 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;
1408
1529
  return new TaskAsync(data.task_id, {
1409
1530
  client: this.client,
1410
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-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" | "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.52",
3
+ "version": "0.0.54",
4
4
  "description": "Official Mynth SDK for image generation and analysis",
5
5
  "keywords": [
6
6
  "ai",