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

> ## Agent Instructions
> Authenticate every request with your API key in the `X-API-Key` header or `Authorization: Bearer`. Keys start with `sk-nunchux-`.
> Image generation is synchronous: the image is in the response.
> Video generation is asynchronous: submit the job, poll its task until it reaches a terminal status, then download the output promptly, because output URLs expire.

# Text-to-image

> Generate an image from a text prompt with a Nunchux Optimized model. The image is in the response.

# Text-to-image

Send a text prompt, and the response contains the generated image. The request is synchronous. There is no task to poll.

## Models

| Model | Model ID | Use it for |
| - | - | - |
| FLUX.2 Klein 9B | `nunchux-flux.2-klein-9b` | Production output. Strong prompt adherence and clean text. |
| FLUX.2 Klein 4B | `nunchux-flux.2-klein-4b` | The fastest output. Fast iteration and batch jobs. |
| FLUX.2 dev | `nunchux-flux.2-dev` | More detail than Klein, in more steps. Has a guidance control. |
| FLUX.2 dev Flash | `nunchux-flux.2-dev-flash` | FLUX.2 dev's detail in about a second. No guidance or negative prompt. |
| FLUX.1 dev | `nunchux-flux.1-dev` | The earlier full-step FLUX model. Has a guidance control. |
| FLUX 3 Image Klein | `nunchux-flux.3-image-klein` | The newest FLUX generation, in 16 steps, up to 4096x4096. No guidance or negative prompt. |
| FLUX 3 Image Klein Base | `nunchux-flux.3-image-klein-base` | The undistilled FLUX 3 Image Klein, in 16 to 50 steps, with a guidance control and a negative prompt. Slower than FLUX 3 Image Klein. |
| FLUX.1 Schnell | `nunchux-flux.1-schnell` | The earlier FLUX generation, for work that already depends on it. |
| Qwen Image | `nunchux-qwen-image` | Text in the image, with more detail than Lightning, in more steps. |
| Qwen Image 2512 Lightning | `nunchux-qwen-image-2512-lightning` | The best text rendering, in English and Chinese. Typography and layout. |
| Qwen Image 2512 | `nunchux-qwen-image-2512` | More detail than Qwen Image 2512 Lightning, in 50 steps. Has a guidance control and a negative prompt. |
| Qwen Image 2.1 | `nunchux-qwen-image-2.1` | Images up to 2752x2752, with a negative prompt. |
| HiDream O1 | `nunchux-hidream-o1-image` | Large, photographic images up to four megapixels. Slower than FLUX and Qwen. |
| HiDream O1 Flash | `nunchux-hidream-o1-image-flash` | HiDream O1's sizes, faster. No guidance or negative prompt. |
| Ideogram 4 | `nunchux-ideogram-4` | Legible words in the image: posters, labels and covers. Slower than FLUX and Qwen. |
| Z-Image Turbo | `nunchux-z-image-turbo` | Fast photographic images in 8 steps. No guidance or negative prompt. |
| Krea 2 Turbo | `nunchux-krea-2-turbo` | Fast photographic images in 8 steps, up to 2048x2048. No guidance or negative prompt. |

