Patterns10 min read
Webhooks for Long-Running Operations
Receive async results without polling.
When to use webhooks
Image generation, OCR on large documents, and PDF generation can take 5–30 seconds. Webhooks let your code keep moving while we work.
Create an inbox
Use the Webhook Relay API to create a temporary endpoint, then pass it as the callback_url to any long-running operation.
javascript
// 1. Create an inbox
const inbox = await fetch("https://webhook-relay-by-helix-api.p.rapidapi.com/create", {
method: "POST",
headers: { /* RapidAPI headers */ }
}).then(r => r.json());
// 2. Start the long operation with callback_url
await fetch("https://ai-image-generation-by-helix-api.p.rapidapi.com/generate", {
method: "POST",
body: JSON.stringify({
prompt: "sunset over mountains",
callback_url: inbox.data.webhook_url
})
});
// 3. Poll the inbox for the result
const result = await fetch(`https://webhook-relay-by-helix-api.p.rapidapi.com/inbox/${inbox.data.id}`);