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.
| Field | Default | Notes |
|---|---|---|
model | auto | A catalog id. Always pass one. auto is experimental |
prompt | required | 1 to 8192 characters |
negative_prompt | none | Up to 8192 characters. Dropped without an error if the model has none |
count | 1 | 1 to 20. Each image succeeds or fails on its own |
size | auto | See sizes |
inputs | none | Up to 20 input images. See image to image |
magic_prompt | false | Rewrite the prompt first. See enhance prompts |
rating | none | true, or a rating object. See rate images |
output.format | the provider's | png, jpg, or webp |
destination | none | A destination name. See destinations |
webhook | registered ones | Per-request URLs. See webhooks |
metadata | none | A JSON object up to 2048 bytes, returned on the task and in webhooks |
access | token 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.
size | Result |
|---|---|
square, portrait, landscape, portrait_tall, landscape_wide | 1: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:2 | that ratio |
Any ratio with _4k, such as 16:9_4k | that 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
statuson every image. One image failing does not fail the task. See tasks. urlis where the file ended up: your storage when you named a destination, otherwise the same asmynth_url.sizeis the delivered file in{width}x{height}pixels.result.modelis 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#
- Choosing an image model: what to check before you pin an id.
- Image to image: send input images.
- Poll for results: collect the task over REST.