> ## 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 images from text with 13 models via one endpoint.

<Tip>
  **Which image model?** Start with `flux-2-klein` ($0.03, fastest). Use `flux-kontext-max` ($0.10) for best quality. Use `flux-kontext-pro` (\$0.05) for image editing. [Compare all →](/models)
</Tip>

## Request

```bash theme={null}
POST https://www.ninjachat.ai/api/v1/images
Authorization: Bearer nj_sk_YOUR_API_KEY
Content-Type: application/json
```

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

## Response

```json theme={null}
{
  "model": "flux-2-klein",
  "images": [
    {
      "url": "https://cdn.example.com/generated-abc123.webp",
      "revised_prompt": "A golden retriever puppy in autumn leaves..."
    }
  ],
  "usage": { "images_generated": 1 },
  "cost": {
    "this_request": "$0.03",
    "per_image": "$0.03",
    "images": 1
  },
  "metadata": { "latency_ms": 1847, "size": "1920x1920" }
}
```

Your image URL is in `images[0].url`. Download it or display it directly.

## Parameters

| Parameter | Type    | Required | Default         | Description                                                                 |
| --------- | ------- | -------- | --------------- | --------------------------------------------------------------------------- |
| `prompt`  | string  | **Yes**  | —               | What you want. Be specific — style, lighting, composition. Max 4,000 chars. |
| `model`   | string  | No       | `nano-banana-2` | Which model. See table below.                                               |
| `size`    | string  | No       | `1920x1920`     | `1920x1920` (square), `2560x1440` (landscape), `1440x2560` (portrait)       |
| `n`       | integer | No       | 1               | Number of images (1–4). Each billed separately.                             |
| `image`   | string  | No       | —               | Reference image URL for image-to-image. Must be public HTTPS.               |

## Models

| Model            | ID                 | Cost       | Speed   | Best for                           |
| ---------------- | ------------------ | ---------- | ------- | ---------------------------------- |
| FLUX Kontext Max | `flux-kontext-max` | \$0.10/img | \~5-15s | Premium editing, max fidelity      |
| FLUX.2 Flex      | `flux-2-flex`      | \$0.08/img | \~5-10s | Maximum quality generation         |
| FLUX.1 Pro Ultra | `flux-1-pro-ultra` | \$0.08/img | \~8-15s | Ultra-high resolution (4MP)        |
| Recraft V3       | `recraft-v3`       | \$0.08/img | \~5s    | Design, illustrations              |
| Google Imagen 4  | `google-imagen-4`  | \$0.08/img | \~15s   | Photorealism, text rendering       |
| Nano Banana Pro  | `nano-banana-pro`  | \$0.08/img | \~5s    | Professional assets, thinking mode |
| Seedream         | `seedream`         | \$0.08/img | \~8s    | Realistic, artistic styles         |
| FLUX.2 Pro       | `flux-2-pro`       | \$0.05/img | \~3-5s  | Balanced quality/speed             |
| FLUX Kontext Pro | `flux-kontext-pro` | \$0.05/img | \~5s    | Image editing, style transfer      |
| Nano Banana 2    | `nano-banana-2`    | \$0.05/img | \~3s    | Best value, text rendering         |
| FLUX.1 Fill      | `flux-1-fill`      | \$0.05/img | \~5s    | Inpainting, outpainting            |
| FLUX.2 Klein     | `flux-2-klein`     | \$0.03/img | \<2s    | Fastest, batch processing          |
| Nano Banana      | `nano-banana`      | \$0.03/img | \~2s    | Fast, budget-friendly              |

<Tip>
  Not ready to write code? [Try this in the API Playground →](https://www.ninjachat.ai/api-playground)
</Tip>

## Full working examples

<CodeGroup>
  ```python Python theme={null}
  import os, requests

  HEADERS = {"Authorization": f"Bearer {os.environ['NINJACHAT_API_KEY']}"}

  def generate_image(prompt, model="flux-2-klein", size="1920x1920"):
      r = requests.post("https://www.ninjachat.ai/api/v1/images",
          headers=HEADERS,
          json={"model": model, "prompt": prompt, "size": size}
      )
      r.raise_for_status()
      return r.json()["images"][0]["url"]

  # Quick draft ($0.03, <2s)
  url = generate_image("A mountain landscape at sunset")
  print(url)

  # High quality final ($0.08, ~5-10 seconds)
  url = generate_image("A mountain landscape at sunset, 8k, ultra detailed",
      model="flux-2-flex", size="2560x1440")
  print(url)
  ```

  ```javascript Node.js theme={null}
  async function generateImage(prompt, model = "flux-2-klein", size = "1920x1920") {
    const r = await fetch("https://www.ninjachat.ai/api/v1/images", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${process.env.NINJACHAT_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ model, prompt, size }),
    });
    if (!r.ok) throw new Error(`${r.status}: ${await r.text()}`);
    return (await r.json()).images[0].url;
  }

  const url = await generateImage("A mountain landscape at sunset");
  console.log(url);
  ```
</CodeGroup>

## Image-to-image

Transform an existing image by passing its URL:

```python theme={null}
r = requests.post("https://www.ninjachat.ai/api/v1/images",
    headers=HEADERS,
    json={
        "model": "flux-kontext-pro",
        "prompt": "Turn this into a watercolor painting with soft colors",
        "image": "https://example.com/my-photo.jpg"  # Must be public HTTPS
    }
)
print(r.json()["images"][0]["url"])
```

## Multiple images

Generate up to 4 variations in one request:

```python theme={null}
r = requests.post("https://www.ninjachat.ai/api/v1/images",
    headers=HEADERS,
    json={
        "model": "recraft-v3",
        "prompt": "Logo for a coffee shop called 'Bean There', minimal vector",
        "n": 4
    }
)
for i, img in enumerate(r.json()["images"]):
    print(f"Variation {i+1}: {img['url']}")
# Cost: 4 × $0.08 = $0.32
```

## Prompt tips

Be specific. Compare:

| Weak   | Strong                                                                                                               |
| ------ | -------------------------------------------------------------------------------------------------------------------- |
| `dog`  | `Golden retriever puppy sitting in autumn leaves, soft golden hour lighting, shallow depth of field, photorealistic` |
| `city` | `Cyberpunk cityscape at night, neon signs reflecting in rain puddles, aerial view, cinematic lighting, 8k`           |
| `logo` | `Minimal vector logo for a tech startup, geometric shapes, blue and white, clean lines, flat design`                 |

Include: **subject** + **style** + **lighting** + **composition** + **detail level**
