How to build your first n8n workflow with AI
n8n looks complicated until you understand the mental model. Once that clicks, you can wire AI into almost any process in under an hour. Here is where to start.
The mental model that makes everything click
n8n is a visual automation tool. You build workflows by connecting nodes, where each node does one specific thing and passes its output to the next. A node might receive a webhook, call an API, transform data, or send a message. The workflow is just a pipeline of these steps.
The thing that trips most beginners is trying to understand n8n all at once. The node library is large. The documentation covers edge cases that do not matter yet. Ignore most of it. You only need to understand three types of nodes to build 80 percent of useful workflows: trigger nodes that start the workflow, action nodes that do something, and the HTTP Request node that connects to anything else.
Start with one workflow that does one thing. Build it, run it, understand why it works. Everything else is a variation of the same pattern.
Getting n8n running
You have two options. n8n Cloud is the fastest way to start. Sign up, get a URL, and you are building workflows in five minutes. It handles hosting, updates, and scaling for you. The free tier gives you a limited number of workflow executions per month, which is plenty to learn.
Self-hosted n8n runs on your own server or locally via Docker. The one-line Docker command is: docker run -it --rm --name n8n -p 5678:5678 n8nio/n8n. This gives you n8n running at localhost:5678. Self-hosted is free and there are no execution limits, but you manage the infrastructure yourself.
For learning, start with Cloud. For production workflows processing sensitive data or requiring high volume, run your own instance.
Once you are logged in, the interface shows you a canvas. Nodes sit on the canvas and connect to each other with lines that represent the data flow. The left panel is your node library. That is the full extent of the UI you need to understand right now.
Your first workflow: classify an email reply with AI
Email reply classification is the ideal first workflow. It is genuinely useful, straightforward to build, and teaches you the core pattern you will use in every workflow after it.
The goal: a cold email reply comes in, the workflow reads it, an AI classifies the intent, and the result gets logged to a Google Sheet.
Start by creating a new workflow and adding a Webhook trigger node. Click on it, set the HTTP method to POST, and copy the webhook URL it generates. This URL is your entry point. Anything sent to this URL will trigger the workflow.
Add an OpenAI node and connect it to the webhook. Click the OpenAI node to configure it. Set the operation to Message a Model, select GPT-4o, and write your system prompt. The prompt should tell it to classify the incoming text as one of four categories: Interested, Not Interested, Out of Office, or Objection. Tell it to return a JSON object with a category field and a confidence field.
In the user message field, reference the data from your webhook using n8n's expression syntax. The incoming email text will be at something like {{ $json.body.email_text }} depending on how you structure your payload.
Add a Google Sheets node. Connect it to the OpenAI node. Set the operation to Append Row. Map the classification output from the OpenAI node along with the original email text to columns in your sheet.
Save the workflow and activate it. Send a test POST request to your webhook URL using Postman or a simple curl command. Watch the execution run in real time by clicking the Executions tab.
If it works, you have built your first AI workflow. If it errors, the execution log shows you exactly which node failed and what the error was. Fix it there.
Working with data in n8n
Everything in n8n is structured as an array of items. Every node receives items and outputs items. An item is a JSON object with a json property that holds the actual data.
When you reference data from a previous node, you use expressions: double curly braces wrapping a path to the field you want. The expression {{ $json.fieldName }} reads the fieldName property from the current item. The expression {{ $('NodeName').item.json.fieldName }} reads a field from a specific named node.
The quickest way to understand what data is available at any point in the workflow is to click the node and look at the Input panel. This shows you the exact structure of what came in. The Output panel shows what the node produced. Reading these two panels tells you everything you need to know to wire the next node correctly.
If you are unsure what a field is called, click the expression editor (the small icon next to any input field). It shows you a tree of all available data you can reference.
Adding error handling once it runs
The most common mistake in n8n workflows is shipping them without any error handling and discovering the failure mode in production when something goes wrong at 2am.
Once your workflow runs clean through happy-path testing, add two things. First, enable Continue on Error in your critical nodes (especially API calls). This means the workflow keeps running even if one node fails, rather than stopping entirely. You can then handle the failure downstream.
Second, add an error workflow. In your main workflow settings, you can specify a separate workflow to trigger whenever the main one fails. That error workflow should send you a Slack message or email with the error details. Building this on day one means you will always know when something breaks.
The function node is your escape hatch when built-in nodes cannot do exactly what you need. It lets you write JavaScript directly. It is also where most beginners get stuck. If you hit a wall with a function node, paste the node code and the input data into Claude Code and ask it to fix it. This saves significant debugging time.