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.credits_charged} credits")
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)