• Docs
  • API reference
  • SDKs & tools
  • Models
  • Changelog
Sign inGet an API key
DocsAPI referenceSDKs & toolsModelsChangelog

TypeScript SDK

OverviewInstallationClientGenerating mediaTasks and pollingErrors

CLI

OverviewLogging inCommands

Integrations

ConvexTanStack Start

Agents

llms.txtSkillsAgent prompt
  1. SDKs & tools
  2. /
  3. TypeScript SDK

Generating media

Generate images and video with the TypeScript client, run the image tools, upload local files, and read plain result objects.

PreviousClientNextTasks and polling

On this page

ImagesLocal filesVideoRating, alt text, review, background removal, upscalingNext steps

image.generate() and video.generate() send one request body, wait for the task, and return the finished result. The body is the REST body, with the same fields. Generate images and generate video are the field references.

Images

import Mynth from "@mynthio/sdk";

const mynth = new Mynth();

const task = await mynth.image.generate({
  model: "black-forest-labs/flux.2-pro",
  prompt: "A lighthouse at dusk, film grain",
  size: "landscape",
  count: 2,
  metadata: { orderId: "ord_42" },
});

for (const image of task.images) {
  console.log(image.url ?? image.mynthUrl, image.width, image.height);
}

The value is an ImageGenerationResult:

MemberHolds
taskId, costThe task ID and final USD charge
model, magicPromptThe resolved model and rewritten prompt
urlsurl of each successful image, skipping any whose url is null
imagesSuccessful images with id, url, mynthUrl, width, height, size, format, mimeType, destination, and rating
failuresEach failed image's { code, message? }
metadataThe metadata you sent, typed from the request
rawThe API's request and result before mapping

urls and images skip failed images, and urls also skips images whose destination upload failed. A task can complete with a short list. Compare images.length with the count you sent, and read failures to see why.

A task that settles as failed is not returned: generate() throws TaskAsyncTaskFailedError. See errors.

Pass a model id on every call. Omitting model makes the API use auto, which is experimental. See the model field. The SDK has no image.estimate(). Price an image body with POST /image/generate/estimate. See estimate cost.

Local files

In inputs, a string is a URL, and a File or Blob is uploaded first. All files of one call go up in a single upload, which accepts at most 10 files.

const task = await mynth.image.generate({
  model: "black-forest-labs/flux.2-pro",
  prompt: "The same lighthouse, at noon",
  inputs: [file],
});

image.upload(file) or image.upload([a, b]) runs that upload on its own and returns { urls }. Uploaded URLs are served for 1 day. Image to image covers input roles.

Video

const task = await mynth.video.generate({
  model: "bytedance/seedance-2.0-mini",
  prompt: "A lighthouse beam sweeping over waves",
  duration: 5,
  size: "9:16_720p",
});

console.log(task.urls[0]);

The result is a plain VideoGenerationResult with taskId, cost, model, videos, urls, failures, metadata, and raw. videos holds successful outputs, and failures lists the errors for failed outputs. Each video uses mynthUrl for Mynth's copy. generate() waits up to an hour.

video.estimate() prices the same body without creating a task. A File in inputs is uploaded first, as on generate().

const quote = await mynth.video.estimate({
  model: "bytedance/seedance-2.0-mini",
  prompt: "A lighthouse beam sweeping over waves",
  duration: 5,
});

console.log(quote.estimated_cost, quote.estimate_kind); // "0.405", "exact"

AVAILABLE_VIDEO_MODELS lists each video model's resolutions, durations, and frame inputs. Video models has the same table.

Rating, alt text, review, background removal, upscaling

These take no model, and each takes a url or a local file. Each method waits, and each has an Async twin.

const rating = await mynth.image.rate({ url });
const alt = await mynth.image.alt({ url });
const review = await mynth.image.review({ url, effort: "low" });
const cutout = await mynth.image.removeBackground({ file, output: { format: "png" } });
const upscaled = await mynth.image.upscale({ file, size: "2x", effort: "low" });
MethodResult members
rate()taskId, cost, level
alt()taskId, cost, alt
review()taskId, cost, score, summary, findings, strengths
removeBackground()taskId, cost, image, metadata
upscale()taskId, cost, image, metadata

Every finished result uses taskId and includes raw. removeBackground() and upscale() return the same image fields as generation and also take destination, webhook, and metadata. upscale() requires size and effort. The guides cover each tool: rate, alt text, review, remove background, and upscale.

Next steps

  • Tasks and polling: generateAsync(), the browser token, and poll intervals.
  • Errors: a rejected request and a failed task.
  • Tasks: how long the files last.