Skip to main content
The SDK exposes completed result wrappers and an async task representation:
  • ImageGenerationResult for completed work
  • ImageRateResult for completed rating tasks
  • ImageAltResult for completed alt text tasks
  • TaskAsync for in-progress work

ImageGenerationResult

ImageGenerationResult is returned from sync generation (generate()) and from TaskAsync.wait() on generation tasks. Useful properties and helpers:
  • result.id
  • result.status
  • result.result
  • result.urls
  • result.getImages()
  • result.getImages({ includeFailed: true })
  • result.getMetadata()
Example:
const result = await mynth.image.generate({
  prompt: "An orange bicycle leaning against a sunlit stone wall",
  metadata: { requestId: "req_123" },
});

console.log(result.urls);
console.log(result.getMetadata());

TaskAsync

ImageRateResult and ImageAltResult expose task, taskId, raw results, and filtered helper methods:
const ratings = await mynth.image.rate({ urls: ["https://..."], mode: "nsfw_sfw" });
ratings.getRatings();
ratings.getErrors();

const altText = await mynth.image.alt({ urls: ["https://..."] });
altText.getAltTexts();
altText.getErrors();

TaskAsync

TaskAsync is returned from:
const task = await mynth.image.generateAsync(request);
const ratingTask = await mynth.image.rateAsync(request);
const altTask = await mynth.image.altAsync(request);
It provides:
  • task.id
  • task.access.publicAccessToken
  • task.wait() — polls until completion and resolves to the matching result wrapper

Browser-safe access token

publicAccessToken is a task-scoped JWT (prefixed with pat_) designed for client-side polling of:
  • GET /tasks/:id/status
  • GET /tasks/:id/result
Generation tasks include a Public Access Token by default. Rating and alt text tasks currently return undefined for task.access.publicAccessToken, so poll those from trusted server code with your API key. Do not use a Public Access Token as a replacement for your server-side API key.

Polling behavior

wait():
  • starts polling lazily — only when first called
  • reuses the same promise if called multiple times
  • polls every 2.5s for the first 12s, then slows to every 5s
  • times out after five minutes
  • retries transient fetch failures up to 7 times, resetting the count after any successful poll

Error classes

The SDK exposes dedicated error classes:
  • MynthAPIError
  • TaskAsyncTimeoutError
  • TaskAsyncUnauthorizedError
  • TaskAsyncFetchError
  • TaskAsyncTaskFetchError
  • TaskAsyncTaskFailedError
Use them when you want differentiated handling for validation failures, unauthorized access, timeouts, and failed tasks. See Errors and Limits for usage examples.