Generate images

The image generation request, every field it takes, the sizes you can ask for, and what comes back.

POST /image/generate creates an image task. Send a model id and a prompt. Everything else is optional.

import Mynth from "@mynthio/sdk";

const mynth = new Mynth();

const task = await mynth.image.generate({
  model: "black-forest-labs/flux.2-pro",
  prompt: "A lighthouse at dusk, film grain",
  size: "landscape",
});

console.log(task.urls[0]);

The SDK and the CLI wait and return the finished task. The REST call returns at once with a task id:

{
  "data": {
    "taskId": "tsk_01KE7XWWEQ4MCGWKBQKJ1G47RP",
    "estimatedCost": "0.03",
    "access": { "publicAccessToken": "pat_eyJhbGciOiJIUzI1NiJ9..." }
  }
}

Collect the result by polling or with a webhook.

Fields#

Every image model takes this body.

FieldDefaultNotes
modelautoA catalog id. Always pass one. auto is experimental
promptrequired1 to 8192 characters
negative_promptnoneUp to 8192 characters. Dropped without an error if the model has none
count11 to 20. Each image succeeds or fails on its own
sizeautoSee sizes
inputsnoneUp to 20 input images. See image to image
magic_promptfalseRewrite the prompt first. See enhance prompts
ratingnonetrue, or a rating object. See rate images
output.formatthe provider'spng, jpg, or webp
destinationnoneA destination name. See destinations
webhookregistered onesPer-request URLs. See webhooks
metadatanoneA JSON object up to 2048 bytes, returned on the task and in webhooks
accesstoken issued{ "pat": { "enabled": false } } skips the browser token

Fields the schema does not know are dropped without an error. If a setting seems to have no effect, check the task's request, which shows the body as it was accepted.

Sizes#

You ask for a shape, not pixels, and Mynth picks the closest size the model serves. Omit size, or send "auto", and Mynth picks a ratio that suits the prompt.

sizeResult
square, portrait, landscape, portrait_tall, landscape_wide1:1, 2:3, 3:2, 9:16, 16:9
1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 2:1, 1:2that ratio
Any ratio with _4k, such as 16:9_4kthat ratio at 4k
{ "type": "aspect_ratio", "aspectRatio": "16:9", "scale": "4k" }the same, as an object

A ratio the model has no preset for snaps to the closest one it serves. A 4k size costs perImage["4k"] and needs a model that has it. On a model without 4k the task fails with CAPABILITY_NOT_SUPPORTED.

What comes back#

A completed task has one entry in result.images per requested image:

{
  "model": "black-forest-labs/flux.2-pro",
  "images": [
    {
      "status": "success",
      "id": "img_V1StGXR8Z5jdHi6BmyT0sC1pQ2rN4wLk",
      "url": "https://cdn.mynth.io/images/img_V1StGXR8Z5jdHi6BmyT0sC1pQ2rN4wLk.webp",
      "mynth_url": "https://cdn.mynth.io/images/img_V1StGXR8Z5jdHi6BmyT0sC1pQ2rN4wLk.webp",
      "size": "1536x1024",
      "format": "webp"
    }
  ]
}
  • Check status on every image. One image failing does not fail the task. See tasks.
  • url is where the file ended up: your storage when you named a destination, otherwise the same as mynth_url.
  • size is the delivered file in {width}x{height} pixels.
  • result.model is the model that ran.
  • The file is served for 7 days. See file lifetimes.

Every field of the result is on the task object.

Price#

The create response holds estimatedCost, and you pay only for the images that succeed. Pricing has the formula, and estimate cost prices a body without generating.

Next steps#