IntegrationsAdvanced

How to Answer a Webhook Instantly While AI Runs in the Background in n8n

Acknowledge the caller in milliseconds, then process a slow AI task asynchronously so the request never times out.

9 minAdvanced

Many senders give up if a webhook takes more than a few seconds to respond, but a long AI generation can run much longer. The pattern that solves this is respond first, work later: reply with a quick acknowledgement, then continue the heavy AI step on a separate branch and deliver the result somewhere else.

What you need

  • An n8n instance, version 1.x
  • A chat model credential for the slow generation step
  • A place to deliver the finished result (Slack, email, or a callback URL)

Step 1: Respond before the AI step

Set the Webhook node Respond option to Using Respond to Webhook Node. Wire a Respond to Webhook node as the very next step so n8n returns a 200 right away, before any model call.

n8n - workflow layout
Webhook -> Respond (200 'received')
|
+-> AI Agent (slow)
|
+-> Slack: post result
The Respond node sits early; the AI branch continues after it.
Respond to Webhook - body
{
  "status": "accepted",
  "message": "Your request is processing. We'll post the result to Slack."
}

Step 2: Continue to the AI node

From the Webhook node, also connect a second branch into your AI Agent or HTTP model node. Because the response already went out, this branch can take as long as it needs.

Both branches start from the webhook
Connect the Webhook node to two nodes: the Respond node and the AI node. n8n runs the response branch and the work branch from the same trigger output.

Step 3: Deliver the finished result

After the AI node, add a delivery step. A Slack message, an email, or an HTTP request back to the caller all work. Include any id from the original payload so the result can be matched up.

bash - caller sees an instant reply
$time curl -X POST https://your-n8n.example.com/webhook/generate \
$ -d '{"id":"job-42","prompt":"write a 500 word post"}'
{"status":"accepted","message":"...processing..."}
real 0m0.180s
$

Result: the caller gets a confirmation in well under a second, and the finished article shows up in your Slack channel a minute later with no timeout error.

Watch related tutorials

Tags
#n8n#webhooks#async#timeout