Webhook-Based Completion Notifications
What you'll learn: How to design callback endpoints that let the LLM service notify your system automatically when a generation job finishes.
The Core Idea
When you submit a long-running LLM request asynchronously (using task queues as you learned), you don't want your application constantly polling "Is it done yet?" Instead, you give the LLM service a webhook URL—essentially saying "call me back at this address when you're finished."
Think of it like ordering takeout: instead of calling the restaurant every five minutes, you give them your phone number and they call you when your food is ready.
How It Works
- Your app submits a generation request to the LLM service along with a callback URL (e.g.,
https://yourapp.com/api/llm-complete) - The service processes asynchronously while your app handles other work
- When complete, the service makes an HTTP POST to your webhook with the results
- Your endpoint receives and processes the completion data
Your webhook endpoint must:
- Be publicly accessible (or use tunneling for development)
- Validate the request authenticity (signatures, tokens)
- Handle the payload and update your database
- Return a success response quickly (200 OK)
- Process heavy work asynchronously if needed
Why Use Webhooks?
Webhooks eliminate polling overhead, reduce latency between completion and processing, and scale better—your servers aren't wasting cycles checking status. The LLM service pushes results exactly when ready.
Key Takeaway: Webhook-based completion notifications let LLM services proactively notify your application when generation finishes, creating efficient event-driven architectures that don't waste resources on polling.