# Generate image

> Queues an image generation and returns the task straight away — generation itself is asynchronous. Follow the task by polling its status or by receiving a webhook. The cost is reserved up front and reconciled when the task finishes, so a partial failure is refunded.

Creates an image task and returns its id. Nothing in the response is an image
yet. Wait for the task by [polling](https://mynth.io/docs/guides/poll-for-results.md) or with a
[webhook](https://mynth.io/docs/concepts/webhooks.md), or let the SDK's `image.generate()` wait
for you.

Always pass `model`. When it is omitted, the API uses `auto`, which is
experimental. See [the model field](https://mynth.io/docs/models.md#auto-is-experimental).
[Generate images](https://mynth.io/docs/guides/generate-images.md) covers sizes and the result.

`POST /image/generate`

**Auth:** API key or OAuth token

## Request body

- `model` (string) — Default `"auto"`. One of: `"alibaba/qwen-image-2.0"`, `"alibaba/qwen-image-2.0-pro"`, `"alibaba/qwen-image-2.1-pro"`, `"alibaba/qwen-image-3.0"`, `"alibaba/qwen-image-3.0-pro"`, `"bytedance/seedream-5.0-lite"`, `"bytedance/seedream-pro"`, `"bytedance/seedream-v5-flash"`, `"black-forest-labs/flux-1-schnell"`, `"black-forest-labs/flux.1-dev"`, `"black-forest-labs/flux.2-dev"`, `"black-forest-labs/flux.2-pro"`, `"black-forest-labs/flux.2-flex"`, `"black-forest-labs/flux.2-max"`, `"black-forest-labs/flux.2-klein-4b"`, `"black-forest-labs/flux-3"`, `"bria/fibo-edit-1.5"`, `"bria/fibo-generate-1.5"`, `"circlestone-labs/anima"`, `"goofy-ai/prefect-pony-xl-lora"`, `"google/gemini-3.1-flash-lite-image"`, `"google/gemini-3.1-flash-image"`, `"google/gemini-nano-banana-2.1"`, `"google/gemini-3-pro-image-preview"`, `"ideogram/ideogram-4.5"`, `"imagineart/imagineart-1.5-pro"`, `"imagineart/imagineart-2.0"`, `"john6666/bismuth-illustrious-mix"`, `"klingai/kling-image-3.0"`, `"klingai/kling-image-o3"`, `"krea/krea-2-turbo"`, `"krea/krea-2-medium"`, `"krea/krea-2-large"`, `"luma/uni-1"`, `"luma/uni-1-max"`, `"maxfeifei8/one-obsession"`, `"meta/muse-image"`, `"microsoft/mai-image-2.6"`, `"microsoft/mai-image-2.6-flash"`, `"minimax/h3"`, `"openai/gpt-image-2"`, `"openai/gpt-image-2.5-flare"`, `"openai/gpt-image-2.5-sunburst"`, `"purplesmartai/pony-diffusion-v6-xl"`, `"recraft/recraft-v4"`, `"recraft/recraft-v4.1-flash"`, `"recraft/recraft-v4-pro"`, `"reve/reve"`, `"reve/reve-remix"`, `"sourceful/riverflow-2.0-pro"`, `"tongyi-mai/z-image"`, `"tongyi-mai/z-image-turbo"`, `"wan/wan2.6-image"`, `"wan/wan2.7-image"`, `"wan/wan2.7-image-pro"`, `"xai/grok-imagine-image"`, `"xai/grok-imagine-image-2.0"`, `"xai/grok-imagine-image-quality"`, `"auto"`. Example `"black-forest-labs/flux.2-pro"`.
- `prompt` (required, string) — Positive prompt. ≥ 1 characters, ≤ 8192 characters. Example `"Cute Cat"`.
- `negative_prompt` (string) — ≤ 8192 characters.
- `magic_prompt` (boolean)
- `count` (integer) — Default `1`. ≥ 1, ≤ 20.
- `size` (object | string) — One of: `"auto"`, `"square"`, `"portrait"`, `"landscape"`, `"portrait_tall"`, `"landscape_wide"`, `"1:1"`, `"2:3"`, `"3:2"`, `"3:4"`, `"4:3"`, `"4:5"`, `"5:4"`, `"9:16"`, `"16:9"`, `"21:9"`, `"2:1"`, `"1:2"`, `"1:1_4k"`, `"2:3_4k"`, `"3:2_4k"`, `"3:4_4k"`, `"4:3_4k"`, `"4:5_4k"`, `"5:4_4k"`, `"9:16_4k"`, `"16:9_4k"`, `"21:9_4k"`, `"2:1_4k"`, `"1:2_4k"`.
  - **auto**
    - `type` (required, "auto")
  - **aspect_ratio**
    - `type` (required, "aspect_ratio")
    - `aspect_ratio` (required, string) — One of: `"1:1"`, `"2:3"`, `"3:2"`, `"3:4"`, `"4:3"`, `"4:5"`, `"5:4"`, `"9:16"`, `"16:9"`, `"21:9"`, `"2:1"`, `"1:2"`.
    - `scale` (string) — Default `"base"`. One of: `"base"`, `"4k"`.
- `inputs` ((string | object)[]) — ≤ 20 items.
  - **type + source**
    - `type` (required, "image")
    - `as` (string) — One of: `"auto"`, `"source"`, `"reference"`.
    - `source` (required, object)
      - `type` (required, "url")
      - `url` (required, string) — format: uri.
- `rating` (object | boolean) — One of: `true`.
  - **nsfw_sfw**
    - `mode` ("nsfw_sfw") — Default `"nsfw_sfw"`.
  - **custom**
    - `mode` (required, "custom")
    - `levels` (required, object[]) — ≥ 2 items, ≤ 7 items.
      - `value` (required, string) — ≥ 1 characters, ≤ 24 characters.
      - `description` (required, string) — ≥ 1 characters, ≤ 150 characters.
- `output` (object)
  - `format` (string) — One of: `"png"`, `"jpg"`, `"webp"`.
- `generate_public_access_token` (boolean) — Return a short-lived public access token as `public_access_token`, for polling this task from browser code without your API key. Defaults to false.
- `webhook` (object)
  - `registered` (boolean) — Set to false to skip the webhooks registered on the account for this task. Custom webhooks in `custom` are still sent.
  - `custom` (object[]) — ≥ 1 items, ≤ 5 items.
    - `url` (required, string) — Receives this task's events, unsigned. Use https and a public host, and put a secret token in the query string to verify deliveries: only `scheme://host` is ever shown back. Example `"https://example.com/hooks/mynth?token=your-secret-token"`.
- `destination` (string) — ≥ 1 characters, ≤ 64 characters. Example `"bunny-prod"`.
- `metadata` (object)

## Response

### 201 — Image generation task created

- `data` (required, object)
  - `task_id` (required, string) — Task ID Example `"tsk_01KE7XWWEQ4MCGWKBQKJ1G47RP"`.
  - `estimated_cost` (required, string) — Estimated cost in USD reserved for this task. Work that fails is refunded, so the final cost may be lower. Example `"0.03"`.
  - `public_access_token` (string) — Short-lived public access token for polling this task's status and result. Safe to hand to browser code instead of your API key. Returned only when the request set `generate_public_access_token: true`. Example `"pat_eyJhbGciOi..."`.

```json
{
  "data": {
    "task_id": "tsk_01KE7XWWEQ4MCGWKBQKJ1G47RP",
    "estimated_cost": "0.03",
    "public_access_token": "pat_eyJhbGciOi..."
  }
}
```

### 400 — The request was rejected before anything was queued. `error.message` says what to change. A field that failed the schema, or one the endpoint does not take, is also listed in `error.issues`.

- `error` (required, object)
  - `code` (required, string) — `validation_error` for a body that failed validation, `invalid_json` for one that is not JSON. One of: `"validation_error"`, `"invalid_json"`.
  - `message` (required, string) — Every problem, in one sentence each, led by the field it is about.
  - `issues` (object[]) — One entry per field that failed the schema, and one per field the endpoint does not take.
    - `path` (required, (string | integer)[]) — Where the problem is, e.g. `["inputs", 0, "source"]`. Empty for the body as a whole.
    - `message` (required, string)

```json
{
  "error": {
    "code": "validation_error",
    "message": "count: Too big: expected number to be <=20. colour: Unknown field.",
    "issues": [
      {
        "path": [
          "count"
        ],
        "message": "Too big: expected number to be <=20"
      },
      {
        "path": [
          "colour"
        ],
        "message": "Unknown field."
      }
    ]
  }
}
```

## Request samples

### cURL

```bash
curl -X POST https://api.mynth.io/image/generate \
  -H "Authorization: Bearer $MYNTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "black-forest-labs/flux.2-pro",
    "prompt": "Cute Cat",
    "destination": "bunny-prod"
  }'
```

### JavaScript

```ts
const response = await fetch("https://api.mynth.io/image/generate", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MYNTH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "black-forest-labs/flux.2-pro",
    "prompt": "Cute Cat",
    "destination": "bunny-prod"
  }),
});

const { data } = await response.json();
```

The full schema for this endpoint is in the [OpenAPI document](https://api.mynth.io/openapi.json).
