> ## 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.

<RequestExample>
  ```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"
    }'
  ```
</RequestExample>

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

### Body

<ParamField body="model" type="string" required>
  Model tag.
</ParamField>

<ParamField body="prompt" type="string" required>
  Text prompt describing the image.
</ParamField>

<ParamField body="n" type="integer">
  Number of images to generate. Defaults to `1`.
</ParamField>

<ParamField body="size" type="string">
  Image size: `auto`, `256x256`, `512x512`, `1024x1024`, `1536x1024`, `1024x1536`, `1792x1024`, or `1024x1792`.
  Defaults to `auto`, which uses the model's native size.
</ParamField>

<ParamField body="output_format" type="string">
  Image format: `png`, `jpeg`, or `webp`. Defaults to `png`.
</ParamField>

<ParamField body="output_compression" type="integer">
  Compression level from `0` to `100`, for the `jpeg` and `webp` formats.
</ParamField>

<ParamField body="background" type="string">
  Background transparency, for models that support it.
</ParamField>

### Response

<ResponseField name="created" type="integer" required>
  Unix timestamp, in seconds, when the images were created.
</ResponseField>

<ResponseField name="data" type="Image[]" required>
  Generated images.

  <Expandable title="properties">
    <ResponseField name="b64_json" type="string" required>
      Base64-encoded image data.
    </ResponseField>
  </Expandable>
</ResponseField>


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