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

# Generate an Image

Generates images from a text prompt.

```py Python theme={null}
from openai import OpenAI
import base64
import os

# 💥 Create an OpenAI client, pointed at Muna
openai = OpenAI(
  api_key=os.environ["MUNA_API_KEY"],
  base_url="https://inference.muna.ai/v1"
)

# 🔥 Generate an image
response = openai.images.generate(
  model="@black-forest-labs/flux.2-klein-4b",
  prompt="A red fox in fresh snow, golden hour",
  size="1024x1024"
)

# 🚀 Save the image
with open("fox.png", "wb") as f:
  f.write(base64.b64decode(response.data[0].b64_json))
```

```ts JavaScript theme={null}
import OpenAI from "openai"
import { writeFile } from "node:fs/promises"

// 💥 Create an OpenAI client, pointed at Muna
const openai = new OpenAI({
  apiKey: process.env.MUNA_API_KEY,
  baseURL: "https://inference.muna.ai/v1"
});

// 🔥 Generate an image
const response = await openai.images.generate({
  model: "@black-forest-labs/flux.2-klein-4b",
  prompt: "A red fox in fresh snow, golden hour",
  size: "1024x1024"
});

// 🚀 Save the image
await writeFile("fox.png", Buffer.from(response.data[0].b64_json, "base64"));
```

```bash curl theme={null}
curl https://inference.muna.ai/v1/images/generations \
  -H "Authorization: Bearer $MUNA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "@black-forest-labs/flux.2-klein-4b",
    "prompt": "A red fox in fresh snow, golden hour",
    "size": "1024x1024"
  }'
```

```json Response theme={null}
{
  "created": 1791516000,
  "data": [
    { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." }
  ]
}
```

### Body

**model** `string` *required*

Model tag.

**prompt** `string` *required*

Text prompt describing the image.

**n** `integer`

Number of images to generate. Defaults to `1`.

**size** `string`

Image size: `auto`, `256x256`, `512x512`, `1024x1024`, `1536x1024`, `1024x1536`, `1792x1024`, or `1024x1792`.
Defaults to `auto`, which uses the model's native size.

**output\_format** `string`

Image format: `png`, `jpeg`, or `webp`. Defaults to `png`.

**output\_compression** `integer`

Compression level from `0` to `100`, for the `jpeg` and `webp` formats.

**background** `string`

Background transparency, for models that support it.

### Response

**created** `integer` *required*

Unix timestamp, in seconds, when the images were created.

**data** `Image[]` *required*

Generated images.

**properties**

**b64\_json** `string` *required*

Base64-encoded image data.


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