- Create an API key - Get credentials to authenticate with our API
- Set up your development environment - Install SDK and create project files
- 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.- Visit the Magic Hour Developer Hub and sign in.

- Name the key (e.g., “My First Project”), then click
Create key.
- Copy the API key immediately - you won’t be able to see it again.

Save your API key securely
Important: Store your API key as an environment variable for security:2. Set up your development environment
Why: SDKs handle authentication, polling, and file downloads automatically, reducing boilerplate code.Create your project directory
Install the SDK
3. Generate your first image
What we’re doing: Creating an AI-generated image using a text prompt. The API will:- Queue your job and return a project ID
- Process your request (usually takes 30-60 seconds)
- Make the result available for download
image_count: 1- Generate one image (costs 5 credits)orientation: "landscape"- 16:9 aspect ratiowait_for_completion: true- SDK polls until donedownload_outputs: true- Automatically download to local diskdownload_directory: "outputs"- Save to the outputs folder we created
Copy the code and run it
- Copy the code from your preferred language tab below
- Paste it into your file (
main.py,main.js,main.go, etc.) - Run the code:
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.- Generate image
- Swap Faces in a Video
Troubleshooting
Common Issues
FileNotFoundError: No such file or directory: ‘outputs/output-1.png’ Solution: Create the outputs directory before running:HTTP Error Codes
If you encounter HTTP errors, here’s what they mean:| Error Code | Meaning | Solution |
|---|---|---|
400 | Bad Request | Check your request parameters and format |
401 | Unauthorized | Verify your API key is correct and active |
402 | Payment Required | Insufficient credits - add more credits |
500 | Internal Server Error | Temporary server issue - retry after a few seconds |
502 | Bad Gateway | Server temporarily unavailable - retry after 30-60 seconds |
503 | Service Unavailable | Server overloaded - retry with exponential backoff |
🎉 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.