@mynthio/sdk 0.0.50 → 0.0.52

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
@@ -692,7 +692,7 @@ const task = await mynth.video.generate({
692
692
  model: "google/gemini-omni-flash-1.1",
693
693
  prompt: "A drone shot over a misty forest at dawn",
694
694
  duration: 8,
695
- resolution: "1080p",
695
+ size: "9:16_1080p",
696
696
  audio: true,
697
697
  });
698
698
 
@@ -720,9 +720,26 @@ return { id: taskAsync.id, access: taskAsync.access };
720
720
 
721
721
  `taskAsync.access.publicAccessToken` works exactly as it does for images: requested with `generate_public_access_token: true`, scoped to that one task, safe to send to the client, and usable against `GET /tasks/:id/status` and `GET /tasks/:id/result`.
722
722
 
723
- ### Duration, Resolution and Audio
723
+ ### Size
724
724
 
725
- `duration` is in whole seconds and `resolution` is a tier (`"480p"`, `"720p"`, `"1080p"`, `"4k"`). Each model accepts a subset of both, and rejects a request outside it. Omit either to take the model default. `audio: true` enables model-native generated audio.
725
+ `size` sets the aspect ratio and the resolution tier:
726
+
727
+ ```ts
728
+ size: "auto"; // default: the model's default shape and tier
729
+ size: "portrait"; // a named shape or an aspect ratio, at the model's default tier
730
+ size: "9:16_1080p"; // a shape with a tier
731
+ size: "auto_1080p"; // the model's default shape, at a tier
732
+ size: { type: "aspect_ratio", aspect_ratio: "9:16", resolution: "1080p" };
733
+ size: { type: "auto", resolution: "1080p" };
734
+ ```
735
+
736
+ Shapes are the same as for images: `square`, `portrait`, `landscape`, `portrait_tall`, `landscape_wide`, and the ratios `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`, `2:1`, `1:2`.
737
+
738
+ The aspect ratio is best effort: the model gets the closest one it supports. With image inputs, the first frame sets the shape and the aspect ratio is ignored. The tier (`"480p"`, `"720p"`, `"1080p"`, `"4k"`) is strict, because it sets the price: each model accepts a subset, and rejects a tier outside it.
739
+
740
+ ### Duration and Audio
741
+
742
+ `duration` is in whole seconds. Each model accepts a range, and rejects a request outside it. Omit it to take the model default. `audio: true` enables model-native generated audio.
726
743
 
727
744
  ### Input Images
728
745
 
@@ -759,7 +776,7 @@ const { estimated_cost } = await mynth.video.estimate({
759
776
  model: "google/gemini-omni-flash-1.1",
760
777
  prompt: "A timelapse of clouds over a canyon",
761
778
  duration: 10,
762
- resolution: "4k",
779
+ size: "16:9_4k",
763
780
  });
764
781
  ```
765
782
 
@@ -780,7 +797,7 @@ console.log(task.metadata);
780
797
  console.log(task.raw);
781
798
  ```
782
799
 
783
- Each video has `id`, `url`, `mynthUrl`, `cost`, `duration`, `resolution`, and `audio`. `url` is `null` when the video could not be delivered there; `mynthUrl` is always set.
800
+ Each video has `id`, `url`, `mynthUrl`, `cost`, `duration`, `resolution`, `aspectRatio`, and `audio`. `aspectRatio` is `null` when the first frame set the shape. `url` is `null` when the video could not be delivered there; `mynthUrl` is always set.
784
801
 
785
802
  ### Video Models
786
803
 
