
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
A webhook is an HTTP request that one application sends to another automatically when something happens: a payment succeeds, a ticket is opened, a deal changes stage or a file lands in a folder. Instead of your system asking "is there anything new?" every few minutes, the source system pushes the event to a URL you control the moment it occurs.
For AI engineers, webhooks are the bridge between a business process and an AI agent. They are how an agent stops being a chat window someone has to open and becomes a system that reacts to real events inside an organization. If you are building AI applications for clients or for your own company, understanding how to receive, verify and process webhooks safely is a core integration skill.
How a webhook works
The mechanics are simple. You register an endpoint URL with the source application and choose which events you care about. When one of those events happens, the source sends an HTTP POST to your endpoint with a JSON payload describing it. Your server answers with a 2xx status code to confirm receipt. Services like Stripe and GitHub document this pattern in detail, and most SaaS tools follow a close variation of it.
Event: what happened, for example
invoice.paidorissue.opened.Payload: the data about the event, usually JSON with IDs, timestamps and the changed object.
Endpoint: the URL in your system that receives the request.
Signature: a header that lets you verify the request really came from the sender.
Webhooks vs polling vs APIs
An API is something you call when you need data. Polling means calling that API on a schedule to check for changes. A webhook flips the direction: the other system calls you. Polling is easy to build but wastes requests and adds delay; webhooks are near real time and efficient, but they require a public endpoint and careful handling of retries and security. In practice, production systems often combine both: webhooks for speed, plus a periodic reconciliation job that catches anything missed.
Why AI agents need webhooks
Most valuable agent use cases start with an event, not with a person typing a prompt. A webhook-triggered agent can:
Classify and draft a first response when a new support ticket arrives.
Summarize a call transcript and update the CRM when a meeting recording is ready.
Enrich and route a new lead the moment a form is submitted.
Check an invoice against a purchase order when a document is uploaded.
Open an incident summary when a monitoring tool fires an alert.
In each case, the webhook supplies the trigger and the context, and the agent decides what to do with it, often by calling tools. If tool use is new to you, our guide on function calling and why AI agents depend on tool use explains how the model selects actions.
A reference architecture for webhook-driven agents
1. Receive fast, process later
LLM calls can take seconds and senders expect a quick response. If your endpoint waits for the agent to finish, the sender may time out and retry. The standard pattern is to validate the request, store the event, push it to a queue and immediately return 200. A background worker then runs the agent.
2. Verify every request
Your endpoint is a public URL, so anyone could send it fake events. Verify the signature header using the shared secret the provider gives you, check timestamps to block replayed requests and reject anything that fails. The Standard Webhooks specification describes a common approach to signing and verification that many providers have adopted.
3. Make processing idempotent
Providers retry when they do not get a success response, and sometimes they deliver the same event twice even when they do. Store each event ID and skip duplicates, so a retried "new ticket" event does not produce two AI replies to the same customer.
4. Fetch fresh data before acting
Treat the payload as a notification, not the source of truth. Before the agent acts, re-read the object from the provider's API with proper credentials. This protects you from stale or out-of-order events and ensures the agent sees the current state.
5. Constrain what the agent can do
Webhook payloads often contain text written by outsiders: email bodies, form fields, ticket descriptions. That text can include prompt injection attempts. Keep the agent's tools narrow, require human approval for sensitive actions and validate tool arguments in code. The OWASP Top 10 for LLM Applications is a useful checklist here. When the agent acts on behalf of a user inside enterprise apps, delegated access matters too; see OAuth 2.0 for AI agents.
6. Log and observe everything
Record the event ID, the agent's decision, the tools it called and the outcome. When a client asks why the agent replied the way it did, you need a trace that connects the original event to the final action.
Example: a support ticket triage agent
The help desk sends a
ticket.createdwebhook to your endpoint.Your service verifies the signature, saves the event ID and enqueues the job.
A worker fetches the full ticket and the customer's account details via API.
The agent classifies urgency and topic, retrieves relevant help articles and drafts a reply.
High-confidence, low-risk tickets get a suggested reply for an agent to approve; urgent ones are routed to a human queue with a summary.
Every step is logged with the original event ID for auditing and evaluation.
Common mistakes
Running the LLM inside the request handler. It causes timeouts, retries and duplicate actions.
Skipping signature verification. An unverified endpoint lets anyone trigger your agent.
Trusting payload text as instructions. User-supplied content is data, never commands.
No dead-letter queue. Failed events disappear silently instead of being retried or reviewed.
Ignoring ordering. An "updated" event can arrive before "created"; design for it.
FAQ
Do I need a server to receive webhooks?
You need a publicly reachable HTTPS endpoint. That can be a small web service, a serverless function or a workflow tool such as n8n that exposes a webhook trigger.
What is the difference between a webhook and a WebSocket?
A webhook is a one-off HTTP request per event. A WebSocket is a persistent, two-way connection, better suited to continuous streams like live chat.
How do I test webhooks locally?
Most providers offer a test event button or CLI, and tunneling tools can expose your local server temporarily so you can inspect real payloads during development.
Keep learning with Coderhouse
Integrating AI systems with the tools a business already runs is a big part of the forward deployed role. The Forward Deployed AI Engineering Course is built for developers comfortable with Python: eight weeks with one 2-hour live class per week and about 6 to 8 hours of work weekly, covering RAG, evaluation, tool-using agents and enterprise integration, including legacy systems, webhooks, delegated identity with OAuth2 and data governance. Explore the paths that fit your goals:
Forward Deployed AI Engineering Course — build, integrate and hand off production AI systems, from event-driven agents to secure enterprise connections.
Data Analytics Course — learn SQL, Python and experimentation to measure the impact of the automations you ship.
GTM Engineer Course (waitlist) — join the waitlist for early access to the program focused on building modern go-to-market systems.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.