M
MJK.Supplies
Home / n8n / n8n AI Automation: Build Claude, GPT, and AI-Pow…
n8n

n8n AI Automation: Build Claude, GPT, and AI-Powered Workflows

n8n is one of the best platforms for building AI-powered automations. Its flexibility, open-source nature, and broad integration library make it ideal for connecting AI models to real business workflows. This guide covers how to add AI to n8n workflows — from simple Claude API calls to full multi-step AI agent pipelines.

M
MJK Supplies · Jun 16, 2026 · 12 min read
ShareXinf↗
n8n AI Automation: Build Claude, GPT, and AI-Powered Workflows

Why n8n for AI Automation

n8n is the best open-source platform for AI workflow automation for several reasons:

HTTP Request node: Call any AI API (Claude, OpenAI, Gemini, ElevenLabs) from a single configurable node. No waiting for a native integration.

Code node: Write JavaScript to pre-process inputs or parse structured outputs from AI models.

Loop and branch: Build retry logic, handle multiple items, route based on AI classification.

Self-hosted: Your data stays on your infrastructure. Critical for sensitive business data being sent to AI.

Active AI community: Templates and examples for common AI workflows are shared in the n8n community.

Connecting Claude to n8n

Use the HTTP Request node to call Claude's API:

Node configuration:

  • Method: POST
  • URL: https://api.anthropic.com/v1/messages
  • Authentication: Header Auth

- Name: x-api-key - Value: {{$env.ANTHROPIC_API_KEY}}

Body (JSON):

{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ { "role": "user", "content": "{{$json.prompt}}" } ] }

Add these headers:

  • anthropic-version: 2023-06-01
  • content-type: application/json

Extract the response in the next Code node:

const responseBody = $input.first().json; const content = responseBody.content[0].text; return [{ json: { aiResponse: content } }];

System Prompts for Workflows

For consistent AI behavior across workflow runs, use system prompts:

{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "system": "You are an email classifier. Classify each email into one of these categories: support, sales, billing, other. Return only the category name, nothing else.", "messages": [ { "role": "user", "content": "Email subject: {{$json.subject}}\nEmail body: {{$json.body}}" } ] }

The system prompt defines Claude's role and constraints. The user message provides the specific data.

Common AI Workflow Patterns

Email Classification and Routing: Gmail trigger → Claude (classify: support/sales/billing) → IF node (branch by category) → Create Zendesk ticket / HubSpot deal / Billing task

Content Generation Pipeline: Airtable trigger (new content brief) → Claude (generate article) → WordPress/CMS (create draft) → Slack (notify team)

Lead Enrichment: HubSpot webhook (new contact) → Apollo API (get company data) → Claude (generate personalised talking points) → HubSpot (update contact)

Document Analysis: Email attachment → Extract text → Claude (summarise and extract key dates/numbers) → Notion (create structured document summary)

Competitor Monitoring: Schedule trigger (weekly) → HTTP (fetch competitor pages) → Claude (compare to previous version, highlight changes) → Slack (alert if significant changes)

Building an AI Agent in n8n

For multi-step AI tasks, chain multiple Claude calls:

Research + Draft workflow:

  1. Webhook: receive article topic
  2. HTTP: search for relevant recent articles (use a search API)
  3. Code: combine search results into research context
  4. HTTP (Claude): "Based on this research, write a 1500-word article about [topic]"
  5. HTTP (Claude): "Review this article and list specific improvements needed"
  6. HTTP (Claude): "Revise the article based on this feedback"
  7. CMS: create article draft

The loop through review-revise dramatically improves final quality.

Using n8n's Built-in AI Nodes

n8n has native AI nodes (available in recent versions):

AI Agent node: Orchestrates an AI agent with tool use capability. Connect tools (calculator, Wikipedia, HTTP) and the AI decides when to use them.

Summarize node: Built-in text summarisation with your choice of AI model.

Ask Claude node: Direct Claude integration without manual HTTP node setup.

Chat Memory nodes: Store conversation history for multi-turn AI conversations.

These native nodes are faster to set up than manual HTTP configuration but less flexible for advanced use cases.

Error Handling for AI Workflows

AI calls can fail. Build robustness:

Retry on failure: Add an "Error Trigger" node → HTTP (retry the Claude call) → Email alert if retry fails

Validate AI output:

// Code node after Claude call const response = $input.first().json.content[0].text; // Validate it's valid JSON if expected try { const parsed = JSON.parse(response); return [{ json: parsed }]; } catch (e) { // Retry or alert throw new Error('AI returned invalid JSON: ' + response); }

Token limit handling: Before sending to Claude, check token count. Truncate or chunk inputs that might exceed limits.

Recommended Tools

  • n8n — Self-hosted or cloud; the automation platform
  • Claude API — Best AI model for reliable workflow integration
  • OpenAI API — Alternative; has native n8n node
  • ElevenLabs — Voice AI to add to n8n workflows
  • Airtable — Data management layer for AI workflows
#n8n#ai#claude#openai

Related articles

MJK Supplies · Automation Services

Want this built for you?

We design and ship custom AI agents and automation systems for teams that want results, not a backlog. Book a free 30-minute consult — no commitment, no pitch deck.