1

Create Your Account

  1. Sign up for a new account.
  2. Visit the Magic Hour Developer Hub
  3. Click Create API Key.
  4. Add a descriptive name. Then click Create key.
  5. Copy the API key and save it.
The API key can only be viewed on creation.
2

Install SDK (Optional)

Skip to the next step if you’re not planning on using our SDKs.
pip install magic_hour
3

Generate an image or a video

from magic_hour import Client
import time
import os
import urllib.request

client = Client(token="YOUR_API_KEY") # change to your API key

create_res = client.v1.ai_image_generator.create(
    image_count=1,
    orientation="landscape",
    style={
        "prompt": "Epic anime art of wizard casting a cosmic spell in the sky that says 'Magic Hour'"
    },
)

print(f"queued image with id {create_res.id}, spent ${create_res.frame_cost} frames")

output_file = "output.png"
while True:
    res = client.v1.image_projects.get(id=create_res.id)
    if res.status == "complete":
        print("render complete!")
        with (
            urllib.request.urlopen(res.downloads[0].url) as response,
            open(output_file, "wb") as out_file,
        ):
            out_file.write(response.read())
        print(f"file downloaded successfully to {output_file}")
        break
    elif res.status == "error":
        print("render failed")
        break
    else:
        print(f"render in progress: {res.status}")
        time.sleep(1)

🎉 Congratulations! You have successfully created an image and a video on Magic Hour!

Learn about available tools