See [Choosing a model](https://docs.nunchux.ai/nunchux-optimized/overview.md#choosing-a-model) for a comparison, and [Performance tiers](https://docs.nunchux.ai/performance-tiers.md) for the tiers that each model serves.

## Endpoint

```text theme={"system"}
POST https://api.nunchux.com/v1/images/generations
```

## Request

Every request must include your API key and a JSON content type. See [Authentication](https://docs.nunchux.ai/authentication.md).

**X-API-Key** `string` *required*

Your API key.

**Content-Type** `string` *required*

Must be `application/json`.

**model** `string` *required*

The model that generates the image.

Options: `nunchux-flux.2-klein-4b`, `nunchux-flux.2-klein-9b`, `nunchux-flux.1-schnell`, `nunchux-flux.1-dev`, `nunchux-flux.2-dev`, `nunchux-flux.2-dev-flash`, `nunchux-flux.3-image-klein`, `nunchux-flux.3-image-klein-base`, `nunchux-qwen-image`, `nunchux-qwen-image-2512-lightning`, `nunchux-qwen-image-2512`, `nunchux-qwen-image-2.1`, `nunchux-hidream-o1-image`, `nunchux-hidream-o1-image-flash`, `nunchux-ideogram-4`, `nunchux-z-image-turbo`, `nunchux-krea-2-turbo`

**prompt** `string` *required*

A text description of the image. Specific, descriptive prompts give better results.

On Qwen Image 2.1, the prompt can use up to 8192 tokens. A longer prompt returns a 400 with `error.details.field` set to `prompt`.

**tier** `string` (default: radical\_speed)

The balance of speed and cost. See [Performance tiers](https://docs.nunchux.ai/performance-tiers.md).

Options: `radical_speed`, `radical_value`

FLUX.1 dev, FLUX.2 dev and Qwen Image have `radical_speed` only. On these models, `radical_value` returns a 400.

FLUX.2 dev Flash has `radical_value` only. Send `"tier": "radical_value"`. A request without `tier` uses `radical_speed`, so it returns a 400.

Do not send this field to Ideogram 4. On Ideogram 4, `extra.rendering_speed` selects the tier.

**width** `integer`

Output width in pixels. Send it together with `height`. Required on models priced per megapixel. Today, that is every model except Ideogram 4, which uses 1024x1024 when you send no dimensions. Range: 1 to 8192. On Ideogram 4: 1024 to 2048, in steps of 16. On Z-Image Turbo: 256 to 2048, in steps of 16. On Krea 2 Turbo: 1024 to 2048, in steps of 16. On FLUX.1 dev: 256 to 2048, in steps of 32. On FLUX.2 dev, FLUX.2 dev Flash, Qwen Image and Qwen Image 2512: 256 to 2048, in steps of 16. On FLUX 3 Image Klein and FLUX 3 Image Klein Base: 256 to 4096, in steps of 16. On Radical Value, FLUX 3 Image Klein and FLUX 3 Image Klein Base take at most 4,194,304 pixels (`width` times `height`, the area of 2048x2048), so 4096x1024 works and 2576x1632 returns a 400. On Qwen Image 2.1: 256 to 2752, in steps of 32. On HiDream O1 and HiDream O1 Flash: one of the sizes listed under Dimensions below.

**height** `integer`

Output height in pixels. Send it together with `width`. Required on models priced per megapixel. Today, that is every model except Ideogram 4, which uses 1024x1024 when you send no dimensions. Range: 1 to 8192. On Ideogram 4: 1024 to 2048, in steps of 16. On Z-Image Turbo: 256 to 2048, in steps of 16. On Krea 2 Turbo: 1024 to 2048, in steps of 16. On FLUX.1 dev: 256 to 2048, in steps of 32. On FLUX.2 dev, FLUX.2 dev Flash, Qwen Image and Qwen Image 2512: 256 to 2048, in steps of 16. On FLUX 3 Image Klein and FLUX 3 Image Klein Base: 256 to 4096, in steps of 16. On Radical Value, FLUX 3 Image Klein and FLUX 3 Image Klein Base take at most 4,194,304 pixels (`width` times `height`, the area of 2048x2048), so 4096x1024 works and 2576x1632 returns a 400. On Qwen Image 2.1: 256 to 2752, in steps of 32. On HiDream O1 and HiDream O1 Flash: one of the sizes listed under Dimensions below.

**steps** `integer`

HiDream O1, HiDream O1 Flash, FLUX.1 dev, FLUX.2 dev, FLUX.2 dev Flash, FLUX 3 Image Klein, FLUX 3 Image Klein Base, Qwen Image, Qwen Image 2512, Qwen Image 2.1, Z-Image Turbo and Krea 2 Turbo only. The number of denoising steps. Range: 1 to 16 on Z-Image Turbo and FLUX 3 Image Klein, 1 to 8 on Krea 2 Turbo, 12 to 50 on FLUX.2 dev Flash, 16 to 50 on FLUX 3 Image Klein Base, 1 to 50 on the others. Default: 28 on FLUX.1 dev, 40 on Qwen Image 2.1, 16 on FLUX 3 Image Klein, 8 on Z-Image Turbo and Krea 2 Turbo, 50 on the others. More steps give more detail, but take longer.

On FLUX.2 dev Flash, the step count does not change the image or the time. The model is distilled, and every count it accepts runs the same schedule. It accepts `steps` so that a FLUX.2 dev request also works on it.

Do not send this field to Ideogram 4: it returns a 400. On Ideogram 4, `extra.rendering_speed` selects the tier.

**true\_cfg\_scale** `number`

HiDream O1, Qwen Image, Qwen Image 2512, Qwen Image 2.1 and FLUX.1 dev only. How closely the image follows the prompt. Range: 0.0 to 20.0. Default: 5.0 on HiDream O1, 4.0 on Qwen Image and Qwen Image 2512, 1.0 on Qwen Image 2.1, off on FLUX.1 dev. Higher values follow the prompt more closely. Lower values give the model more freedom. On Qwen Image, Qwen Image 2512, Qwen Image 2.1 and FLUX.1 dev, it also sets how strongly the image avoids the `negative_prompt`.

On FLUX.1 dev, send it with `negative_prompt`, at a value above 1.0. The model then renders a second pass for the negative prompt, so the request takes longer. Without it, FLUX.1 dev ignores `negative_prompt`.

On Qwen Image 2.1, the default 1.0 has no effect. Send a value above 1.0 together with `negative_prompt`.

**guidance\_scale** `number`

FLUX.1 dev, FLUX.2 dev and FLUX 3 Image Klein Base only. How closely the image follows the prompt. Range: 0.0 to 20.0. Default: 3.5 on FLUX.1 dev, 4.0 on FLUX.2 dev and FLUX 3 Image Klein Base.

**negative\_prompt** `string`

Qwen Image, Qwen Image 2512, Qwen Image 2.1, FLUX.1 dev and FLUX 3 Image Klein Base only. What the image must not show. On FLUX.1 dev and Qwen Image 2.1, it takes effect only when you also send `true_cfg_scale` above 1.0.

**prompt\_expansion** `string` (default: off)

Ideogram 4, FLUX 3 Image Klein and FLUX 3 Image Klein Base only. With any mode other than `off`, Nunchux rewrites the prompt into a detailed scene description before the image renders. On Ideogram 4, `fast` adds a few seconds. `standard`, `balanced` and `quality` take longer: up to about 40, 45 and 55 seconds. If the rewrite fails, the image renders from your prompt, and the response has no `revised_prompt`. On FLUX 3 Image Klein and FLUX 3 Image Klein Base, `standard` is the only mode, and it adds about 3 to 4 seconds. The response returns the rewritten prompt as `revised_prompt`. FLUX 3 Image Klein and FLUX 3 Image Klein Base follow a full description of the scene much better than a short prompt, so send `standard` unless your prompt already describes the subject, the setting, the light and the style.

Options: `off`, `fast`, `standard`, `balanced`, `quality`. On FLUX 3 Image Klein and FLUX 3 Image Klein Base: `off`, `standard`.

**extra** `object`

Model options.

**properties**

**rendering\_speed** `string` (default: quality)

Ideogram 4 only. Selects the tier. `turbo` is the fastest and costs the least, but gives less detail. `quality` gives the most detail. A request without it renders and is billed as Quality.

Options: `turbo`, `balanced`, `quality`

**n** `integer` (default: 1)

The number of images to generate. Only 1 is supported.

**response\_format** `string` (default: b64\_json)

The format of the returned image.

Options: `url`, `b64_json`

In both formats, Nunchux keeps the generated image for 7 days, so that it appears in your request history. Then Nunchux deletes it.

**seed** `integer`

The random seed. The same seed with the same parameters gives the same result.

**content\_moderation** `boolean` (default: true)

Whether Nunchux's content filter checks this request. Only accounts approved to turn moderation off may send `false`. Others get a 403. See [Content moderation](https://docs.nunchux.ai/content-moderation.md).

> [!NOTE]
>
> Dimensions
>
> * Send `width` and `height` together. A request with only one of them returns a 400.
> * Models priced per megapixel charge from the output area, so they require `width` and `height`. A request with no dimensions returns a 400. The API does not choose a default size for these models. The [pricing page](https://nunchux.ai/pricing) shows each model's unit. Today, every text-to-image model except Ideogram 4 is priced per megapixel.
> * Both values must be integers. The string `"1024"` is rejected, not converted.
> * Larger images take longer to generate.
> * HiDream O1 and HiDream O1 Flash render these sizes: 1024x1024, 2048x2048, 2304x1728, 1728x2304, 2560x1440, 1440x2560, 2496x1664, 1664x2496, 3104x1312, 1312x3104, 2304x1792, 1792x2304. On HiDream O1 Flash, another size is not refused: the image comes back at the closest of these sizes, by aspect ratio first, which can be larger than you asked for. A request for 1536x1024 returns 2496x1664. Send one of the listed sizes to get the size you ask for.

A minimal request body:

```json theme={"system"}
{
  "model": "nunchux-qwen-image-2512-lightning",
  "tier": "radical_speed",
  "prompt": "A beautiful sunset over mountains",
  "width": 1024,
  "height": 1024,
  "response_format": "b64_json",
  "seed": 42
}
```

A request body for Qwen Image 2.1, with a negative prompt:

```json theme={"system"}
{
  "model": "nunchux-qwen-image-2.1",
  "tier": "radical_speed",
  "prompt": "A bookshop window at dusk with a hand-painted sign that reads \"OPEN LATE\"",
  "negative_prompt": "blurry, low contrast",
  "true_cfg_scale": 4.0,
  "width": 1024,
  "height": 1024,
  "response_format": "b64_json",
  "seed": 42
}
```

A request body for FLUX 3 Image Klein, with prompt expansion. The response returns the rewritten prompt in `data[0].revised_prompt`:

```json theme={"system"}
{
  "model": "nunchux-flux.3-image-klein",
  "tier": "radical_speed",
  "prompt": "A red bicycle leaning on a brick wall",
  "prompt_expansion": "standard",
  "width": 1024,
  "height": 1024,
  "response_format": "b64_json",
  "seed": 42
}
```

## Response

The response is JSON. The `data` array contains the image, as base64 data or as a URL.

**created** `integer` *required*

The Unix timestamp of the generation.

**data** `array` *required*

The generated items.

**Item properties**

**url** `string`

The URL of the image. Returned when `response_format` is `url`.

**b64\_json** `string`

The image as base64 data. Returned when `response_format` is `b64_json`.

**revised\_prompt** `string`

Ideogram 4, FLUX 3 Image Klein and FLUX 3 Image Klein Base only. The rewritten prompt that the model rendered. Returned when `prompt_expansion` is not `off` and the rewrite succeeds. To make the same image again, send it as `prompt` with `prompt_expansion` set to `off`, the same `seed` and the same size. On FLUX 3 Image Klein, also send the same `steps`. On FLUX 3 Image Klein Base, also send the same `steps`, `guidance_scale` and `negative_prompt`. On Ideogram 4, also send the same `extra.rendering_speed`.

**model** `string` *required*

The model that generated the image.

**tier** `string` *required*

The tier that served the request: `radical_speed` or `radical_value`. On Ideogram 4 this field is always `radical_speed` and does not show the Turbo, Balanced or Quality tier. The `extra.rendering_speed` you sent selects that tier.

```json Base64 format theme={"system"}
{
  "created": 1234567890,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAYAAAB/HSuDAAAACXBIWXMAAA7EAAAOxAGVKw4b..."
    }
  ],
  "model": "nunchux-qwen-image-2512-lightning",
  "tier": "radical_speed"
}
```

```json URL format theme={"system"}
{
  "created": 1234567890,
  "data": [
    {
      "url": "https://example.com/generated-image.png"
    }
  ],
  "model": "nunchux-qwen-image-2512-lightning",
  "tier": "radical_speed"
}
```

To save a base64 result from cURL, add this pipe to the command:

```bash theme={"system"}
# Replace output.jpg with the file name that you want.
| jq -r '.data[0].b64_json // error(.error.message // .detail // tostring)' | base64 -d > output.jpg
```

## Example

```bash cURL theme={"system"}
curl -X POST https://api.nunchux.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $NUNCHUX_API_KEY" \
  -d '{
    "model": "nunchux-flux.2-klein-9b",
    "tier": "radical_speed",
    "prompt": "cozy coffee shop interior with vintage furniture",
    "width": 1024,
    "height": 1024,
    "response_format": "b64_json",
    "seed": 42
  }' | jq -r '.data[0].b64_json // error(.error.message // .detail // tostring)' | base64 -d > output.jpg
```

```python Python theme={"system"}
import os
import base64
import requests

response = requests.post(
    "https://api.nunchux.com/v1/images/generations",
    headers={
        "Content-Type": "application/json",
        "X-API-Key": os.environ["NUNCHUX_API_KEY"],
    },
    json={
        "model": "nunchux-flux.2-klein-9b",
        "tier": "radical_speed",
        "prompt": "cozy coffee shop interior with vintage furniture",
        "width": 1024,
        "height": 1024,
        "response_format": "b64_json",
        "seed": 42,
    },
)

# Decode the base64 image and save it. Change output.jpg to any file name.
image_b64 = response.json()["data"][0]["b64_json"]
with open("output.jpg", "wb") as f:
    f.write(base64.b64decode(image_b64))
```

```javascript JavaScript theme={"system"}
import { writeFile } from "node:fs/promises";

const response = await fetch("https://api.nunchux.com/v1/images/generations", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": process.env.NUNCHUX_API_KEY,
  },
  body: JSON.stringify({
    model: "nunchux-flux.2-klein-9b",
    tier: "radical_speed",
    prompt: "cozy coffee shop interior with vintage furniture",
    width: 1024,
    height: 1024,
    response_format: "b64_json",
    seed: 42,
  }),
});
const data = await response.json();

// Decode the base64 image and save it. Change output.jpg to any file name.
await writeFile("output.jpg", Buffer.from(data.data[0].b64_json, "base64"));
```

```python Python (OpenAI) theme={"system"}
import os
import base64

from openai import OpenAI

client = OpenAI(
    base_url="https://api.nunchux.com/v1",
    api_key=os.environ["NUNCHUX_API_KEY"],
)

# The OpenAI SDK has no width/height parameter. Send them in `extra_body`,
# which the SDK merges into the request body.
response = client.images.generate(
    model="nunchux-flux.2-klein-9b",
    prompt="cozy coffee shop interior with vintage furniture",
    n=1,
    response_format="b64_json",
    extra_body={"width": 1024, "height": 1024},
)

# Decode the base64 image and save it. Change output.jpg to any file name.
image_b64 = response.data[0].b64_json
with open("output.jpg", "wb") as f:
    f.write(base64.b64decode(image_b64))
```

## Tips

* Write detailed prompts. Include the style, lighting, composition, colors, materials and atmosphere.
* Use FLUX.2 Klein 9B for production output. Use FLUX.2 Klein 4B when speed is more important than detail.
* Use Qwen Image when the image must contain text, and for Chinese text. Use Ideogram 4 when the words must be legible on a poster, a label or a cover. Put the exact words in quotes or capitals, and say where they go.
* Use Qwen Image 2512 when you want more detail than Qwen Image 2512 Lightning gives and the extra time is acceptable. Use `negative_prompt` to keep things out of the image.
* Use HiDream O1 for large, photographic images. Describe the light and the materials. A larger size costs more, because the price is per megapixel.
* Use HiDream O1 Flash for HiDream O1's large sizes in less time. Put everything in the prompt: it takes no guidance and no negative prompt.
* Use FLUX.2 dev Flash to try many prompts quickly at FLUX.2 dev's detail. Send `tier` as `radical_value`. To get a different image, change the `seed`, not `steps`. Put everything in the prompt: it takes no guidance and no negative prompt.
* Use FLUX.2 dev or FLUX.1 dev when you want more detail than FLUX.2 Klein gives, and the extra time is acceptable. Steer them with `guidance_scale`. On FLUX.1 dev, to keep things out of the image, send `negative_prompt` with `true_cfg_scale` above 1.0, at the cost of a second pass.
* Use FLUX 3 Image Klein for fast output from the newest FLUX generation. Write a full description of the scene: the subject, the setting, the light, the composition and the style. A short prompt gives a generic image. To have Nunchux write the description from a short prompt, send `prompt_expansion` set to `standard`. Keep the default 16 steps. It takes no guidance and no negative prompt.
* Use FLUX 3 Image Klein Base when you want more detail or more control than FLUX 3 Image Klein gives, and the extra time is acceptable. Steer it with `guidance_scale` and `negative_prompt`. Send `prompt_expansion` set to `standard` for a short prompt.
* Use Qwen Image 2.1 for images up to 2752x2752. Send `width` and `height` in multiples of 32. To keep things out of the image, send `negative_prompt` with `true_cfg_scale` above 1.0.
* Use Z-Image Turbo for fast photographic images. It is step-distilled: keep the default 8 steps, and describe what you want in the prompt, because it takes no guidance and no negative prompt.
* Use Krea 2 Turbo for fast photographic images at larger sizes, up to 2048x2048. Each side must be at least 1024. Keep the default 8 steps, and leave out guidance and the negative prompt. The same prompt and seed give a close result, but not always an identical image.
* On Ideogram 4, draft with `extra.rendering_speed` set to `turbo`. Use `quality` for the final image.
* On FLUX.2 Klein, FLUX 3 Image Klein, FLUX 3 Image Klein Base, Qwen Image 2512, Qwen Image 2512 Lightning, Qwen Image 2.1, HiDream O1, HiDream O1 Flash, Z-Image Turbo and Krea 2 Turbo, use `radical_speed` when response time is important. Use `radical_value` for large batches where cost per image is more important.
* Keep the `seed` when you like a result. Then change one parameter at a time.

## Errors and limits

| Status | Code | Cause |
| - | - | - |
| 400 | none | A required field is missing, the model ID is not valid, or a value is not valid. The body is a plain `detail` string. |
| 400 | `invalid_request` | The model does not offer the `tier` you sent, for example `radical_value` on FLUX.1 dev, or `radical_speed` on FLUX.2 dev Flash. `error.details.reason` is `tier_not_available`. |
| 400 | `invalid_request` | The model does not take a field you sent, or does not take its value: a size outside the model's range or off its grid, a `steps` value out of range, or a field the model does not take. For example: `guidance_scale` on Qwen Image and Qwen Image 2.1; `prompt_expansion` on Qwen Image 2.1; `true_cfg_scale` or `prompt_expansion` on Z-Image Turbo; `guidance_scale` or `negative_prompt` on Krea 2 Turbo and FLUX 3 Image Klein; `guidance_scale`, `true_cfg_scale` or `negative_prompt` on HiDream O1 Flash and FLUX.2 dev Flash; a `steps` value above 16 on FLUX 3 Image Klein, outside 16 to 50 on FLUX 3 Image Klein Base, or outside 12 to 50 on FLUX.2 dev Flash; an area above 4,194,304 pixels on the Radical Value tier of FLUX 3 Image Klein or FLUX 3 Image Klein Base; 1040x1040 on FLUX.1 dev or Qwen Image 2.1. `error.details.field` names the field, and `error.details.reason` is `field_not_accepted`. |
| 400 | `engine_error` | The model accepted the request but cannot render it. |
| 403 | `model_not_available` | Your account does not have access to this model. |

> [!NOTE]
>
> Refused requests
>
> * Nunchux charges only after a successful generation. A refused request is never billed.
> * Do not branch on a dimension-specific code. A refused size, `steps` value or field returns `invalid_request`, and `error.details.field` names the field. `engine_error` means the model could not render a request it accepted.

For authentication, credit and rate-limit errors, see [Error codes](https://docs.nunchux.ai/errors.md). Every request counts toward the requests-per-minute cap of your plan. See [Rate limits](https://docs.nunchux.ai/rate-limits.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.