Skip to content

Your First AI Workflow with n8n

n8n is a powerful workflow automation tool that lets you connect AI models like OpenAI’s GPT to hundreds of apps without code. Build smart automations visually with a drag-and-drop interface.

What you’ll build: An AI-powered content moderation workflow that automatically analyzes user submissions and routes them based on sentiment.

Use cases: Content moderation, email auto-responses, data enrichment, customer support triage.

Time: 30 minutes

  • n8n account (free at n8n.cloud) or self-hosted installation
  • OpenAI API key
  • Basic understanding of automation concepts
  1. Go to n8n.cloud
  2. Create free account
  3. Access your workflow editor
Terminal window
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n

Access at http://localhost:5678

  1. Click Settings > Credentials
  2. Click Add Credential
  3. Search “OpenAI”
  4. Enter your API key
  5. Test connection
  6. Save

Workflow: AI Content Analyzer

Components:

  1. Webhook - Receives content submissions
  2. OpenAI - Analyzes sentiment
  3. IF - Routes based on result
  4. HTTP Request - Sends to appropriate endpoint

1. Add Webhook Trigger

  • Drag “Webhook” node to canvas
  • Set path: /analyze-content
  • Method: POST
  • Click “Listen for test event”

2. Add OpenAI Node

  • Search “OpenAI” and add node
  • Connect to webhook
  • Select credential
  • Operation: “Message a Model”
  • Model: gpt-4o-mini
  • Prompt:
Analyze this content for sentiment and toxicity:
Content: {{$json.body.content}}
Return JSON with format:
{
"sentiment": "positive|negative|neutral",
"toxic": boolean,
"confidence": 0.0-1.0,
"reason": "brief explanation"
}

3. Add IF Node

  • Connect to OpenAI node
  • Condition: {{$json.toxic}} === true
  • True branch: Flag for review
  • False branch: Approve

4. Add Action Nodes

For True (toxic content):

  • HTTP Request node
  • URL: Your moderation endpoint
  • Method: POST
  • Body: {{$json}}

For False (clean content):

  • HTTP Request node
  • URL: Your approval endpoint
  • Method: POST
  • Body: {{$json}}
  1. Click Execute Workflow
  2. Send test data via webhook:
Terminal window
curl -X POST http://localhost:5678/webhook/analyze-content \
-H "Content-Type: application/json" \
-d '{"content": "This is a great product!"}'
  1. Check execution log
  2. Verify correct routing
Gmail Trigger → OpenAI (Draft Response) → IF (Confident?) → Gmail (Send)
Database Trigger → OpenAI (Analyze) → Update Record → Slack Notify
Scheduler → OpenAI (Generate) → Format → Post to CMS

Add “Error Trigger” node:

  • Catches workflow failures
  • Logs to monitoring system
  • Sends alerts

Use “Wait” node between API calls to avoid rate limits.

Monitor OpenAI usage:

  • Set max tokens
  • Use cheaper models for simple tasks
  • Cache frequent requests
  • Test with sample data first
  • Use n8n’s test execution mode
  • Monitor costs during testing
Gmail Trigger
OpenAI (Analyze Sentiment)
IF (Urgent + Negative?)
↓ Yes ↓ No
Slack Alert Label Email
Twitter Trigger (New Mentions)
OpenAI (Classify Intent)
Switch (Intent Type)
↓ Question ↓ Complaint ↓ Praise
OpenAI Reply Alert Team Thank User

Issue: OpenAI timeout

  • Increase timeout in HTTP Request settings
  • Use shorter prompts
  • Check API status

Issue: Webhook not receiving data

  • Verify webhook URL is correct
  • Check firewall settings
  • Test with curl first

Issue: High costs

  • Use gpt-4o-mini instead of gpt-4o
  • Add caching layer
  • Limit workflow triggers

Learn more:

Advanced workflows:

  • Multi-step AI reasoning chains
  • Custom function nodes
  • Sub-workflows for reusability

Found an issue? Open an issue!