How to Build Your First AI Automation in Under 30 Minutes
Most "build your first AI automation" tutorials run 8,000 words and end with a workflow you'll never touch again. This one takes 30 minutes and ships something real: an automation that turns inbound emails into structured CRM entries, free, with the same architecture you'd use for production work.
An AI automation is a workflow where one or more AI model calls sit inside a sequence of trigger, processing, and action steps that runs without human intervention.
TL;DR
- The simplest valuable AI automation has three parts: a trigger (something happens), an AI step (model interprets unstructured input), and an action (write the result somewhere useful).
- This tutorial uses n8n cloud's free tier, Gmail, and the OpenAI API. OpenAI's per-token pricing is what keeps the model calls in this tutorial to a fraction of a cent, so a month of light personal use costs next to nothing.
- The workflow takes inbound emails, asks an LLM to extract sender intent, contact info, and urgency as JSON, then creates a row in a Google Sheet you can use as a starter CRM.
- The same three-step pattern (trigger, AI, action) generalizes to dozens of real workflows: support ticket routing, lead qualification, document classification, social mention triage.
- You'll hit one of three classic failure modes by step 4: wrong JSON, a missing field, a model hallucination. The fixes are below.
What you will build
The workflow watches a Gmail inbox. Every time a new email arrives, it sends the subject and body to GPT-4o-mini, which returns a JSON object with the sender's name, company, intent (sales, support, recruiting, spam), urgency (low, medium, high), and a one-sentence summary. The result gets appended as a row in a Google Sheet. That's a starter inbound-lead CRM, built in one sitting.
The same pattern with different inputs and outputs powers countless production automations. The point of this tutorial is the pattern, not this specific use case.
What you need before you start
Three accounts. None require a credit card to start.
- An n8n cloud account at n8n.io: free trial, then 20 dollars per month for the Starter plan, or self-host for free if you prefer
- A Google account with Gmail and Sheets access
- An OpenAI account with API access and a few dollars of credit on file. OpenAI's pricing page puts GPT-4o-mini at 0.15 dollars per million input tokens and 0.60 dollars per million output tokens, which works out to a fraction of a cent per email
If you want a fully free path, swap n8n cloud for n8n self-hosted on your laptop or a low-cost VPS, and swap OpenAI for the free Groq API or Google AI Studio's Gemini free tier. The architecture is identical.
Step 1: Set up the trigger
Sign in to n8n cloud and create a new workflow. Add a Gmail Trigger node and connect your Google account through the OAuth flow. Set the trigger to "On Message Received" with a polling interval of one minute. Filter to a specific label like inbox or a custom automate-me label, so you can test cleanly without flooding your sheet with every existing email.
Click "Listen for Test Event" and send yourself a test email from another account. The node should light up green, with the email's subject, body, and sender visible in the right panel. If it doesn't, check two things first: Gmail OAuth scopes (re-authenticate and select the correct scopes) and the label filter (verify the label name matches exactly).
Step 2: Send the email content to an LLM
Add an OpenAI node after the Gmail trigger. Choose the "Message a Model" operation, model gpt-4o-mini, and set the temperature to 0. The system message goes:
You are a strict JSON extraction service. Given an email, return ONLY valid JSON matching this schema:
{
"sender_name": "string",
"company": "string or null",
"intent": "sales | support | recruiting | spam | other",
"urgency": "low | medium | high",
"summary": "one sentence summary"
}
Do not include any text outside the JSON.
The user message is the email content, built from the trigger output:
Subject: {{ $json.subject }}
From: {{ $json.from.value[0].address }}
Body: {{ $json.text }}
Execute the node. The output should be a JSON-parseable string in the message field. If you get prose instead of JSON, the model ignored the system instruction. Set temperature to 0 and add the phrase "ONLY JSON, no prose" to the system message.
Step 3: Parse the JSON response
Add a Code node after the OpenAI node. The default JavaScript snippet should be:
const raw = $input.first().json.message.content;
let parsed;
try {
parsed = JSON.parse(raw);
} catch (e) {
parsed = { sender_name: 'unknown', company: null, intent: 'other', urgency: 'low', summary: 'JSON parse failed' };
}
return [{ json: parsed }];
This is the single most important node in the whole automation. Models occasionally return malformed JSON, and without a try/catch your workflow crashes. The fallback values mean a bad model response writes a row you can review later, instead of breaking the pipeline.
Always wrap LLM JSON parsing in a try/catch with sensible fallbacks. The most common production AI workflow failure is a model returning prose when you expected JSON. The second most common is a missing field. Defensive parsing isn't optional.
Step 4: Write the row to Google Sheets
Add a Google Sheets node. Connect your Google account, create a new sheet called email-triage with columns: received_at, sender_name, company, intent, urgency, summary, original_subject. Set the Google Sheets node operation to "Append Row" and map each column to the upstream nodes: received_at from the Gmail trigger's date, sender_name through summary from the Code node's output, original_subject from the Gmail trigger.
Execute the workflow end to end with a test email. You should see a new row appear in your sheet within seconds.
Step 5: Activate and test
Click the Active toggle at the top right of the workflow. Send three test emails of different types: a sales inquiry, a support question, and an obvious recruiter pitch. Check your sheet after one minute. All three should appear with the correct intent classifications.
That's a working production AI automation, in four nodes. Based on OpenAI's published pricing, the model call for a typical email costs a small fraction of a cent. The pattern you just used is the same one behind most "AI agent" products you've read about.
What to do when it breaks
It will break. Here are the three failures you're most likely to hit in the first week, and the fixes.
The model returns prose instead of JSON. Set temperature to 0, restate the JSON-only requirement in the user message, and add an "Output: " prefix the model can complete. If it still happens, swap to a model with native structured output mode (gpt-4o with the response_format: json_object parameter).
The model hallucinates a sender name or company that wasn't in the email. Usually that means the prompt asked for a field that's genuinely missing. Make the field nullable in the schema and instruct the model to return null when the value isn't present.
The Google Sheets node throws a quota error. Google's published limit is 60 write requests per minute per user. Low-volume personal use won't come close. For higher volume, switch the destination to Airtable or a Postgres table.
The pattern, generalized
The trigger-AI-action pattern is the building block for almost every useful AI automation. Examples that drop into the same template:
- Trigger: new Slack message in a channel. AI: classify whether this needs the on-call engineer. Action: page on-call if yes.
- Trigger: new Stripe charge. AI: write a personalized thank-you email referencing the customer's plan and history. Action: send via SendGrid.
- Trigger: new podcast episode in an RSS feed. AI: summarize the episode and extract three key claims. Action: post to a Notion database.
- Trigger: new GitHub issue. AI: classify priority and tag the right component. Action: update the issue with the labels.
Each of these is the same four nodes with different connectors. Once you've built one, the rest are mostly a matter of swapping the trigger and the prompt.
What to do next
Three concrete next steps to extend what you've built.
First, add a Filter node before the OpenAI call to skip newsletters and automated emails. That saves money and cuts noise. Second, add a Slack node alongside the Sheets node that pings you immediately for any email tagged as high urgency. Third, swap the Google Sheet for an Airtable base where you can add follow-up tracking columns and turn the triage feed into an actual mini-CRM.
The hard part of AI automation isn't the AI. It's the workflow design: picking a trigger that fires at the right time, structuring the prompt so the output is reliable, and writing to a destination that's actually useful. The AI is one node in a four-node pipeline.
FAQs
Related Guides
- How to Build a Lead Generation Workflow in n8n Step by Step
- The Complete AI Automation Playbook for 2026: Tools, Workflows, and ROI
- How to Build a Weekly AI Article Recommendation Workflow
Do I need to know how to code to build AI automations?
No. n8n, Make, and Zapier are no-code platforms that let you wire up triggers, AI calls, and actions visually. You'll run into small JavaScript snippets in nodes like the JSON parser in this tutorial, but those are short, copy-pasteable, and well documented. Most useful automations need zero original code.
What is the cheapest way to run AI automations?
Self-host n8n on a low-cost VPS or your laptop, use the Groq API or Gemini's free tier for LLM calls, and write outputs to free Google Sheets or Airtable bases. Cost scales with LLM token usage, so picking a small model like gpt-4o-mini, Gemini Flash, or Llama on Groq matters a lot.
Should I use n8n, Make, or Zapier for my first automation?
For pure ease of use and the largest app catalog, Zapier. For the best price-to-power ratio with multi-step logic, Make. For the most flexibility and a self-hostable option, n8n. The patterns are identical across all three. Most readers of this site end up on n8n because the AI ecosystem has standardized around it for production work.
How do I keep my OpenAI costs from getting out of control?
Set a hard monthly spend limit in your OpenAI billing dashboard. That's the real safety net. Use the smallest model that solves the problem: gpt-4o-mini handles most extraction tasks for a fraction of gpt-4o's cost, according to OpenAI's pricing page. Add filters before the LLM call so you don't pay to process newsletters and noise. Log token usage so you can spot a runaway prompt early.
Are AI automations reliable enough for production?
Yes, if you build them with defensive parsing, validation rules, and good observability. The unreliable AI automations you hear about usually skipped the parsing safeguards or had no monitoring. A well-built automation with a try/catch on the LLM output, a validation step, and error notifications holds up for years.
