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

# Image generation

> Generate and edit images with GPT Image, Nano Banana, FLUX and more.

<div className="ndoc-brand-strip"><span className="ndoc-brand"><span className="ndoc-brand-mark"><img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/6cf26e8b/openai.svg" alt="" width="28" height="28" loading="lazy" /></span><span>GPT Image</span></span><span className="ndoc-brand"><span className="ndoc-brand-mark"><img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/263e7dab/gemini.svg" alt="" width="28" height="28" loading="lazy" /></span><span>Nano Banana</span></span><span className="ndoc-brand"><span className="ndoc-brand-mark"><img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/09b9d42e/bfl.png" alt="" width="28" height="28" loading="lazy" /></span><span>FLUX</span></span><span className="ndoc-brand"><span className="ndoc-brand-mark"><img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/86e0e433/bytedance.svg" alt="" width="28" height="28" loading="lazy" /></span><span>Seedream</span></span></div>

<div className="ndoc-media-gallery">
  <img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/mcp/ff91269f/kiyo-citrus-studio.webp" alt="Citrus drink campaign with sculptural studio lighting" width="480" height="600" loading="lazy" />

  <img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/mcp/d78d5571/kiyo-poolside.webp" alt="Summer drink campaign beside a turquoise pool" width="480" height="600" loading="lazy" />

  <img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/mcp/b7a461f7/kiyo-volcanic-poster.webp" alt="Drink campaign against a dramatic volcanic landscape" width="480" height="600" loading="lazy" />
</div>

## Generate an image

Send a prompt. Get an image URL.

```json POST /api/v1/images/generations theme={null}
{
  "model": "flux-2-klein",
  "prompt": "A golden retriever puppy in autumn leaves, soft lighting, photorealistic",
  "size": "1920x1920",
  "n": 1
}
```

```json Response theme={null}
{
  "created": 1787529600,
  "model": "flux-2-klein",
  "provider": "...",
  "data": [{"url": "https://cdn.../generated-abc123.webp", "revised_prompt": "..."}],
  "usage": {"images_generated": 1},
  "cost_usd": 0.014,
  "request_id": "req_...",
  "routing": {"provider_attempts": ["..."], "retries": 0}
}
```

With default durable storage, your image URL is in `data[0].url`. The response also includes cost and request details.

## Parameters

| Parameter          | Default         | Description                                                                                                                 |
| ------------------ | --------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `prompt`           | required        | Be specific — subject, style, lighting, composition. Max 4,000 chars.                                                       |
| `model`            | `nano-banana-2` | Choose from the [model catalog](/models-overview#image-models).                                                             |
| `size`             | `1920x1920`     | Exactly one of `1920x1920` (square), `2560x1440` (landscape), `1440x2560` (portrait).                                       |
| `n`                | `1`             | 1–4 images; each is billed.                                                                                                 |
| `image`            | —               | Public HTTPS reference URL for image-to-image.                                                                              |
| `reference_images` | —               | Ordered HTTPS reference URLs; up to 14, with a lower limit on some models. Use this or `image`, not both.                   |
| `storage`          | `durable`       | `durable` returns a permanent NinjaChat URL; `provider` skips the copy and may return a temporary URL or inline image data. |
| `aspect_ratio`     | —               | Aspect ratio for models that support it directly, e.g. `16:9`, `1:1` (Nano Banana, Imagen 4, FLUX.2 Flex).                  |
| `width`            | —               | Image width in pixels, 256–2048 (FLUX models only).                                                                         |
| `height`           | —               | Image height in pixels, 256–2048 (FLUX models only).                                                                        |

<Warning>
  `size` is a strict enum — `1024x1024` and other values are rejected with `validation_error`. Pick one of the three.
</Warning>

## Which model?

<div className="ndoc-model-grid">
  <a className="ndoc-model-link" href="/api-reference/models/image/flux-2-klein"><span className="ndoc-brand-mark">  <img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/09b9d42e/bfl.png" alt="" width="28" height="28" loading="lazy" /></span><span><strong>FLUX.2 Klein</strong><small>Black Forest Labs</small></span><span aria-hidden="true">↗</span></a>
  <a className="ndoc-model-link" href="/api-reference/models/image/nano-banana-2"><span className="ndoc-brand-mark">  <img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/263e7dab/gemini.svg" alt="" width="28" height="28" loading="lazy" /></span><span><strong>Nano Banana 2</strong><small>Google</small></span><span aria-hidden="true">↗</span></a>
  <a className="ndoc-model-link" href="/api-reference/models/image/gpt-image-2"><span className="ndoc-brand-mark">  <img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/6cf26e8b/openai.svg" alt="" width="28" height="28" loading="lazy" /></span><span><strong>GPT Image 2</strong><small>OpenAI</small></span><span aria-hidden="true">↗</span></a>
  <a className="ndoc-model-link" href="/api-reference/models/image/flux-kontext-max"><span className="ndoc-brand-mark">  <img src="https://cdn.photogenius.ai/new-ai-images/site/v1/landing/marks/marks/09b9d42e/bfl.png" alt="" width="28" height="28" loading="lazy" /></span><span><strong>FLUX.1 Kontext Max</strong><small>Black Forest Labs</small></span><span aria-hidden="true">↗</span></a>
</div>

[Explore all image models and pricing →](/models-overview#image-models)

## In code

<CodeGroup>
  ```typescript TypeScript SDK theme={null}
  import { NinjaChat } from "@ninjachat/sdk";

  const client = new NinjaChat({ apiKey: process.env.NINJACHAT_API_KEY! });
  const image = await client.images.generate({
    model: "flux-2-klein",
    prompt: "A mountain landscape at sunset",
    size: "1920x1920",
  });

  console.log(image.data[0].url);
  ```

  ```python Python SDK theme={null}
  import os
  from ninjachat import NinjaChat

  client = NinjaChat(api_key=os.environ["NINJACHAT_API_KEY"])
  image = client.images.generate(
      model="flux-2-klein",
      prompt="A mountain landscape at sunset",
      size="1920x1920",
  )

  print(image["data"][0]["url"])
  ```
</CodeGroup>

<Tip>
  Try prompts live in the [Playground](https://www.ninjachat.ai/developers/playground) — every run shows the exact request. Or let an agent drive: the [MCP server](/mcp/overview) offers a curated selection of these models through your agent.
</Tip>
