Overview
Instead of pollingGET /jobs/{id} repeatedly, you can provide a webhook URL to receive a POST request when your job completes. This is more efficient and reduces unnecessary API calls.
Using Webhooks
Add theX-Webhook-URL header to any generation request. When the job reaches a terminal state (completed, failed, or cancelled), the API will send a POST request to your URL with the full job data.
Webhook Payload
When the job completes, your webhook URL receives a POST request with the job data:Best Practices
Respond quickly - Return a 2xx status code promptly. Process the webhook data asynchronously if needed.
- Use HTTPS endpoints for security
- Implement idempotency in case of duplicate deliveries
- Log webhook receipts for debugging
Webhooks vs Polling
Use webhooks when you have a server that can receive HTTP requests. Use polling for client-side applications or when you can’t expose a public endpoint.
Next Steps
Job Lifecycle
Learn about job states and status polling
Code Examples
See complete examples with webhook handling