@@ -1049,7 +1066,8 @@ try {
1049
1066
  } catch (error) {
1050
1067
  if (error instanceof MynthAPIError) {
1051
1068
  // `message` says what to fix. On a validation_error, `issues` lists each invalid field.
1052
- console.error(error.status, error.code, error.message, error.issues);
1069
+ // On public_access_token_failed, the task was created: follow `taskId` rather than resending.
1070
+ console.error(error.status, error.code, error.message, error.issues, error.taskId);
1053
1071
  } else if (error instanceof TaskAsyncTimeoutError) {
1054
1072
  console.error("Task polling timed out");
1055
1073
  } else if (error instanceof TaskAsyncUnauthorizedError) {
@@ -1064,21 +1082,6 @@ try {
1064
1082
  }
1065
1083
  ```
1066
1084
 
1067
- ## Migrating from 0.0.49
1068
-
1069
- 0.0.50 follows the stable API, which changed in one go. Nothing in it is backward compatible:
1070
-
1071
- - Request fields are snake_case, and the API now rejects a field it does not know. `size.aspectRatio` is `size.aspect_ratio`.
1072
- - `access: { pat: { enabled } }` is `generate_public_access_token: true`, and it now defaults to `false`: pass it to get `taskAsync.access.publicAccessToken` from `generateAsync()`, `removeBackgroundAsync()`, `upscaleAsync()` and `video.generateAsync()`.
1073
- - `webhook.dashboard` is `webhook.registered`.
1074
- - `MynthAPIError.code` and every task error code are lowercase: `validation_error`, `insufficient_balance`, `provider_error`.
1075
- - API data the SDK returns as is is snake_case: `MynthSDKTypes.TaskData` (`user_id`, `api_key_id`, `created_at`, `updated_at`), the model catalog (`display_name`, `per_image`, `per_second`, `max_total`) and `video.estimate()` (`estimated_cost`, `estimate_kind`).
1076
- - A video's `url` can be `null`, like an image's. `result.urls` skips it.
1077
- - Webhooks follow Standard Webhooks. Every registered webhook got a new `whsec_...` signing secret: copy it from the dashboard into `MYNTH_WEBHOOK_SECRET`. `X-Mynth-Event`, `X-Mynth-Delivery` and `X-Mynth-Signature` are gone; deliveries carry `webhook-id`, `webhook-timestamp` and `webhook-signature`.
1078
- - The webhook body is an event, `{ id, type, timestamp, data }`, with the task in `data`. `MynthSDKTypes.WebhookPayload` and its variants are replaced by `MynthSDKTypes.WebhookEvent`, and `verifyWebhook()` returns one.
1079
- - Webhook callbacks get `{ event }` in their last argument instead of `deliveryId`. Deduplicate on `event.id`.
1080
- - Unsigned deliveries to a custom URL are refused unless the helper gets the `unsigned` option.
1081
-
1082
1085
  ## Documentation
1083
1086
 
1084
1087
  For product documentation and API guides, visit [mynth.io/docs](https://mynth.io/docs).
package/dist/index.d.ts CHANGED
@@ -13,7 +13,12 @@ export declare class MynthAPIError extends Error {
13
13
  * `message` already states all of them.
14
14
  */
15
15
  readonly issues?: ReadonlyArray<MynthAPIErrorIssue> | undefined;
16
- constructor(message: string, status: number, code?: string, issues?: ReadonlyArray<MynthAPIErrorIssue>);
16
+ /**
17
+ * The task the request created before it failed, when `code` is
18
+ * `public_access_token_failed`. It will run: follow it rather than resending.
19
+ */
20
+ readonly taskId?: string | undefined;
21
+ constructor(message: string, status: number, code?: string, issues?: ReadonlyArray<MynthAPIErrorIssue>, taskId?: string);
17
22
  }
18
23
  type MynthAPIErrorIssue = {
19
24
  /** Where the problem is, e.g. `["size", "scale"]`. Empty for the body as a whole. */
@@ -538,7 +543,7 @@ declare class MynthImage {
538
543
  * model: "google/gemini-omni-flash-1.1",
539
544
  * prompt: "A cat surfing a wave at sunset",
540
545
  * duration: 8,
541
- * resolution: "1080p",
546
+ * size: "9:16_1080p",
542
547
  * });
543
548
  *
544
549
  * console.log(result.urls); // ["https://..."]
@@ -613,7 +618,7 @@ declare class MynthVideo {
613
618
  * Price a video generation request without generating anything.
614
619
  *
615
620
  * The request is validated exactly as `generate()` would validate it, so an
616
- * unsupported duration, resolution or input combination throws here too —
621
+ * unsupported duration, resolution tier or input combination throws here too —
617
622
  * making this a cheap pre-flight check as well as a cost lookup. Because
618
623
  * video pins a concrete model, the returned estimate is exact.
619
624
  *
@@ -626,7 +631,7 @@ declare class MynthVideo {
626
631
  * model: "google/gemini-omni-flash-1.1",
627
632
  * prompt: "A timelapse of clouds over a canyon",
628
633
  * duration: 10,
629
- * resolution: "4k",
634
+ * size: "16:9_4k",
630
635
  * });
631
636
  * ```
632
637
  */
package/dist/index.js CHANGED
@@ -407,18 +407,24 @@ var MynthAPIError = class extends Error {
407
407
  * `message` already states all of them.
408
408
  */
409
409
  issues;
410
- constructor(message, status, code, issues) {
410
+ /**
411
+ * The task the request created before it failed, when `code` is
412
+ * `public_access_token_failed`. It will run: follow it rather than resending.
413
+ */
414
+ taskId;
415
+ constructor(message, status, code, issues, taskId) {
411
416
  super(message);
412
417
  this.name = "MynthAPIError";
413
418
  this.status = status;
414
419
  this.code = code;
415
420
  this.issues = issues;
421
+ this.taskId = taskId;
416
422
  }
417
423
  };
418
424
  function createApiError(data, status) {
419
425
  const body = typeof data === "object" && data !== null ? data : {};
420
426
  const error = typeof body.error === "object" && body.error !== null ? body.error : {};
421
- return new MynthAPIError(typeof error.message === "string" && error.message || `Request failed with status ${status}`, status, typeof error.code === "string" ? error.code : void 0, Array.isArray(error.issues) ? error.issues : void 0);
427
+ return new MynthAPIError(typeof error.message === "string" && error.message || `Request failed with status ${status}`, status, typeof error.code === "string" ? error.code : void 0, Array.isArray(error.issues) ? error.issues : void 0, typeof error.task_id === "string" ? error.task_id : void 0);
422
428
  }
423
429
  /** An error body that is not JSON (a proxy's HTML page, say) still yields an API error. */
424
430
  async function readErrorBody(response) {
@@ -1281,7 +1287,7 @@ var MynthImage = class {
1281
1287
  * model: "google/gemini-omni-flash-1.1",
1282
1288
  * prompt: "A cat surfing a wave at sunset",
1283
1289
  * duration: 8,
1284
- * resolution: "1080p",
1290
+ * size: "9:16_1080p",
1285
1291
  * });
1286
1292
  *
1287
1293
  * console.log(result.urls); // ["https://..."]
@@ -1369,7 +1375,7 @@ var MynthVideo = class {
1369
1375
  * Price a video generation request without generating anything.
1370
1376
  *
1371
1377
  * The request is validated exactly as `generate()` would validate it, so an
1372
- * unsupported duration, resolution or input combination throws here too —
1378
+ * unsupported duration, resolution tier or input combination throws here too —
1373
1379
  * making this a cheap pre-flight check as well as a cost lookup. Because
1374
1380
  * video pins a concrete model, the returned estimate is exact.
1375
1381
  *
@@ -1382,7 +1388,7 @@ var MynthVideo = class {
1382
1388
  * model: "google/gemini-omni-flash-1.1",
1383
1389
  * prompt: "A timelapse of clouds over a canyon",
1384
1390
  * duration: 10,
1385
- * resolution: "4k",
1391
+ * size: "16:9_4k",
1386
1392
  * });
1387
1393
  * ```
1388
1394
  */
package/dist/utils.js CHANGED
@@ -182,6 +182,7 @@ function toOutputVideo(video) {
182
182
  cost: video.cost,
183
183
  duration: video.duration,
184
184
  resolution: video.resolution,
185
+ aspectRatio: video.aspect_ratio,
185
186
  audio: video.audio
186
187
  };
187
188
  }
@@ -484,6 +484,18 @@ declare namespace MynthSDKTypes {
484
484
  type VideoGenerationModelId = "bytedance/seedance-2.0-mini" | "google/gemini-omni-flash-1.1" | "prunaai/p-video" | "xai/grok-imagine-video-1.5";
485
485
  type VideoGenerationModel = VideoGenerationModelId;
486
486
  type VideoGenerationRequestResolution = "480p" | "720p" | "1080p" | "4k";
487
+ type VideoGenerationRequestSizeShape = "auto" | "square" | "portrait" | "landscape" | "portrait_tall" | "landscape_wide" | ImageGenerationRequestAspectRatio;
488
+ type VideoGenerationRequestSizePreset = VideoGenerationRequestSizeShape | `${VideoGenerationRequestSizeShape}_${VideoGenerationRequestResolution}`;
489
+ type VideoGenerationRequestSizeAspectRatio = {
490
+ type: "aspect_ratio";
491
+ aspect_ratio: ImageGenerationRequestAspectRatio;
492
+ resolution?: VideoGenerationRequestResolution;
493
+ };
494
+ type VideoGenerationRequestSizeAuto = {
495
+ type: "auto";
496
+ resolution?: VideoGenerationRequestResolution;
497
+ };
498
+ type VideoGenerationRequestSize = VideoGenerationRequestSizePreset | VideoGenerationRequestSizeAspectRatio | VideoGenerationRequestSizeAuto;
487
499
  type VideoGenerationRequestWebhook = ImageGenerationRequestWebhook;
488
500
  type VideoGenerationRequestInputSource = {
489
501
  type: "url";
@@ -507,8 +519,8 @@ declare namespace MynthSDKTypes {
507
519
  negative_prompt?: string;
508
520
  /** Duration in whole seconds. Defaults to the model's default duration. */
509
521
  duration?: number;
510
- /** Resolution tier. Defaults to the model's default tier. */
511
- resolution?: VideoGenerationRequestResolution;
522
+ /** Aspect ratio and resolution tier. Defaults to `"auto"` at the model's default tier. */
523
+ size?: VideoGenerationRequestSize;
512
524
  /** Model-native generated audio. Only for models with the audio capability. */
513
525
  audio?: boolean;
514
526
  inputs?: (string | VideoGenerationRequestInput)[];
@@ -538,6 +550,8 @@ declare namespace MynthSDKTypes {
538
550
  /** Duration of the generated video in seconds */
539
551
  duration: number;
540
552
  resolution: VideoGenerationRequestResolution;
553
+ /** Aspect ratio the video was generated at, e.g. `"16:9"`. `null` when the first frame set it. */
554
+ aspect_ratio: string | null;
541
555
  /** Whether the video was generated with audio */
542
556
  audio: boolean;
543
557
  };
@@ -829,6 +843,8 @@ type MynthOutputVideo = {
829
843
  duration: number;
830
844
  /** Resolution tier the video was rendered at */
831
845
  resolution: MynthSDKTypes.VideoGenerationRequestResolution;
846
+ /** Aspect ratio the video was generated at, e.g. `"16:9"`. `null` when the first frame set it. */
847
+ aspectRatio: string | null;
832
848
  /** Whether the video has generated audio */
833
849
  audio: boolean;
834
850
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mynthio/sdk",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
4
4
  "description": "Official Mynth SDK for image generation and analysis",
5
5
  "keywords": [
6
6
  "ai",