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

# Image Generation APIs

> Generate images using FLUX, Stable Diffusion, and LoRA adapters

# Image Generation APIs

<Warning>
  **Sunset Notice:** All image generation models on this page are being discontinued. These models will be removed in a future update. Please plan your migration accordingly.
</Warning>

Generate stunning images from text prompts using state-of-the-art diffusion models. Choose from FLUX.1-dev for best quality, SDXL for versatility, or Stable Diffusion for classic reliability.

## Endpoint

```
POST https://api.hyperbolic.xyz/v1/image/generation
```

## Basic Example

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import requests
    import base64

    url = "https://api.hyperbolic.xyz/v1/image/generation"
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY"
    }
    data = {
        "model_name": "FLUX.1-dev",
        "prompt": "A futuristic city skyline at sunset, cyberpunk style, neon lights",
        "height": 1024,
        "width": 1024,
        "steps": 30,
        "cfg_scale": 5
    }

    response = requests.post(url, headers=headers, json=data)
    result = response.json()

    # Decode and save the image
    image_data = base64.b64decode(result["images"][0]["image"])
    with open("generated_image.png", "wb") as f:
        f.write(image_data)
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST "https://api.hyperbolic.xyz/v1/image/generation" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -d '{
        "model_name": "FLUX.1-dev",
        "prompt": "A futuristic city skyline at sunset, cyberpunk style, neon lights",
        "height": 1024,
        "width": 1024,
        "steps": 30,
        "cfg_scale": 5
      }' | jq -r ".images[0].image" | base64 -d > generated_image.png
    ```
  </Tab>
</Tabs>

## Request Parameters

### Required Parameters

| Parameter    | Type   | Description                                   |
| ------------ | ------ | --------------------------------------------- |
| `model_name` | string | Model ID (e.g., `FLUX.1-dev`, `SDXL1.0-base`) |
| `prompt`     | string | Text description of the image to generate     |

### Optional Parameters

| Parameter         | Type    | Default | Description                                                  |
| ----------------- | ------- | ------- | ------------------------------------------------------------ |
| `height`          | integer | 1024    | Image height in pixels                                       |
| `width`           | integer | 1024    | Image width in pixels                                        |
| `steps`           | integer | 30      | Number of inference steps (more = higher quality, slower)    |
| `cfg_scale`       | float   | 5       | Prompt relevance (higher = closer to prompt, typically 5-15) |
| `negative_prompt` | string  | -       | What to avoid in the generated image                         |
| `seed`            | integer | -       | Random seed for reproducible results                         |
| `sampler`         | string  | -       | Sampling algorithm to use                                    |
| `backend`         | string  | auto    | Computation backend: `auto`, `tvm`, or `torch`               |

### SDXL-Specific Parameters

| Parameter           | Type    | Description                              |
| ------------------- | ------- | ---------------------------------------- |
| `prompt_2`          | string  | Secondary prompt for SDXL models         |
| `negative_prompt_2` | string  | Secondary negative prompt for SDXL       |
| `enable_refiner`    | boolean | Enable SDXL refiner for enhanced details |

## Response Format

The API returns a JSON object containing base64-encoded image data:

```json theme={null}
{
  "images": [
    {
      "image": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ]
}
```

### Decoding the Response

```python theme={null}
import base64

def save_image(response_json, filename="output.png"):
    """Decode and save the generated image."""
    image_data = base64.b64decode(response_json["images"][0]["image"])
    with open(filename, "wb") as f:
        f.write(image_data)
```

## Available Models

| Model                          | Model ID       | Best For                                   |
| ------------------------------ | -------------- | ------------------------------------------ |
| FLUX.1-dev ⚠️ Sunset           | `FLUX.1-dev`   | Best quality, outstanding prompt following |
| SDXL 1.0 ⚠️ Sunset             | `SDXL1.0-base` | High-quality, versatile, supports LoRA     |
| SDXL Turbo ⚠️ Sunset           | `SDXL-turbo`   | Fast generation                            |
| Stable Diffusion 2 ⚠️ Sunset   | `SD2`          | Good balance of speed and quality          |
| Stable Diffusion 1.5 ⚠️ Sunset | `SD1.5`        | Classic, reliable, supports LoRA           |
| Segmind SD 1B ⚠️ Sunset        | `SSD`          | Domain-specific applications               |

### Model Recommendations

<Tip>
  **Choosing the right model:**

  * **Best quality:** FLUX.1-dev for outstanding prompt following and visual quality
  * **Fast generation:** SDXL Turbo for quick iterations
  * **Image-to-image:** SDXL 1.0 or SD1.5 (FLUX does not support image-to-image)
  * **LoRA support:** SDXL 1.0 or SD1.5 for style customization
</Tip>

## Supported Resolutions

All image models support the following resolutions:

| Resolution  | Aspect Ratio        |
| ----------- | ------------------- |
| 1024 x 1024 | 1:1 (Square)        |
| 1152 x 896  | \~4:3               |
| 1216 x 832  | \~3:2               |
| 1344 x 768  | \~16:9              |
| 1536 x 640  | \~2.4:1 (Ultrawide) |
| 1664 x 2432 | \~2:3 (Portrait)    |
| 2048 x 2048 | 1:1 (Large Square)  |
| 2432 x 1664 | \~3:2 (Landscape)   |
| 640 x 1536  | \~1:2.4 (Tall)      |
| 768 x 1344  | \~9:16 (Portrait)   |
| 832 x 1216  | \~2:3               |

## Pricing

**Base rate:** \$0.01 per image at 1024x1024 resolution with 25 steps.

**Pricing formula:**

```
Price = $0.01 × (width/1024) × (height/1024) × (steps/25)
```

### Pricing Examples

| Resolution  | Steps | Price    |
| ----------- | ----- | -------- |
| 1024 x 1024 | 25    | \$0.01   |
| 1024 x 1024 | 50    | \$0.02   |
| 2048 x 2048 | 25    | \$0.04   |
| 2048 x 2048 | 50    | \$0.08   |
| 512 x 512   | 25    | \$0.0025 |

## Image-to-Image Generation

Transform existing images using a reference image. Supported by Stable Diffusion models only.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import requests
    import base64
    from PIL import Image
    from io import BytesIO

    def encode_image(image_path):
        """Encode an image file to base64."""
        with Image.open(image_path) as img:
            buffered = BytesIO()
            img.save(buffered, format="PNG")
            return base64.b64encode(buffered.getvalue()).decode("utf-8")

    # Encode your reference image
    reference_image = encode_image("input_image.png")

    url = "https://api.hyperbolic.xyz/v1/image/generation"
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY"
    }
    data = {
        "model_name": "SDXL1.0-base",
        "prompt": "A watercolor painting of the same scene",
        "image": reference_image,
        "strength": 0.7,
        "height": 1024,
        "width": 1024,
        "steps": 30
    }

    response = requests.post(url, headers=headers, json=data)
    result = response.json()

    # Save the result
    image_data = base64.b64decode(result["images"][0]["image"])
    with open("transformed_image.png", "wb") as f:
        f.write(image_data)
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    # First encode your image: base64 -i input.png -o input_base64.txt

    curl -X POST "https://api.hyperbolic.xyz/v1/image/generation" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -d '{
        "model_name": "SDXL1.0-base",
        "prompt": "A watercolor painting of the same scene",
        "image": "YOUR_BASE64_ENCODED_IMAGE",
        "strength": 0.7,
        "height": 1024,
        "width": 1024,
        "steps": 30
      }' | jq -r ".images[0].image" | base64 -d > transformed_image.png
    ```
  </Tab>
</Tabs>

### Image-to-Image Parameters

| Parameter  | Type   | Description                                                              |
| ---------- | ------ | ------------------------------------------------------------------------ |
| `image`    | string | Base64-encoded reference image                                           |
| `strength` | float  | Transformation strength (0-1). Higher values = more change from original |

<Info>
  **Strength guide:**

  * `0.3-0.5`: Subtle changes, preserves most of the original
  * `0.5-0.7`: Moderate transformation
  * `0.7-1.0`: Major changes, original is mostly a guide

  Image-to-image is supported by Stable Diffusion models only. FLUX.1-dev does not support this feature.
</Info>

## LoRA Adapters

LoRA (Low-Rank Adaptation) adapters let you apply custom styles to your generated images. Available for SDXL and SD1.5 models.

### Available LoRAs

**SDXL LoRAs:**

| LoRA Name                     | Style               |
| ----------------------------- | ------------------- |
| `Add_Detail`                  | Enhanced details    |
| `More_Art`                    | Artistic style      |
| `Pixel_Art`                   | Pixel art style     |
| `Logo`                        | Logo design         |
| `Sci-fi`                      | Science fiction     |
| `Crayons`                     | Crayon drawing      |
| `Paint_Splash`                | Paint splash effect |
| `Outdoor_Product_Photography` | Product photography |

**SD1.5 LoRAs:**

| LoRA Name            | Style                 |
| -------------------- | --------------------- |
| `Add_Detail`         | Enhanced details      |
| `Superhero`          | Comic superhero style |
| `Lineart`            | Line art              |
| `Anime_Lineart`      | Anime-style line art  |
| `Cartoon_Background` | Cartoon backgrounds   |
| `Pencil_Sketch`      | Pencil sketch         |

### Using LoRAs

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import requests
    import base64

    url = "https://api.hyperbolic.xyz/v1/image/generation"
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY"
    }
    data = {
        "model_name": "SDXL1.0-base",
        "prompt": "a cute cat",
        "height": 1024,
        "width": 1024,
        "lora": {"Pixel_Art": 1.0}
    }

    response = requests.post(url, headers=headers, json=data)
    result = response.json()

    image_data = base64.b64decode(result["images"][0]["image"])
    with open("pixel_cat.png", "wb") as f:
        f.write(image_data)
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST "https://api.hyperbolic.xyz/v1/image/generation" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -d '{
        "model_name": "SDXL1.0-base",
        "prompt": "a cute cat",
        "height": 1024,
        "width": 1024,
        "lora": {"Pixel_Art": 1.0}
      }' | jq -r ".images[0].image" | base64 -d > pixel_cat.png
    ```
  </Tab>
</Tabs>

### Combining Multiple LoRAs

Mix multiple LoRAs by adjusting their weights (0.0-1.0):

```python theme={null}
data = {
    "model_name": "SDXL1.0-base",
    "prompt": "a cute cat logo",
    "height": 1024,
    "width": 1024,
    "lora": {
        "Pixel_Art": 0.5,
        "Logo": 0.5,
        "Paint_Splash": 0.9
    }
}
```

<Tip>
  Experiment with different weight combinations to achieve unique styles. Lower weights apply subtle influence, while higher weights create stronger effects.
</Tip>

## Backend Options

| Backend | Description                                          |
| ------- | ---------------------------------------------------- |
| `auto`  | Automatically selects the best backend (recommended) |
| `tvm`   | Optimized for speed using TVM                        |
| `torch` | PyTorch backend, more flexible                       |

## Tips for Better Results

### Prompt Writing

* **Be specific:** "A golden retriever puppy playing in autumn leaves, soft sunlight" works better than "a dog"
* **Include style:** Add artistic style keywords like "photorealistic", "oil painting", "anime style"
* **Describe lighting:** Mention lighting conditions like "soft natural light", "dramatic shadows", "neon glow"

### Using Negative Prompts

Exclude unwanted elements:

```python theme={null}
data = {
    "model_name": "FLUX.1-dev",
    "prompt": "professional portrait photo of a woman",
    "negative_prompt": "blurry, low quality, distorted, deformed",
    "height": 1024,
    "width": 1024
}
```

### Reproducible Results

Use the `seed` parameter to generate the same image:

```python theme={null}
data = {
    "model_name": "FLUX.1-dev",
    "prompt": "a magical forest",
    "seed": 42,
    "height": 1024,
    "width": 1024
}
```

### CFG Scale Guide

* **1-5:** More creative, may deviate from prompt
* **5-10:** Balanced (recommended)
* **10-15:** Closely follows prompt
* **15+:** Very strict, may reduce quality

## Next Steps

<CardGroup cols={3}>
  <Card title="Text APIs" icon="message" href="/docs/inference/text-apis">
    Generate text with large language models
  </Card>

  <Card title="Vision Language Models" icon="eye" href="/docs/inference/vlm-apis">
    Analyze images with multimodal AI
  </Card>

  <Card title="Audio APIs" icon="volume-high" href="/docs/inference/audio-apis">
    Text-to-speech generation
  </Card>
</CardGroup>
