Skip to main content

Image Generation APIs

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

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)

Request Parameters

Required Parameters

ParameterTypeDescription
model_namestringModel ID (e.g., FLUX.1-dev, SDXL1.0-base)
promptstringText description of the image to generate

Optional Parameters

ParameterTypeDefaultDescription
heightinteger1024Image height in pixels
widthinteger1024Image width in pixels
stepsinteger30Number of inference steps (more = higher quality, slower)
cfg_scalefloat5Prompt relevance (higher = closer to prompt, typically 5-15)
negative_promptstring-What to avoid in the generated image
seedinteger-Random seed for reproducible results
samplerstring-Sampling algorithm to use
backendstringautoComputation backend: auto, tvm, or torch

SDXL-Specific Parameters

ParameterTypeDescription
prompt_2stringSecondary prompt for SDXL models
negative_prompt_2stringSecondary negative prompt for SDXL
enable_refinerbooleanEnable SDXL refiner for enhanced details

Response Format

The API returns a JSON object containing base64-encoded image data:
{
  "images": [
    {
      "image": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ]
}

Decoding the Response

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

ModelModel IDBest For
FLUX.1-devFLUX.1-devBest quality, outstanding prompt following
SDXL 1.0SDXL1.0-baseHigh-quality, versatile, supports LoRA
SDXL TurboSDXL-turboFast generation
Stable Diffusion 2SD2Good balance of speed and quality
Stable Diffusion 1.5SD1.5Classic, reliable, supports LoRA
Segmind SD 1BSSDDomain-specific applications

Model Recommendations

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

Supported Resolutions

All image models support the following resolutions:
ResolutionAspect Ratio
1024 x 10241: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 20481: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

ResolutionStepsPrice
1024 x 102425$0.01
1024 x 102450$0.02
2048 x 204825$0.04
2048 x 204850$0.08
512 x 51225$0.0025

Image-to-Image Generation

Transform existing images using a reference image. Supported by Stable Diffusion models only.
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)

Image-to-Image Parameters

ParameterTypeDescription
imagestringBase64-encoded reference image
strengthfloatTransformation strength (0-1). Higher values = more change from original
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.

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 NameStyle
Add_DetailEnhanced details
More_ArtArtistic style
Pixel_ArtPixel art style
LogoLogo design
Sci-fiScience fiction
CrayonsCrayon drawing
Paint_SplashPaint splash effect
Outdoor_Product_PhotographyProduct photography
SD1.5 LoRAs:
LoRA NameStyle
Add_DetailEnhanced details
SuperheroComic superhero style
LineartLine art
Anime_LineartAnime-style line art
Cartoon_BackgroundCartoon backgrounds
Pencil_SketchPencil sketch

Using LoRAs

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)

Combining Multiple LoRAs

Mix multiple LoRAs by adjusting their weights (0.0-1.0):
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
    }
}
Experiment with different weight combinations to achieve unique styles. Lower weights apply subtle influence, while higher weights create stronger effects.

Backend Options

BackendDescription
autoAutomatically selects the best backend (recommended)
tvmOptimized for speed using TVM
torchPyTorch 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:
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:
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