Overview
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.
How Webhooks Work
1
Include Webhook URL
Add the
webhook parameter to your API request with your endpoint URL.2
Request Processing
ModelsLab processes your request asynchronously.
3
Webhook Delivery
When complete, ModelsLab sends a POST request to your webhook URL with the results.
Using Webhooks
Add thewebhook parameter to any API request that supports async processing:
Webhook Payload
When your request completes, ModelsLab sends a POST request to your webhook URL with this payload:Success Payload
Failure Payload
Workflow Webhook Payload
For Workflows API, the payload structure includes additional workflow information:Setting Up Your Webhook Endpoint
Create an endpoint on your server to receive webhook notifications:Webhook Requirements
HTTPS Required
Your webhook URL must use HTTPS for security.
Respond Quickly
Return a 2xx status code within 30 seconds to acknowledge receipt.
Handle Duplicates
Webhooks may be sent multiple times. Use
id or track_id for idempotency.Public Endpoint
Your webhook endpoint must be publicly accessible.
The track_id Parameter
Use track_id to correlate webhook responses with your internal records:
Retry Policy
If your webhook endpoint is unreachable or returns a non-2xx status:- Workflow webhooks: Retried up to 3 times with exponential backoff
- Generation webhooks: Best-effort delivery, use fetch endpoint as fallback
Testing Webhooks Locally
Use a tunneling service to test webhooks during development:Using ngrok
Using localtunnel
Best Practices
Always respond with 2xx
Always respond with 2xx
Return a 200 or 202 status code immediately to acknowledge receipt. Do heavy processing asynchronously.
Implement idempotency
Implement idempotency
Store the
id or track_id and check before processing to handle duplicate deliveries.Log webhook payloads
Log webhook payloads
Log all incoming webhook payloads for debugging and audit purposes.
Use a message queue
Use a message queue
For production systems, push webhook data to a queue (Redis, SQS, etc.) and process asynchronously.
Set up monitoring
Set up monitoring
Monitor your webhook endpoint for failures and response times.
Endpoints Supporting Webhooks
Thewebhook parameter is supported by these API endpoints:
| Category | Endpoints |
|---|---|
| Image Generation | text2img, img2img, inpaint, controlnet |
| Video | text2video, img2video, text2video_ultra, img2video_ultra |
| Audio | text_to_speech, voice_to_voice, music_gen, song_generator |
| 3D | text_to_3d, image_to_3d |
| Image Editing | All editing endpoints |
| Training | fine_tune, lora_fine_tune |
| Workflows | run (workflow execution) |
Troubleshooting
Webhook not received
Webhook not received
- Verify your URL is publicly accessible (test with curl from outside your network)
- Check your server logs for incoming requests
- Ensure your endpoint returns 2xx within 30 seconds
- Use the fetch endpoint to check if the request completed
Receiving duplicate webhooks
Receiving duplicate webhooks
This is expected behavior for reliability. Implement idempotency using the request
id or your track_id.Webhook timing out
Webhook timing out
If your processing takes too long:
- Return 200 immediately
- Process the webhook payload asynchronously
- Use a message queue for heavy processing

