> ## Documentation Index
> Fetch the complete documentation index at: https://oxenai-eric-revamp-getting-started.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generation

> Generate images from text prompts in minutes

## Overview

Generate images from text descriptions using models like FLUX and DALL-E.

## Minimal Example (Synchronous)

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

  response = requests.post(
      "https://hub.oxen.ai/api/ai/images/generate",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
      },
      json={
          "model": "black-forest-labs-flux-2-klein-4b",
          "prompt": "A red cube on a white background, minimal",
      },
  )

  data = response.json()
  print("Image URL:", data["images"][0]["url"])
  ```

  ```bash cURL theme={null}
  curl -X POST https://hub.oxen.ai/api/ai/images/generate \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "black-forest-labs-flux-2-klein-4b",
      "prompt": "A red cube on a white background, minimal"
    }'
  ```
</CodeGroup>

## With Base64 Response

Set `response_format` to `"b64_json"` to get the image bytes directly instead of a URL:

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

  response = requests.post(
      "https://hub.oxen.ai/api/ai/images/generate",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
      },
      json={
          "model": "black-forest-labs-flux-2-klein-4b",
          "prompt": "A blue sphere on grey background",
          "response_format": "b64_json",
      },
  )

  data = response.json()
  image_bytes = base64.b64decode(data["images"][0]["b64_json"])

  with open("output.png", "wb") as f:
      f.write(image_bytes)

  print("Saved to output.png")
  ```

  ```bash cURL theme={null}
  curl -X POST https://hub.oxen.ai/api/ai/images/generate \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "black-forest-labs-flux-2-klein-4b",
      "prompt": "A blue sphere on grey background",
      "response_format": "b64_json"
    }'
  ```
</CodeGroup>

## Async Generation (Recommended)

For longer-running image generation jobs, using the async queue avoids long-lived HTTP connections:

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

  API_KEY = "YOUR_API_KEY"
  MODEL = "black-forest-labs-flux-2-klein-4b"
  HEADERS = {
      "Authorization": f"Bearer {API_KEY}",
      "Content-Type": "application/json",
  }

  # 1. Enqueue
  response = requests.post(
      "https://hub.oxen.ai/api/ai/queue",
      headers=HEADERS,
      json={
          "model": MODEL,
          "prompt": "A watercolor painting of a mountain landscape",
      },
  )
  generations = response.json()["generations"]
  print(f"Enqueued {len(generations)} generation(s)")

  # 2. Poll until done
  while True:
      status = requests.get(
          "https://hub.oxen.ai/api/ai/queue",
          headers=HEADERS,
          params={"model": MODEL},
      ).json()
      if status["count"] == 0:
          break
      print(f"Still processing: {status['count']} remaining")
      time.sleep(10)

  print("Done!")
  ```

  ```bash cURL theme={null}
  # 1. Enqueue
  curl -X POST https://hub.oxen.ai/api/ai/queue \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "black-forest-labs-flux-2-klein-4b",
      "prompt": "A watercolor painting of a mountain landscape"
    }'

  # 2. Poll until done
  curl -H "Authorization: Bearer YOUR_API_KEY" \
    "https://hub.oxen.ai/api/ai/queue?model=black-forest-labs-flux-2-klein-4b"
  ```
</CodeGroup>

## What's Next

* [Image Generation Reference](/inference-api/reference/image_generation) for the full parameter list
* [Image Editing Reference](/inference-api/reference/image_editing) to edit existing images
* [Async Queue](/inference-api/reference/async_queue) to generate multiple images in parallel
