how to connect Claude to n8n on VPS
Learn how to setup Claude with n8n on your VPS. We show you 3 workflows, how to pick model nodes, and how to avoid high bills from retry loops.
Wetin you dey build
Three working AI workflows for n8n instance wey you don already run: one webhook wey go summarize anything wey you throw at am, one scheduled feed-reader wey go turn articles into structured spreadsheet rows, and one AI Agent wey go call HTTP API by itself to answer questions. Dis one na no-code version of calling the Claude API from Python on your VPS — same API, same tokens, same bill, but instead of script, n8n nodes dey handle the orchestration.
I assume say n8n don dey run behind HTTPS according to self-hosted n8n on Docker guide. If e never happen, do dat one first — webhooks need real TLS endpoint, and de credential store wey you wan put API key inside need de encryption-key backup wey dat guide talk about.
De interesting problem for here no be just drag-and-drop. Na model selection per node, prompt fields wey dey silently interpolate undefined, and de fact say automation dey run without person — workflow wey cost half a cent per run dey cheap, until retry loop run am four thousand times overnight. Most of dis guide na about dem.
One credential, encrypted with de key wey you back up
Get API key from Anthropic Console for platform.claude.com — Settings, den API Keys, den create key wey get name like n8n-vps. Dem go show am once only. Fund de account or set up billing; API usage na pay-per-token and e dey separate from any Claude.ai subscription.
For n8n: Credentials, Create credential, pick Anthropic, paste de key for API Key field, save. Every Claude node for every workflow dey use dis one stored credential — you no go ever paste de key inside node.
Two operational notes. First, n8n dey encrypt stored credentials with N8N_ENCRYPTION_KEY. If you set dat env var explicitly for your compose file according to n8n guide, your credential go survive container rebuilds; if you let n8n generate one and you lose de volume, every stored credential — including dis key — na unrecoverable ciphertext. Back up de key now if you skip am. Second, treat n8n credential store as de blast radius: anyone wey fit edit workflows for your instance fit make requests with your Anthropic key. Set spend limit for Console under Settings so say if instance komot or runaway, e get ceiling.
Model choice na per-node decision
De model dropdown for n8n Claude nodes dey pull live from API, so e go show wetin your key fit access. As of July 2026, de lineup and API pricing per million input/output tokens na: Claude Haiku 4.5 (claude-haiku-4-5) at $1/$5 with 200K context window, Claude Sonnet 5 (claude-sonnet-5) at $3/$15 — introductory $2/$10 through August 31, 2026 — and Claude Opus 4.8 (claude-opus-4-8) at $5/$25, both with 1M-token context windows. E still get Claude Fable 5 (claude-fable-5) at $10/$50 for hard reasoning work; nothing for dis guide need am. Use dem exact IDs — any date-suffixed variant wey you remember from old tutorial go 404, and prices dey move, so check platform.claude.com before you trust any number wey you read anywhere, including here.
De habit wey you must build: pick de model per node, no be per platform. Classification, extraction, summarization, routing — de bread and butter of automation — dey run well for Haiku at one-third of Sonnet list price and one-fifth of Opus. Reserve Sonnet for agents and multi-step reasoning, Opus for de rare workflow wey wrong answer cost more than de tokens. Workflow wey get five Claude nodes fit and suppose mix models.
De two Claude nodes, and which one to use where
n8n dey ship two different Anthropic integrations, and picking de wrong one na de most common mistake for beginners.
De Anthropic node na regular app node: one request in, one response out. Im Text resource get Message a Model operation, plus operations for analyzing images and documents. Use am whenever workflow logic dey inside n8n — trigger, Claude call, next node. Workflow 1 and 2 below dey use am or im chain equivalent.
De Anthropic Chat Model node na sub-node — small attachment wey dey supply de model to root node like AI Agent or Basic LLM Chain. E no get trigger and e no get output of im own; e just dey show de model picker plus sampling options like Maximum Number of Tokens and Sampling Temperature. One warning from n8n docs wey you suppose memorize: expressions inside sub-nodes always resolve against de first input item, no be each item — put per-item expressions for de root node prompt fields, no be for de sub-node.
Workflow 1: webhook in, summary out
De hello-world of AI automation: anything wey dem POST to URL go get summary and land for Slack or your inbox.
- Webhook node — HTTP Method POST, path
summarize. n8n dey give you test URL and production URL; de production one only dey listen once workflow don active. - Anthropic node — Message a Model, model
claude-haiku-4-5, Max Tokens around 300. - Slack node (or Send Email) — post de response text to channel.
De prompt na where n8n expressions meet Claude. POST body dey land under $json.body, so de user message field go look like:
Summarize the following feedback in three bullets, then one line:
verdict: praise | complaint | churn-risk. No preamble.
{{ $json.body.text }}Put role and format instructions for de node system prompt field, no be for de user message — de system prompt dey stay constant while de payload dey change, and dat one dey keep behavior stable and make de prompt easy to read six months from now. Test am from de VPS itself:
curl -X POST https://n8n.example.com/webhook/summarize \
-H 'Content-Type: application/json' \
-d '{"text": "Third support ticket this month about slow disk IO..."}'Cost per run for Haiku: 1,200-token payload plus prompt na about $0.0012 in, 300 tokens out na $0.0015 — roughly one-quarter of a cent. One thousand runs for month na under $3. De same node wey point to Opus 4.8 na about five times dat. Dat ratio, when you multiply am by every workflow wey you build, na why de per-node model habit matter.
Workflow 2: scheduled RSS to structured rows
Now something wey dey follow clock, with structured output: read RSS feed every hour, classify each item, append rows to sheet.
- Schedule Trigger — every hour.
- RSS Read — de feed URL. E dey output one item per article.
- Basic LLM Chain — with Anthropic Chat Model sub-node set to
claude-haiku-4-5, and Structured Output Parser sub-node wey hold JSON schema. - Google Sheets (or Postgres) — append one row per item.
De Structured Output Parser na wetin dey turn "Claude, please return JSON" from hope to contract: e dey validate de model reply against your schema and e dey fail de item loudly instead of writing garbage rows. Schema like:
{
"type": "object",
"properties": {
"category": { "type": "string", "enum": ["release", "security", "tutorial", "other"] },
"relevance": { "type": "number" },
"one_line_summary": { "type": "string" }
},
"required": ["category", "relevance", "one_line_summary"]
}And de chain prompt dey reference de feed item:
Classify this article for a VPS hosting audience.
Title: {{ $json.title }}
Content: {{ $json.contentSnippet }}Cost math dey change for here: dis one na per-item, no be per-run. Fifty articles every hour, twenty-four hours a day, na 36,000 Claude calls for month — for Haiku maybe $40–90 depending on article length, for Opus na about five times dat. Deduplicate before de LLM node (simple IF against previously seen links, or n8n Remove Duplicates node) and de number go drop, because most hourly polls no dey get anything new. De cheapest token na de call wey you no make.
Workflow 3: an AI Agent wey dey use tools
De first two workflows na pipelines — you dey decide de steps. AI Agent node dey flip dat: you give Claude goal and tools, and e go decide which tools to call, and in what order, until e finish. n8n need chat model sub-node and at least one tool sub-node attached.
One concrete build — ops assistant wey dey answer "wetin dey down and why" from your monitoring:
- Chat Trigger (or webhook) — de question dey come in.
- AI Agent — with Anthropic Chat Model sub-node set to
claude-sonnet-5. Agents dey plan and chain tool calls; Haiku fit drive simple single-tool agents, but Sonnet na de sensible floor once tools plenty. - HTTP Request node attached as a tool — point am to your Uptime Kuma status API or Zabbix endpoint. Second HTTP tool fit hit anything else wey get REST API.
Two settings dey do most of de work. Agent System Message dey define de job: "You are an ops assistant. Use de status tool to check current monitor state before answering. Report only monitors wey dey down, with duration." And each tool description no be documentation for humans — na how Claude dey decide when to call am. "Returns current up/down state for all monitored services as JSON" go get called at de right moments; "status API" go get ignored or misused. When you attach de HTTP Request node as a tool, enable im Optimize Response option and pick de JSON fields wey matter — otherwise every long API response go enter de model context as input tokens wey you go pay for.
Set Max Iterations for de agent (default na 10) to de smallest number wey work — na de difference between "de agent give up after 4 tool calls" and one loop of dozen model round-trips. And understand de billing shape: each iteration dey re-send de full conversation so far — system message, question, every prior tool result — as input tokens. One six-iteration agent run fit easily reach 20,000 cumulative input tokens and 2,000 output: for Sonnet 5 introductory pricing na about $0.06, roughly $0.09 at standard $3/$15 — call am twenty times a simple summarization run. If you see say you dey bolt many tools to one agent, dat na de point wey running MCP servers on your VPS go become de cleaner architecture.
Cost guardrails, because nobody dey watch
Unattended workflow need de controls wey human wey dey keyboard dey provide implicitly. Four layers, cheapest first.
Max Tokens for every Claude node. Na hard output cap. Summarizer need 300, classifier need 100. Dis one dey limit de expensive side of de ledger ($5–$25 per million output tokens versus $1–$5 for input) and e dey act as runaway brake — prompt bug wey make Claude ramble go cost 300 tokens, no be 8,000.
Model per node. We don talk am above; na five-to-tenfold price lever across de current lineup and e dey take ten seconds to set.
Bound de loops. Max Iterations for agents. Workflow timeout for workflow settings so say if execution jam, e go die instead of spinning. And watch out with per-node Retry On Fail: na de right tool for transient errors, but retries dey multiply cost — Max Tries of 3 with Wait Between Tries of 5000 ms means persistent failure dey bill you up to three times per item before e give up. Never wrap a retry around one node wey don already succeed expensively.
An error workflow as de backstop. Create workflow wey start with Error Trigger node wey go post de failed workflow name and error to Slack, den set am as de Error Workflow for each AI workflow for settings. De failure mode wey dis one dey catch na de ugly one: schedule-triggered workflow wey dey error every run, every hour, for one week — each run dey burn tokens before e die. Pair am with monthly spend limit for Anthropic Console and check de Console usage page de first few days after you activate anything scheduled. If you wan understand exactly wetin dem dey bill you for, the token-usage guide dey dissect am.
Failure modes, with de strings wey you go see
De node fail instantly with "Authorization failed - please check your credentials." De API return 401. De underlying body na:
{"type": "error", "error": {"type": "authentication_error", "message": "invalid x-api-key"}}Key wey dem mispaste — truncated, trailing whitespace, or de placeholder from tutorial. Recreate de n8n credential and paste am again; if e work yesterday, check if de key don expire for Console or if volume restore roll back to credential wey encrypted with different N8N_ENCRYPTION_KEY.
Executions dey fail for bursts with a 429 rate_limit_error, message like "Number of request tokens has exceeded your per-minute rate limit." Rate limits na per-minute buckets, and n8n dey make am easy to fire fifty webhook or RSS executions at once. Fix am structurally: process items for sequence (Loop Over Items) instead of parallel, and set Retry On Fail with Max Tries 3 and Wait Between Tries at im 5000 ms maximum — n8n dey cap dat field at 5000 ms. When you need longer backoff so say retries land for next minute window, put a Wait node for de error path or process items one by one. De response carry retry-after header wey dey tell you exactly how long to wait — n8n fixed wait no fit read am, so build de longer pause yourself.
404 not_found_error naming your model. De body dey echo de typo:
{"type": "error", "error": {"type": "not_found_error", "message": "model: claude-haiku-4.5"}}Dots instead of hyphens (4.5 for 4-5), a date suffix from old blog post, or retired model. Fix de ID against de current list — dis one dey bite people wey dey type for de model field as expression instead of picking from dropdown.
Claude dey answer question wey you no ask. No error anywhere — de run dey green. n8n expression wey reference missing field, like {{ $json.body.text }} when de payload use message, dey put literal string undefined inside your prompt, and Claude go respond to prompt about nothing. If de referenced node no execute at all, you go get "Referenced node is unavailable", but missing field dey silent. Before you activate, always run once with real data and read de actual rendered prompt for de node input panel — de expression editor dey preview de resolved value, and undefined dey right there if you look.
FAQ
How do I connect Claude to n8n?
Create API key for Anthropic Console for platform.claude.com, den for n8n add credential of type Anthropic and paste am for API Key field. Every Claude node — de Anthropic app node and de Anthropic Chat Model sub-node — dey use dat stored credential. n8n dey encrypt am with N8N_ENCRYPTION_KEY, so back up dat key or your credentials go lost with de volume.
What does an AI workflow cost per run?
Estimate tokens per run, den multiply am by de model per-million prices — as of July 2026, Haiku 4.5 na $1/$5 per million input/output tokens and Sonnet 5 na $3/$15 ($2/$10 introductory through August 2026). Webhook summarization for Haiku dey run about one-quarter of a cent; agent run for Sonnet with several tool calls dey land near $0.06–$0.10 because every iteration dey re-send de whole conversation as input. Verify de run for de Console usage page instead of trusting estimates.
Which Claude model should I use for n8n automations?
Haiku 4.5 for classification, extraction, summarization, and routing — high-volume work wey speed and price dey dominate. Sonnet 5 for AI Agent nodes and multi-step reasoning. Opus 4.8 only where wrong answer cost expensive enough to justify im $5/$25 list price — five times Haiku, a bit under twice Sonnet. Set de model per node, no be per workflow — one workflow fit mix all three.
How do I stop an n8n workflow from overspending on the Claude API?
Layer de guardrails: low Max Tokens for every Claude node, Max Iterations for agents, workflow timeout, and conservative Retry On Fail settings so say failures no dey multiply token spend. Den add Error Trigger workflow wey go alert you for Slack when any AI workflow fail, and set monthly spend limit for Anthropic Console as de hard ceiling wey nothing for VPS fit override.
Do AI Agent tool calls cost extra?
No separate tool fee, but tools no be free: every tool result dey feed back to de model as input tokens, and each agent iteration dey re-send de entire conversation so far. One chatty API response wey dem pass without filter fit dwarf your actual prompt — enable Optimize Response for HTTP Request tools and return only de fields de agent need.