IntegrationsIntermediate

How to Trigger an n8n AI Agent from a Webhook Node

Expose an n8n webhook, feed the request into the built-in AI Agent node, and return the model reply as the HTTP response.

10 minIntermediate

n8n ships an AI Agent node and a Respond to Webhook node, which together let you build a tiny self-hosted AI endpoint. A caller POSTs a question, the agent thinks, and your workflow answers in the same request. No extra hosting beyond your n8n instance is needed.

What you need

  • An n8n instance (cloud or self-hosted, version 1.x)
  • Credentials for a chat model, for example OpenAI or Anthropic
  • A REST client such as curl, Postman, or Insomnia

Step 1: Add a Webhook node in Respond mode

Create a new workflow and add a Webhook node. Set the HTTP Method to POST and the Path to ask. Under Respond, choose Using Respond to Webhook Node so you can return the model output later.

n8n - Webhook node
Node: Webhook
HTTP Method: POST
Path: ask
Respond: Using Respond to Webhook Node
Test URL: /webhook-test/ask
Prod URL: /webhook/ask
Set Respond to Using Respond to Webhook Node.

Step 2: Add the AI Agent node

Add an AI Agent node and connect a Chat Model sub-node to it (pick your provider and credential). In the agent's Text field, reference the incoming question with an expression so each request drives the prompt.

AI Agent - Text (expression)
{{ $json.body.question }}
Where the body lives
The Webhook node nests the parsed JSON under body. So a posted field named question is read as $json.body.question, not $json.question.

Step 3: Return the answer

Add a Respond to Webhook node at the end. Set Respond With to JSON and build a small body that pulls the agent output.

Respond to Webhook - Response Body
{
  "answer": "{{ $json.output }}"
}

Step 4: Activate and test

Click Active in the top right to switch from the test URL to the production /webhook/ask path, then call it.

bash - call the n8n endpoint
$curl -X POST https://your-n8n.example.com/webhook/ask \
$ -H "Content-Type: application/json" \
$ -d '{"question":"What is a webhook in one sentence?"}'
{"answer":"A webhook is an automatic HTTP callback that one app sends to another when an event happens."}
$

Result: you now have a private AI question endpoint that lives entirely inside n8n and answers callers in real time.

Watch related tutorials

Tags
#n8n#webhooks#ai-agent#self-hosted