Skip to main content
Create images from text prompts, edit existing images, and generate variations using DALL-E and GPT Image models.

Generate images

Create images from text descriptions:
import os
from dedalus_labs import Dedalus

client = Dedalus(
    api_key=os.environ.get("DEDALUS_API_KEY")
)

response = client.images.generate(
    prompt="A serene mountain landscape at sunset with a lake reflection",
    model="openai/dall-e-3",
    size="1024x1024",
    quality="hd",
    n=1
)

image_url = response.data[0].url
print(f"Generated image: {image_url}")

Async usage

Generate images asynchronously:
import os
import asyncio
from dedalus_labs import AsyncDedalus

client = AsyncDedalus(
    api_key=os.environ.get("DEDALUS_API_KEY")
)

async def main():
    response = await client.images.generate(
        prompt="A futuristic cityscape with flying cars",
        model="openai/dall-e-3"
    )
    print(response.data[0].url)

asyncio.run(main())

Available models

Highest quality image generation with advanced understanding:
response = client.images.generate(
    prompt="A photorealistic cat wearing a space suit",
    model="openai/dall-e-3",
    size="1024x1024",  # 1024x1024, 1792x1024, 1024x1792
    quality="hd",       # standard or hd
    style="vivid",      # vivid or natural
    n=1                 # Only n=1 supported
)

Response formats

Images are returned as URLs (valid for 60 minutes):
response = client.images.generate(
    prompt="A sunset over mountains",
    model="openai/dall-e-3",
    response_format="url"  # Default for DALL-E
)

# Download the image
import requests
from pathlib import Path

image_url = response.data[0].url
image_data = requests.get(image_url).content
Path("generated_image.png").write_bytes(image_data)
gpt-image-1 always returns base64-encoded images and doesn’t support the response_format parameter.

Image sizes

Different models support different sizes:
# Square
response = client.images.generate(
    prompt="A cat",
    model="openai/dall-e-3",
    size="1024x1024"
)

# Landscape
response = client.images.generate(
    prompt="A wide landscape",
    model="openai/dall-e-3",
    size="1792x1024"
)

# Portrait
response = client.images.generate(
    prompt="A tall building",
    model="openai/dall-e-3",
    size="1024x1792"
)

Style control (DALL-E 3)

Hyper-real and dramatic images:
response = client.images.generate(
    prompt="A dragon in a mystical forest",
    model="openai/dall-e-3",
    style="vivid"  # More dramatic and vivid
)

Quality levels

# Standard quality (faster, lower cost)
response = client.images.generate(
    prompt="A cat",
    model="openai/dall-e-3",
    quality="standard"
)

# HD quality (higher detail, more cost)
response = client.images.generate(
    prompt="A detailed portrait",
    model="openai/dall-e-3",
    quality="hd"
)

Edit images

Edit images using inpainting (DALL-E 2 and GPT Image):
from pathlib import Path
from dedalus_labs import Dedalus

client = Dedalus()

response = client.images.edit(
    image=Path("original.png"),
    prompt="Add a red hat to the person",
    mask=Path("mask.png"),  # Optional: transparent areas indicate what to change
    model="openai/dall-e-2",
    size="1024x1024",
    n=1
)

print(response.data[0].url)
Image editing requirements:
  • Images must be square PNG files
  • Less than 4MB in size
  • If mask is not provided, the image must have transparency (alpha channel)
  • Transparent areas indicate where to edit

Create variations

Generate variations of an existing image (DALL-E 2 only):
from pathlib import Path
from dedalus_labs import Dedalus

client = Dedalus()

response = client.images.create_variation(
    image=Path("original.png"),
    model="openai/dall-e-2",
    n=3,  # Generate 3 variations
    size="512x512"
)

for i, image_data in enumerate(response.data):
    print(f"Variation {i+1}: {image_data.url}")

Advanced features (GPT Image)

Transparent backgrounds

response = client.images.generate(
    prompt="A coffee cup logo",
    model="openai/gpt-image-1",
    background="transparent",  # transparent, opaque, or auto
    output_format="png"        # Must use png or webp for transparency
)

Output compression

response = client.images.generate(
    prompt="A landscape photo",
    model="openai/gpt-image-1",
    output_format="webp",
    output_compression=85  # 0-100, only for webp or jpeg
)

Streaming image generation

response = client.images.generate(
    prompt="A complex artwork",
    model="openai/gpt-image-1",
    stream=True,
    partial_images=3  # Number of progressive previews (0-3)
)

# Access progressive images as they're generated
for event in response:
    if event.type == "partial":
        print(f"Partial image {event.index} received")
    elif event.type == "final":
        print("Final image received")

Multiple images (DALL-E 2)

Generate multiple images in one request:
response = client.images.generate(
    prompt="A cute robot",
    model="openai/dall-e-2",
    n=4,  # Generate 4 images (max 10)
    size="512x512"
)

for i, image_data in enumerate(response.data):
    print(f"Image {i+1}: {image_data.url}")
DALL-E 3 only supports n=1. Use DALL-E 2 for multiple image generation.

Complete example

import requests
from pathlib import Path
from dedalus_labs import Dedalus

client = Dedalus()

# Generate a high-quality image
response = client.images.generate(
    prompt="A professional photograph of a modern minimalist office space with natural lighting, plants, and ergonomic furniture",
    model="openai/dall-e-3",
    size="1792x1024",  # Landscape
    quality="hd",
    style="natural",
    n=1
)

image_url = response.data[0].url
print(f"Generated image URL: {image_url}")
print(f"Revised prompt: {response.data[0].revised_prompt}")

# Download and save the image
image_data = requests.get(image_url).content
output_path = Path("office_space.png")
output_path.write_bytes(image_data)
print(f"Image saved to {output_path}")

Error handling

import dedalus_labs
from dedalus_labs import Dedalus

client = Dedalus()

try:
    response = client.images.generate(
        prompt="A sunset",
        model="openai/dall-e-3"
    )
except dedalus_labs.BadRequestError as e:
    print(f"Invalid request: {e.message}")
    # Common causes: policy violation, invalid parameters
except dedalus_labs.APIConnectionError as e:
    print("Network error occurred")
    print(e.__cause__)
except dedalus_labs.RateLimitError as e:
    print("Rate limit exceeded")
except dedalus_labs.APIStatusError as e:
    print(f"API error: {e.status_code}")
Generated images from DALL-E are owned by you and can be used commercially. Make sure your prompts comply with OpenAI’s usage policies.

Build docs developers (and LLMs) love