Claude API + n8n: Build AI Workflows in 30 Minutes (2026)
n8n is the most flexible workflow automation tool for connecting Claude API to your stack — Postgres, Slack, Gmail, Notion, Stripe, 400+ integrations. The HTTP Request node calls Claude in 3 fields, and you can build email triage, content generation, lead scoring, or RAG pipelines without writing code. Self-hosted n8n costs $0 (Docker), cloud starts at $20/month. With Claude Haiku at $1/M input tokens, full workflows cost $5-50/month for SMB usage. This guide covers connection setup, 5 production templates, error handling, and cost optimization.
For Claude API basics see the Python tutorial. For an alternative no-code option, the Vercel AI SDK is code-first but lower setup.
Why n8n vs Zapier vs Make
| Dimension | n8n | Zapier | Make |
|---|---|---|---|
| Free tier | Self-host unlimited | 100 tasks/mo | 1,000 ops/mo |
| Pricing (10K runs) | $20/mo cloud | ~$70/mo | ~$25/mo |
| AI integrations | HTTP node + Claude/OpenAI nodes | OpenAI native, Claude via webhook | OpenAI native |
| Self-hostable | Yes | No | No |
| JavaScript code | Built-in Function nodes | Limited | Limited |
| Best for | Devs, complex flows | Marketers, simple flows | Visual + JSON workflows |
For Claude-heavy workflows, n8n wins on: free self-host, full HTTP control, JavaScript escape hatch.
Setup: Claude API in n8n (3 minutes)
Option A: HTTP Request node (universal)
- n8n → New workflow → Add HTTP Request node
- Method:
POST - URL:
https://api.anthropic.com/v1/messages - Authentication: Header Auth → Name:
x-api-key, Value:{your-claude-key} - Headers: add
anthropic-version: 2023-06-01andcontent-type: application/json - Body Content Type:
JSON - JSON body:
{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "{{ $json.prompt }}"}]
}
Test → you get Claude's response in $json.content[0].text for downstream nodes.
Option B: Anthropic node (community)
The n8n-nodes-anthropic community node simplifies syntax. Install via:
npm install n8n-nodes-anthropic # self-hosted only
Then drag the Anthropic node, paste your API key once, select model from dropdown.
Template 1: Email Triage Pipeline
Trigger: Gmail new email → Claude classifies → Slack routes
Gmail Trigger → HTTP (Claude) → Switch → Slack (per category)
Claude prompt:
Classify this email into ONE category:
- urgent_customer
- sales_lead
- billing_question
- spam
- other
Respond with just the category name.
Email subject: {{ $json.subject }}
Email body: {{ $json.body }}
Switch node routes by Claude's output. Urgent → #support-urgent. Leads → #sales. Done in 8 nodes.
Cost: 500 emails/day × Haiku ($1/M tokens) = ~$0.15/day = $4.50/mo.
Template 2: Notion → Blog Post Generator
Trigger: Notion DB row created with status="Draft" → Claude writes post → Notion updates row
Notion Trigger → HTTP (Claude write) → HTTP (Claude SEO check) → Notion Update
Claude prompt for writing:
Write a 1500-word blog post on this topic.
Topic: {{ $json.title }}
Keywords: {{ $json.keywords }}
Audience: {{ $json.audience }}
Output markdown only. Include H2 sections and FAQ at bottom.
Second Claude call validates structure (H1+FAQ+data point). If pass, save to Notion as "Ready". If fail, save as "Needs revision" with feedback.
Cost: 1 post/day × Sonnet ($3/$15) for 4K tokens = ~$0.15/post = $4.50/mo.
Template 3: Lead Scoring + Enrichment
Trigger: Webhook (from form) → Claude scores → Postgres stores → Slack alerts high-score
Webhook → HTTP (Claude scoring) → Postgres Insert → IF (score>80) → Slack
Claude prompt:
Score this B2B lead from 0-100. Factor:
- Company size (use {{ $json.company_size }})
- Job title decision-making weight
- Email domain quality
- Stated use case fit ({{ $json.use_case }})
Output JSON: {"score": N, "reason": "...", "next_action": "..."}
Set Body Content Type with response_format or use prompt-driven JSON. See Claude API JSON Mode for reliability patterns.
Template 4: RAG over Internal Docs
Trigger: Slack slash command → Vector DB retrieval → Claude answers → Slack reply
Slack Trigger → Postgres (pgvector query) → HTTP (Claude with context) → Slack Reply
This needs an embedding step (use OpenAI embeddings or Voyage AI), but Claude does the final answer with retrieved context. Wrap retrieved chunks in <untrusted_documents> markers per Claude Prompt Injection Defense.
Cost: 50 queries/day × Sonnet + 8K context = ~$1/day = $30/mo. Cache retrieved chunks with cache_control to drop 90%.
Template 5: Customer Support Auto-Reply
Trigger: New Zendesk ticket → Claude drafts reply → human approves → Zendesk sends
Zendesk Trigger → HTTP (Claude draft) → Wait (human review via webhook) → Zendesk Update
Critical: this is draft, never auto-send. The human approval gate is the Prompt Injection Defense Pattern 7 — irreversible action requires explicit human OK.
Error Handling
n8n's default error mode is "stop workflow." For Claude API, add:
- Continue on error on the HTTP node (Settings tab)
- IF node to check
{{ $json.error }} - Wait + Retry for 429/529 (with exponential backoff in a Function node)
- Slack alert for persistent failures
For production patterns see Claude API Error Handling.
Cost Optimization
- Use Haiku for classification/extraction ($1/M vs $3/M for Sonnet) — saves 67%
- Cache long system prompts —
cache_control: {"type": "ephemeral"}saves 90% on repeated context - Batch low-priority requests through Claude Batch API — 50% off
- Set
max_tokensto reality — 200 is enough for classifications - Run n8n self-hosted — $0 vs $20/mo cloud
Combined: 80% reduction vs naive Sonnet-only flows.
Frequently Asked Questions
Does n8n have an official Claude node?
Not as of May 2026 — only community nodes. The HTTP Request node is the official-supported path and works identically.
Can n8n stream Claude responses?
Yes via the SSE feature in HTTP Request node, but streaming is rarely useful in workflows (you want the complete response before routing). Use streaming only for chat UIs.
How do I keep Claude API keys safe in n8n?
Store as n8n Credentials (encrypted at rest), never in workflow JSON. Self-hosted n8n: env var N8N_ENCRYPTION_KEY rotates the encryption key.
Can I run Claude tool use in n8n?
Yes — pass tools array in the JSON body, then handle the tool_use content blocks in a Function node, dispatch to other n8n nodes, and feed tool_result back in a follow-up Claude call. Multi-step but doable. For deeper tool use patterns see Claude API Tool Use.
What's the latency of Claude via n8n?
Add ~50ms to direct API calls for n8n routing. Total: 800ms-2s for Sonnet 4.5 short responses, faster for Haiku.
Master Claude API Production Patterns
Claude Agent SDK Cookbook ($79) — 40 production agent recipes including 8 n8n workflow templates with error handling, tool use, and cost guardrails ready to import.