Skip to content
How-to Beginner 35 min read by Rajat Jain Updated August 13, 2026

How to Build an AI Workflow with n8n

Build a working AI workflow in n8n: Chat Trigger to AI Agent with an OpenAI model and a Wikipedia tool, copy-ready import JSON, verification, and real error fixes.

Note

Verified 13 August 2026 against docs.n8n.io (stable line 2.x, structured around the current AI Agent and Chat Trigger node names), n8n.io/pricing, and the official n8n Cloud docs. Node renames changed in 2025-2026: Manual Chat Trigger is now just Chat Trigger (v1.24.0+), and the AI Agent node's agent-type dropdown was removed in v1.82.0 (every agent now works as a Tools Agent).

Before you start

  • An n8n instance (we recommend the free n8n Cloud trial for this walkthrough); a self-hosted instance needs port 5678 reachable
  • An OpenAI API key - get one at platform.openai.com
  • Node 20+ if you self-host with the official image
  • Basic familiarity with node-and-connector builders (drag, connect, execute)
Jump to section
  1. 1

    Decide: n8n Cloud vs self-hosted

    Cloud is the fastest path (one account, 800 free AI credits trial). Self-hosting means running the official Docker image on a machine with port 5678 open - cheaper at scale, but you own updates and uptime.

  2. 2

    Create the workflow

    Start from blank or import the copy-ready JSON below - it wires a Chat Trigger to an AI Agent that has an OpenAI Chat Model and the Wikipedia tool attached.

  3. 3

    Add credentials

    Create the OpenAI credential in n8n and paste your API key. The Chat Model sub-node loads model names dynamically once the credential exists.

  4. 4

    Run the workflow in chat

    Open the Chat Trigger's chat window, send a prompt that needs live knowledge, and watch the execution log: agent → model → tool call → final answer.

  5. 5

    Verify it actually worked

    Refine the system prompt, add a second tool from the official tool list, and re-test. Know how export/import works so you can share and reuse the result.

By the end of this guide you’ll have a working AI workflow in n8n: a chat window connected to an AI Agent that answers questions - and reaches live Wikipedia when it needs facts it doesn’t know. You’ll wire it with the current official node names, verify each step in the execution log, dodge the real error messages, and learn the export/import habits that make these workflows shareable.

If you already know what AI agents are or how MCP connects AI tools, you’ll see n8n as the orchestration layer that binds them - its AI Agent node is the same pattern, pointed at real systems.

What an AI workflow is in n8n

In the builder you’ll see three kinds of nodes:

  • Root nodes - where execution starts (chat trigger, webhook, schedule).
  • Cluster root nodes - the AI Agent: it makes decisions and orchestrates the rest.
  • Sub-nodes - the model, the tools, the memory, the output parser. They attach to the agent as connected “clusters”, not as separate pipeline steps.

The workflow this guide builds: Chat Trigger → AI Agent (OpenAI Chat Model + Wikipedia tool). The agent, at runtime, decides when to search - exactly the pattern your own agent follows, but without writing code.

Name changes to know about

The node you’ll drag is Chat Trigger - the old Manual Chat Trigger was renamed in n8n v1.24.0. The old AI Agent “agent type” dropdown (ReAct vs Tools Agent) is gone since v1.82.0; every agent now works as a Tools Agent and only uses tools you explicitly connect. All steps below use the current names.

Step 1: Pick your instance: n8n Cloud or self-hosted

n8n CloudSelf-hosted (Community)
Setup~5 minutes, browser accountDocker on your own machine/VM
Price (2026)Free trial (800 AI credits), then from €20/mo billed annually (Starter, 2,500 executions/mo)Free software; you pay compute + your own model API usage
Updatesn8n maintains infrastructureYou own updates, backups and uptime
When to chooseNew to n8n; want workflows working tonightScale beyond 10K executions/mo, data-residency needs (EU storage is offered on Cloud), or fixed budgets

The official docs line on self-hosting is worth quoting: “Self-hosting n8n requires technical expertise” - the built-in Docker install docs are even tagged as outdated in favor of a Docker Compose setup. For this guide, n8n Cloud’s free trial is the recommended path (sign up at app.n8n.cloud/register).

