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.
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.
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.
{{ $json.body.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.
{
"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.
Result: you now have a private AI question endpoint that lives entirely inside n8n and answers callers in real time.
Watch related tutorials
32:08
21:45
34:10
26:40
32:15
40:20