Skip to main content
Magic Hour is an AI video and image generation platform. You submit a job, we render it, and you download the result. This guide gets you to your first output in a few minutes. What you’ll accomplish:
  1. Create an API key - Get credentials to authenticate with our API
  2. Set up your development environment - Install SDK and create project files
  3. Generate your first image - Make an API call and download the result (costs ~100 credits)
Credit Cost: The examples in this guide will use approximately 100 credits. New accounts get 400 free credits plus 100 daily credits if you claim them in the web app.

1. Create your API key

Why: API keys authenticate your requests and track your usage.
  1. Visit the Magic Hour Developer Hub and sign in. Create API Key
  2. Name the key (e.g., “My First Project”), then click Create key. Create API Key Modal
  3. Copy the API key immediately - you won’t be able to see it again. Copy API Key

Save your API key securely

Important: Store your API key as an environment variable for security:
# Add to your ~/.bashrc or ~/.zshrc file
export MAGIC_HOUR_API_KEY="your_api_key_here"

# Reload your shell
source ~/.bashrc  # or source ~/.zshrc
Never commit API keys to version control. Always use environment variables or secure credential management.

2. Set up your development environment

Why: SDKs handle authentication, polling, and file downloads automatically, reducing boilerplate code.

Create your project directory

# Create and navigate to project directory
mkdir magic-hour-quickstart
cd magic-hour-quickstart

# Create outputs directory (prevents FileNotFoundError)
mkdir outputs

# Create your Python file
touch main.py

Install the SDK

pip install magic_hour

3. Generate your first image

What we’re doing: Creating an AI-generated image using a text prompt. The API will:
  1. Queue your job and return a project ID
  2. Process your request (usually takes 30-60 seconds)
  3. Make the result available for download
Why these parameters:
  • image_count: 1 - Generate one image (costs 5 credits)
  • orientation: "landscape" - 16:9 aspect ratio
  • wait_for_completion: true - SDK polls until done
  • download_outputs: true - Automatically download to local disk
  • download_directory: "outputs" - Save to the outputs folder we created

Copy the code and run it

  1. Copy the code from your preferred language tab below
  2. Paste it into your file (main.py, main.js, main.go, etc.)
  3. Run the code:
# Make sure you're in your project directory
cd magic-hour-quickstart

# Run the script
python main.py
Expected output:
queued image with id clx1234567890, spent 5 credits
render complete!
created image with id clx1234567890, spent 5 credits. Outputs are saved at ['outputs/output-1.png']
SDK Versions: The .generate() helper function requires Python SDK v0.36.0+ or Node SDK v0.37.0+. Other SDKs use the manual create/poll/download pattern shown in the examples.
from magic_hour import Client
import time
import os
import urllib.request

# Use environment variable for security
client = Client(token=os.getenv("MAGIC_HOUR_API_KEY"))

result = client.v1.ai_image_generator.generate(
    image_count=1,
    orientation="landscape",
    style={
        "prompt": "Epic anime art of wizard casting a cosmic spell in the sky that says 'Magic Hour'"
    },
    wait_for_completion=True, # wait for the render to complete
    download_outputs=True, # download the outputs to local disk
    download_directory="outputs", # save the outputs to the "outputs" directory
)

print(f"created image with id {result.id}, spent {result.credits_charged} credits. Outputs are saved at {result.downloaded_paths}")

Troubleshooting

Common Issues

FileNotFoundError: No such file or directory: ‘outputs/output-1.png’ Solution: Create the outputs directory before running:
mkdir outputs
Error: MAGIC_HOUR_API_KEY environment variable not set Solution: Make sure you’ve set your API key as an environment variable:
export MAGIC_HOUR_API_KEY="your_api_key_here"

HTTP Error Codes

If you encounter HTTP errors, here’s what they mean:
Error CodeMeaningSolution
400Bad RequestCheck your request parameters and format
401UnauthorizedVerify your API key is correct and active
402Payment RequiredInsufficient credits - add more credits
500Internal Server ErrorTemporary server issue - retry after a few seconds
502Bad GatewayServer temporarily unavailable - retry after 30-60 seconds
503Service UnavailableServer overloaded - retry with exponential backoff
For persistent errors: Contact [email protected] with your project ID.
🎉 Congratulations! You have successfully created an image and a video on Magic Hour!

Next Steps

  • Explore the API Reference: Learn how to generate and edit videos and images programmatically. API Reference →
  • Try All APIs in Google Colab: Run our complete cookbook with sample code for all 22 APIs. Just add your API key and start experimenting.
  • Use the Web App: Try more tools and experiment interactively at magichour.ai.
  • Handle Results at Scale: Set up webhooks to process results async and avoid polling.
  • Join the Community: Get help, share projects, and see what others are building in Discord.
  • Stay Updated: Check out the Changelog for new products and API updates.
Prefer fast iteration inside your editor? Install this documentation as an MCP server to get contextual help while integrating the Magic Hour API. Learn more.