Skip to main content
The SDK exposes two task representations:
  • Task for completed work
  • TaskAsync for in-progress work

Task

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

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

TaskAsync

TaskAsync is returned from:
await mynth.generate(request, { mode: "async" });
It provides:
  • task.id
  • task.access.publicAccessToken
  • task.toTask()

Browser-safe access token

publicAccessToken is designed for client-side polling of:
  • GET /tasks/:id/status
  • GET /tasks/:id/results
Do not use it as a replacement for your server-side API key.

Polling behavior

toTask():
  • starts polling lazily
  • reuses the same promise if called multiple times
  • polls quickly for the first few seconds, then slows down
  • times out after five minutes
  • retries transient fetch failures

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 generation tasks. See Errors and Limits for usage examples.