Configure webhooks to receive real-time notifications when ModelsLab API requests complete. Set up callback URLs for async image, video, and audio generation.
Webhooks allow you to receive real-time notifications when your API requests complete processing. Instead of polling the fetch endpoint repeatedly, ModelsLab will send the results directly to your server.
Best for: Long-running operations like video generation, model training, and batch image processing where you don’t want to keep polling for results.
Add the webhook parameter to any API request that supports async processing:
import requestsresponse = requests.post( "https://modelslab.com/api/v6/video/text2video", json={ "key": "your_api_key", "model_id": "cogvideox", "prompt": "A spaceship flying through an asteroid field", "width": 512, "height": 512, "num_frames": 25, "webhook": "https://your-server.com/webhook/modelslab", "track_id": "video_001" # Optional: your own identifier })# You'll get an immediate response with the request IDdata = response.json()print(f"Request ID: {data['id']}")# Results will be sent to your webhook URL when ready
const response = await fetch("https://modelslab.com/api/v6/video/text2video", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: "your_api_key", model_id: "cogvideox", prompt: "A spaceship flying through an asteroid field", width: 512, height: 512, num_frames: 25, webhook: "https://your-server.com/webhook/modelslab", track_id: "video_001" })});const data = await response.json();console.log(`Request ID: ${data.id}`);// Results will be sent to your webhook URL when ready
curl -X POST "https://modelslab.com/api/v6/video/text2video" \ -H "Content-Type: application/json" \ -d '{ "key": "your_api_key", "model_id": "cogvideox", "prompt": "A spaceship flying through an asteroid field", "width": 512, "height": 512, "num_frames": 25, "webhook": "https://your-server.com/webhook/modelslab", "track_id": "video_001" }'
Use track_id to correlate webhook responses with your internal records:
# When making the requestresponse = requests.post(url, json={ "key": "your_api_key", "prompt": "A sunset", "webhook": "https://your-server.com/webhook", "track_id": "order_12345" # Your internal order ID})# In your webhook handlerdef handle_webhook(data): track_id = data.get('track_id') # "order_12345" # Update your order with the generated content update_order(track_id, data['output'])
# Install ngrokbrew install ngrok # macOS# Start your local serverpython app.py # Running on port 5000# In another terminal, start ngrokngrok http 5000# Use the ngrok URL as your webhook# https://abc123.ngrok.io/webhook/modelslab