Skip to main content
Mynth work is task-based. POST /image/generate always returns a task (taskId + optional Public Access Token). The SDK generate() method creates that task and polls until it finishes. Use this guide when you need to wait for results or poll yourself. For browser UI polling with a Public Access Token, see Browser Polling. For push delivery instead of polling, see Use Webhooks.

Wait in the SDK (simplest path)

On a server (or any place that holds your API key), use generate(). It returns a completed result wrapper:
rate() and alt() work the same way: they start a task with sync: false and poll until completion.

Start a task without waiting

Use generateAsync() when you need the task ID immediately — for example to return to a client, store the ID, or wait later:
Also available: rateAsync(), altAsync(). Those return a TaskAsync without a Public Access Token — poll them from trusted code with your API key.

Handle success and failure

task.wait() resolves only when the task status is completed. It throws dedicated errors otherwise:
Task statuses: A completed image.generate task can still contain per-image failures (images[].status: "failed"). Use result.getImages() for successes only, or result.getImages({ includeFailed: true }) for both.

Poll with REST

Create a generation task (always async at the API):

Poll status

GET /tasks/:id/status accepts your API key or the task’s Public Access Token:
Poll until completed or failed.

Fetch the result

GET /tasks/:id/result uses the same auth options. It returns id, type, status, and result (null while pending or when a failed task has no result):
Completed generate example:

Owner-only full task

GET /tasks/:id requires your Mynth API key (not a Public Access Token). Use it when you need the original request, full result, cost, timestamps, or errors:
See Tasks reference for the full shape.

Public Access Tokens

Generation responses include a task-scoped Public Access Token by default (access.pat.enabled defaults to true). The token:
  • is a JWT prefixed with pat_
  • is scoped to one task
  • is valid for one hour
  • works only on GET /tasks/:id/status and GET /tasks/:id/result
Disable it when you only poll from the server with an API key:
Do not put your API key in the browser. Return only taskId and publicAccessToken to clients — see Browser Polling. rate and alt tasks do not currently return a Public Access Token. Poll those with your API key from trusted server code.

SDK polling behavior

TaskAsync.wait(): Because the final detail fetch uses the API key, call wait() from code that has the SDK client configured with your key. Browser clients should poll /status and /result with the Public Access Token instead. Full SDK helpers and error classes: SDK tasks.

REST sync mode for rate and alt

Unlike image generation, POST /image/rate and POST /image/alt default to server-side sync ("sync": true). The API waits up to ~55 seconds and returns results inline when possible. Set "sync": false (or use rateAsync() / altAsync()) to get a pending task and poll yourself. If sync mode times out, the API returns a 202 pending task — poll the same task endpoints.

Choose a completion strategy

How async fits generation

  1. You create a task (POST /image/generate, or generate / generateAsync in the SDK).
  2. Mynth queues work and returns taskId (and usually a Public Access Token).
  3. You wait in the SDK, poll /status then /result, or receive a webhook.
  4. On completed, read images (or rate/alt results) from the result payload.
Creating a task does not return final media in the create response. Always wait, poll, or subscribe before treating the job as done.