> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mynth.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Async and Polling

> Choose between sync and async generation, then retrieve task results correctly.

Mynth is task-based. Even when you use the SDK in sync mode, the SDK is still polling an async task under the hood.

## Use sync mode when

* your request can wait for completion
* you are on the server
* you want the simplest API

```ts theme={"theme":"kanagawa-dragon"}
const result = await mynth.image.generate({
  prompt: "Minimal product shot of a matte black espresso grinder",
  model: "google/gemini-3.1-flash-image",
});

console.log(result.urls); // string[]
```

## Use async mode when

* you need to respond quickly
* you want browser progress updates
* you are orchestrating background work

```ts theme={"theme":"kanagawa-dragon"}
const task = await mynth.image.generateAsync({
  prompt: "Minimal product shot of a matte black espresso grinder",
  model: "google/gemini-3.1-flash-image",
});

console.log(task.id);
console.log(task.access.publicAccessToken);

// Poll until done
const result = await task.wait();
console.log(result.urls);
```

The same endpoints the SDK uses internally are documented below.

## Poll the status endpoint

```bash theme={"theme":"kanagawa-dragon"}
curl https://api.mynth.io/tasks/$TASK_ID/status \
  -H "Authorization: Bearer $PUBLIC_ACCESS_TOKEN"
```

Response:

```json theme={"theme":"kanagawa-dragon"}
{
  "data": {
    "status": "pending"
  }
}
```

## Fetch final results

```bash theme={"theme":"kanagawa-dragon"}
curl https://api.mynth.io/tasks/$TASK_ID/result \
  -H "Authorization: Bearer $PUBLIC_ACCESS_TOKEN"
```

## Owner-only task details

Use `GET /tasks/:id` when you need the full task object, including the original request and full result payload.

This endpoint requires your Mynth API key and is not available through the public access token.

```bash theme={"theme":"kanagawa-dragon"}
curl https://api.mynth.io/tasks/$TASK_ID \
  -H "Authorization: Bearer $MYNTH_API_KEY"
```

See [Tasks reference](/reference/tasks#full-task-shape) for the response shape.

## SDK polling behavior

`TaskAsync.wait()` polls until the task is completed or failed. The SDK:

* polls quickly at first, then more slowly
* times out after five minutes
* retries transient fetch failures
* throws dedicated task and polling error classes

Read [SDK tasks](/sdk/js-ts/tasks) for the exact behavior.