Self-hosting on the official image (uses the container’s demos/hello-world page at http://localhost:5678):

docker run -it --rm \
  -p 5678:5678 \
  -e N8N_SECURE_COOKIE=false \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n

Step 2: Create the workflow (import it, don’t rebuild it)

Start from Workflows → Add workflow (blank), or skip the dragging entirely - import the copy-ready JSON below via the workflow’s … menu → Import from file (the official export/import path). It contains all four nodes with the exact current type identifiers:

NodeType identifier (import JSON)
Chat Triggern8n-nodes-langchain.chatTrigger
AI Agentn8n-nodes-langchain.agent
OpenAI Chat Modeln8n-nodes-langchain.lmChatOpenAI
Wikipedia tooln8n-nodes-langchain.toolWikipedia
{
  "name": "AI Workflow - Wikipedia Research Assistant",
  "nodes": [
    {
      "parameters": {
        "public": true,
        "options": {}
      },
      "id": "chat-trigger",
      "name": "Chat Trigger",
      "type": "n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [0, 0],
      "webhookId": "CHAT_WEBHOOK_ID"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "You are a research assistant. Answer questions from the user. If you need current or factual details, search Wikipedia with the tool before answering. Keep answers concise (max 3 paragraphs) and always cite the entry you used.",
        "options": {}
      },
      "id": "ai-agent",
      "name": "AI Agent",
      "type": "n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [220, 0]
    },
    {
      "parameters": {
        "options": {},
        "model": "gpt-4o-mini"
      },
      "id": "openai-model",
      "name": "OpenAI Chat Model",
      "type": "n8n-nodes-langchain.lmChatOpenAI",
      "typeVersion": 1,
      "position": [220, 220],
      "credentials": {
        "openAiApi": {
          "id": "YOUR_OPENAI_CREDENTIAL_ID",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "wikipedia-tool",
      "name": "Wikipedia",
      "type": "n8n-nodes-langchain.toolWikipedia",
      "typeVersion": 1,
      "position": [440, 220]
    }
  ],
  "connections": {
    "Chat Trigger": {
      "main": [[{ "node": "AI Agent", "type": "main", "index": 0 }]]
    },
    "AI Agent": {
      "ai_languageModel": [[{ "node": "OpenAI Chat Model", "type": "ai_languageModel", "index": 0 }]],
      "ai_tool": [[{ "node": "Wikipedia", "type": "ai_tool", "index": 0 }]]
    }
  },
  "settings": { "executionOrder": "v1" }
}

Two honest caveats about imported JSON

First, one required tool-input is empty by design: the JSON only needs the sub-node wiring, not a pre-set value. Second, exports embed credential IDs/names - official docs warn you to anonymize these before sharing, and imports with a mismatched credential name will still work as long as the credential exists in the target instance (the editor shows an inline error otherwise).

If you prefer to build by drag-and-drop instead of importing: add Chat Trigger (root, core-nodes), add AI Agent (cluster root), connect trigger → agent, then attach sub-nodes: OpenAI Chat Model (models → chat model) and Wikipedia (tools → Wikipedia). Wire the connectors and you’re done - each sub-node needs only its connector line, not a value.

Step 3: Set up the OpenAI credential

  1. In the OpenAI Chat Model node, open Credential and choose Create new credential (type OpenAI API).
  2. Paste your OpenAI API key - the only required field. Organization ID is optional per the official credentials docs, only needed if your account belongs to multiple organizations.
  3. Save, then check the Model dropdown - models load dynamically from the API once a valid credential exists; pick gpt-4o-mini or whatever your account has access to.
  4. Leave the default model options alone for now. There is no required parameter beyond the credential.

The system prompt in the agent node does the steering: it tells the model to search Wikipedia before answering. Keep it short - the tools you connect do the heavy lifting.

Step 4: Run it - and watch it think

  1. Execute the workflow (the Test workflow dialog opens the chat window embedded in the current editor).
  2. Send a question that demands live knowledge: “When was Portugal’s 25 April Bridge built - and how long is it?”
  3. Answer will be composed by the model - and the executions log (bottom panel) shows every step: the trigger, the agent, two OpenAI calls (tool round-trip), and the Wikipedia node.

How you know the tool actually fired

Ask something only Wikipedia could tell you: a fact that isn’t in the model’s training or your prompt. If the answer contains it, the tool round-trip happened. You can also drag a second sub-node (e.g. a Calculator tool) into the agent and ask an arithmetic question the model can’t be trusted on.

Two behaviors to expect, both official:

  • Every chat message = one workflow execution. n8n bills per execution on Cloud plans, and large prompts add model API cost. This is the biggest difference between a chat workflow and a plain webhook.
  • Chat sessions persist via memory. By default the agent keeps per-session context; adding a Simple Memory sub-node keeps history across messages (it’s what the “Load Previous Session” option in the trigger’s session settings uses).

Step 5: Verify it worked, then make it yours

Verification checklist (official, in order):

  1. Execution was successful - no red nodes in the executions log; the Chat Trigger shows 200 status.
  2. The tool was used - the Wikipedia node has an execution entry with query/output (subset of the answer’s facts).
  3. The answer cites the entry - the system prompt’s instruction surfaced in the reply.
  4. Duplicate check - “same question twice”: memory sub-node not attached → identical answers; attached → context-aware follow-ups.

Then remix it:

  • Add tools from the official tool sub-node list - calculator, code, SEARXNG web search, WolframAlpha, HTTP Request over toolMCP (any MCP server you set up with our MCP guide), plus memory and output parsers.
  • Most tools need credentials (Wikipedia doesn’t).
  • Export your work: … menu → Download file writes JSON; Import from URL/File restores it. Copy-paste nodes between workflows (Ctrl/Cmd+C → V) also works on the canvas.

Troubleshooting

”Workflow could not be started!” on the Chat Trigger

Classic cause per the official chat-trigger docs: showing a “Load Previous Session” chat with a sessionId while no fixed-sessionId memory (Simple Memory) is attached. Fix: remove the session option or attach Simple Memory and set its sessionId to a fixed value. Also double-check the root node itself has its required connector satisfied (a Chat Trigger without an agent/chain attached can’t start).

Execution failed on the OpenAI Chat Model node / 401

The two usual causes: the credential exists but the key is invalid/revoked; or the credential type doesn’t match the node (the Chat Model only accepts OpenAI API). Check the error text in the node output: 401 = authentication (go to Credentials, edit, re-paste the key). 429 = rate limit/quota (check your OpenAI billing; small key-or-quota mistakes are the top cause). Model-not-found errors mean the model ID in the node isn’t accessible to your key - switch to gpt-4o-mini.

Assistant stops mid-answer or skips the tool

The model only reaches tools it’s explicitly wired to: if the tool connector line isn’t drawn from the agent to the tool sub-node, the agent silently acts without it. Confirm the connector shows on canvas, and that the prompt actually instructs tool use (“search Wikipedia before answering”). If answers are still tool-less, the model chose not to call it - rephrase or use a stronger model.

Executions are slow or OpenAI errors with “context length exceeded”

Chat memory grows every turn; long sessions bust the model’s context window. Attach (or reset) Simple Memory, or raise the model’s max-tokens / switch to a model with a larger context. Visit the official Chat Model docs for the exact options.

Webhook/chat URL returns 524 - “Request Timeout”

n8n Cloud terminates long requests at ~100 seconds (official Webhook docs). For chat workflows this bites only on huge prompts with many tool round-trips; split the work, or reduce parallel tool calls. Self-hosted instances don’t have this fixed cap.

Self-hosted: “Another process is using port 5678” / containers won’t start

The official image binds 5678. A second instance or leftover container from a first run owns it - docker ps to find it, docker rm -f <name> to remove. For the local walkthrough also keep N8N_SECURE_COOKIE=false or the web UI rejects browser connections.

You did it

  • You chose Cloud vs self-hosted with the cost table in mind
  • The workflow runs end-to-end from the Chat Trigger’s test chat
  • OpenAI credential attached - no auth error on execute
  • One answer in the execution log proves the Wikipedia tool fired
  • You can export the workflow to JSON and re-import it cleanly
Official sources

All fetched 13 August 2026 (n8n stable 2.x). Treat node names credentialed as of that date.

Next: connect your workflow to the outside AI universe - point an MCP client at n8n’s built-in MCP server so Claude can drive your workflows, or deep-dive into what makes agents tick under the hood.

Questions, answered first

What is an AI Agent node in n8n?

The AI Agent node is n8n's cluster root node for building AI-enabled workflows: it connects to one chat or trigger root node upstream, one language-model sub-node, and any number of tool/retriever/memory sub-nodes, then orchestrates them - decide, call a tool, read the output, decide again - until it answers. Since v1.82.0 it always works as a Tools Agent and takes decisions only from tools you explicitly connect.

Do I need a paid plan to use AI nodes in n8n?

No. AI nodes work on the free Community edition and the Cloud free trial; you only pay for your own model API usage (your OpenAI key bills you directly). Paid Cloud plans mainly change execution volume and add production features: from €20/month (Starter, 2,500 executions/month) up to the Business plan with self-hosting in the bundle. The 2026 Cloud free trial also includes 800 AI credits for n8n's hosted AI features.

How do AI workflows compare to normal n8n workflows?

Normal workflows are fixed pipelines: data in, deterministic nodes, data out. AI workflows use the builder's Cluster node system: a root node (AI Agent) plus sub-nodes (Chat Model, tools, memory, output parser). The agent picks its path at runtime based on the prompt, which makes outputs vary - and makes them require the model credential, the memory sub-nodes, and model-aware troubleshooting that the rest of this guide covers.

Can my AI workflow also call other AI tools like MCP servers?

Yes. n8n ships an HTTP Request node and official tool sub-nodes (including toolMCP for MCP-compatible servers you configure), so an agent can call a Filesystem or GitHub MCP server - and n8n itself exposes its own built-in MCP server so external AI tools like Claude Code can control your workflows. Both directions are covered in our [MCP guide](/guides/how-to-use-mcp/).

Is n8n fair-code / can I use it for free?

Yes - n8n is fair-code, not open source, which means you run the free Community edition commercially or self-hosted without paying, while the codebase stays protected. Fair-code restrictions mainly cover rebranding/re-selling; for individuals and most companies the Community edition plus your own model API costs is zero-license-fee. Check n8n.io/pricing for the exact edition boundaries.

You did it

  • You decided on Cloud vs self-hosted with a real cost in mind
  • The workflow executes end-to-end from the Chat Trigger's test chat
  • The OpenAI credential is attached with no auth error on execute
  • Your agent used the Wikipedia tool (the prompt's answer contains facts not in the prompt)
  • You checked both an execution's input and output in the execution log
  • You can export the workflow as JSON and re-import it
Official sources