Skip to main content
By the end of this guide, you’ll have:
  • Created a webhook endpoint in your application
  • Registered it with Magic Hour
  • Tested it with a real API call
  • Verified webhook delivery works

What Are Webhooks?

Webhooks let you receive real-time notifications when your API requests complete, eliminating the need for polling. Instead of repeatedly checking job status, Magic Hour automatically notifies your application when jobs finish. Benefits:
  • βœ… Real-time notifications (no polling delays)
  • βœ… Efficient resource usage (no constant polling)
  • βœ… Better user experience (instant updates)
  • βœ… Scalable for high-volume operations

Step 1: Create Your Webhook Endpoint

First, create a simple webhook handler that can receive and process events.
Using Jupyter/Colab? See the β€œColab/Jupyter” tab below for notebook-compatible code, or use webhook.site for instant testing without any code.

Step 2: Make Your Endpoint Publicly Accessible

Your webhook endpoint needs to be accessible from the internet. Choose one of these options:

Step 3: Register Your Webhook with Magic Hour

1

Visit Developer Hub

Go to Magic Hour Developer Hub, and click Create WebhookWebhook Table
2

Configure webhook

Enter your webhook details:
  • Endpoint URL: Your public HTTPS URL (e.g., https://abc123.ngrok.io/webhook)
  • Events: Select the events you want to receive:
    • video.started - When video processing begins
    • video.completed - When video is ready for download
    • video.errored - When video processing fails
    • image.completed - When image is ready for download
    • image.errored - When image processing fails
    • audio.completed - When audio is ready for download
    • audio.errored - When audio processing fails Create webhook modal
Click Create Webhook
3

Save webhook secret

Important: Copy and save the webhook secret - you’ll need this for security verification later.Webhook Secret
Store this secret securely! It’s used to verify that webhooks are actually from Magic Hour.

Step 4: Test Your Webhook End-to-End

Now let’s verify everything works by making a real API call and watching for the webhook.
1

Start monitoring your webhook

If using your own server: Watch the console logs
If using Colab/Jupyter: Watch the cell output for webhook eventsIf using webhook.site: Keep the browser tab open to see incoming requests in real-time
2

Make a test API call

Create a simple image to trigger webhook events:
3

Verify webhook delivery

Within seconds, you should see webhook events in your console or webhook.site:
Success! πŸŽ‰ Your webhook is working end-to-end.

Understanding Webhook Retries

If your endpoint doesn’t respond with a 2xx status code, Magic Hour will retry delivery:
  • Duration: Up to 24 hours
  • Pattern: Exponential backoff (1s, 2s, 4s, 8s, …)
  • After 24 hours: Event marked as failed, no more retries
Disabled Webhooks: If a webhook is disabled, pending events are skipped and marked as failed after 24 hours.

Best Practices for Reliable Webhooks

βœ… Do:
  • Return 2xx status codes within 10 seconds
  • Process events asynchronously (respond fast, process later)
  • Implement idempotent processing (handle duplicate events)
  • Log all webhook events for debugging
❌ Don’t:
  • Perform long-running operations before responding
  • Return non-2xx codes for successful receipt
  • Assume events are delivered exactly once
  • Block the response while processing

Production Webhook Handler

For production, implement robust error handling and background processing:

Testing Locally

Before registering with Magic Hour, test your handler locally:
You should see the event logged in your server console.

Webhook Handler Requirements

Your webhook endpoint must:

1. Accept POST Requests

2. Parse JSON Payload

3. Return 2xx Status Code

4. Respond Within 10 Seconds

Troubleshooting

Webhook not receiving events?
  • βœ… Check your endpoint URL is publicly accessible
  • βœ… Ensure your server returns HTTP 2xx status codes
  • βœ… Verify the webhook is enabled in Developer Hub
  • βœ… Check server logs for errors
  • βœ… Test with ngrok or webhook.site first
Colab/Jupyter specific issues:
  • βœ… Install required packages: !pip install fastapi uvicorn nest-asyncio pyngrok
  • βœ… Make sure the server thread started successfully
  • βœ… Check if ngrok tunnel is active and accessible
  • βœ… Try webhook.site as an alternative for quick testing
AsyncIO errors in notebooks?
  • βœ… Use the Colab/Jupyter code version with nest_asyncio.apply()
  • βœ… Don’t run uvicorn.run() directly in notebooks - use the threading approach

Next Steps

Now that your webhook is working:

Secure Your Webhook

Add signature verification to ensure webhooks are from Magic Hour

Event Types Reference

Learn about all available webhook events and their payloads

Webhook API Reference

Complete webhook API documentation

First Integration

Build a complete integration from scratch

Need help? Join our Discord community or email support@magichour.ai