Skip to main content

Overview

AI Image Generator creates high-quality images from text descriptions using advanced AI models. The API generates original artwork, photos, illustrations, and designs based on detailed text prompts with customizable styles, orientations, and resolutions.

How It Works

  1. Write a prompt - Describe the image you want to create
  2. Choose a style - Select from 30+ art styles and tools
  3. Set orientation - Choose square, landscape, or portrait
  4. API generates images - AI creates images matching your description
  5. Download results - Retrieve your generated images

Use Cases

  • Content creation - Generate images for blogs, social media, marketing
  • Concept art - Visualize ideas before production
  • Stock photo replacement - Create custom images on-demand
  • Product mockups - Generate product visualizations
  • Creative projects - Artwork, illustrations, and designs

Best Practices

Writing Effective Prompts

Be specific and descriptive - The more detail you provide, the better the results.
✅ Good prompts:
  • “A serene mountain landscape at sunset with vibrant orange and purple colors, dramatic clouds, photorealistic style”
  • “Minimalist logo design of a flying bird in blue gradient, vector art style, clean lines”
  • “Cozy coffee shop interior with warm lighting, wooden furniture, plants, cinematic photography”
❌ Avoid:
  • Too vague: “A nice picture”
  • Too short: “Mountain”
  • Conflicting instructions: “Bright dark image”

Style Selection

Magic Hour offers 30+ art styles. Match the style to your use case:
Use CaseRecommended Styles
Marketing photosPhotorealistic, Cinematic
IllustrationsAnime, Cartoon, Watercolor
Logos & iconsVector, Minimalist
Concept artDigital Art, Fantasy

Orientation Guidelines

OrientationAspect RatioBest For
square1:1Profile pictures, thumbnails, social posts
landscape16:9Banners, headers, desktop wallpapers
portrait9:16Stories, mobile wallpapers, posters

Code Examples

Basic Image Generation

from magic_hour import Client
import os

client = Client(token=os.getenv("MAGIC_HOUR_API_KEY"))

result = client.v1.ai_image_generator.generate(
    image_count=1,
    orientation="landscape",
    style={
        "prompt": "A serene mountain landscape at sunset with vibrant colors",
        "tool": "ai-photo-generator"
    },
    name="Mountain Sunset",
    wait_for_completion=True,
    download_outputs=True,
    download_directory="./outputs/"
)

if result.status == "complete":
    print(f"✅ Image complete!")
    print(f"Downloaded to: {result.downloaded_paths}")
    print(f"Credits charged: {result.credits_charged}")
else:
    print(f"❌ Job failed with status: {result.status}")
    if hasattr(result, 'error_message'):
        print(f"Error: {result.error_message}")

Generate Multiple Images

result = client.v1.ai_image_generator.generate(
    image_count=4,  # Generate 4 variations
    orientation="square",
    style={
        "prompt": "Cute cat wearing sunglasses, digital art style",
        "tool": "ai-anime-generator"
    },
    name="Cat Variations",
    wait_for_completion=True,
    download_outputs=True,
    download_directory="./outputs/"
)

if result.status == "complete":
    print(f"✅ Image complete!")
    print(f"Downloaded to: {result.downloaded_paths}")
    print(f"Credits charged: {result.credits_charged}")
else:
    print(f"❌ Job failed with status: {result.status}")
    if hasattr(result, 'error_message'):
        print(f"Error: {result.error_message}")

Portrait Orientation

result = client.v1.ai_image_generator.generate(
    image_count=1,
    orientation="portrait",
    style={
        "prompt": "Professional business woman in modern office",
        "tool": "ai-photo-generator"
    },
    name="Business Portrait",
    wait_for_completion=True,
    download_outputs=True,
    download_directory="./outputs/"
)

if result.status == "complete":
    print(f"✅ Images complete!")
    print(f"Downloaded to: {result.downloaded_paths}")
    print(f"Credits charged: {result.credits_charged}")
else:
    print(f"❌ Job failed with status: {result.status}")
    if hasattr(result, 'error_message'):
        print(f"Error: {result.error_message}")

Pricing

QualityCredits per Image
Standard5 credits
Pro quality30 credits
Try this in our Google Colab Cookbook: Run this API with sample code. Just add your API key.

API Reference

AI Image Generator API Reference

View full API specification