Claude + n8n: build AI workflows on a VPS
Connect Claude to n8n on your own VPS: an integration guide with credentials, model choice per node, three worked AI workflows, cost math, and common errors.
What you are building
Three working AI workflows on the n8n instance you already run: a webhook that summarizes whatever you throw at it, a scheduled feed-reader that turns articles into structured spreadsheet rows, and an AI Agent that calls an HTTP API on its own to answer questions. This is the no-code counterpart to calling the Claude API from Python on your VPS, same API, same tokens, same bill, but the orchestration lives in n8n nodes instead of a script.
I assume n8n is already up behind HTTPS per the self-hosted n8n on Docker guide. If it is not, do that first, webhooks need a real TLS endpoint, and the credential store you are about to put an API key into needs the encryption-key backup that guide nags you about.
The interesting problems here are not drag-and-drop. They are model selection per node, prompt fields that silently interpolate undefined, and the fact that an automation runs unattended, a workflow that costs half a cent per run is cheap until a retry loop runs it four thousand times overnight. Most of this guide is about those.
One credential, encrypted with the key you backed up
Get an API key from the Anthropic Console at platform.claude.com, Settings, then API Keys, then create a key named something like n8n-vps. It is shown once. The Console also asks you to choose an expiration when you create the key; note the date, because an expired key breaks an unattended workflow with the same 401 described under failure modes below. Fund the account or set up billing; API usage is pay-per-token, paid from prepaid credits. A Pro subscription does not cover it, but Claude Max and Team plans now include monthly Claude API credits ($100 on Max 5x, $200 on Max 20x, pooled up to $500 on Team) that you claim by linking a Console organization in your claude.ai billing settings. Those credits pay for API calls like the ones n8n makes, do not cover Claude Code, and expire at the end of each billing cycle. If you were hoping to build these three workflows without paying anything, there is no free tier, only a few endpoints, such as token counting, that cost nothing at all.
In n8n: Credentials, Create credential, pick Anthropic, paste the key into the API Key field, save. Every Claude node in every workflow references this one stored credential, you never paste the key into a node.
Two operational notes. First, n8n encrypts stored credentials with N8N_ENCRYPTION_KEY. If you set that env var explicitly in your compose file per the n8n guide, your credential survives container rebuilds; if you let n8n generate one and then lose the volume, every stored credential, this key included, is unrecoverable ciphertext. Back the key up now if you skipped it. Second, treat the n8n credential store as the blast radius: anyone who can use your Anthropic credential can make requests with your key. On the Community edition that is you and the instance owner; n8n's docs put it as "Only the instance owner and the user who creates them can access workflows and credentials", so other Member accounts cannot reach it. Sharing workflows and credentials is a paid feature on self-hosted n8n (Business or Enterprise), and once you share a workflow, its editors can use every credential that workflow uses. So if anyone else logs into this instance, read which access controls sit behind a paid n8n licence before handing out accounts. Set a spend limit in the Console under Settings so a compromised or runaway instance has a ceiling.
Model choice is a per-node decision
The model dropdown in n8n's Claude nodes is pulled live from the API, so it shows what your key can access. The models this guide uses, with API pricing per million input/output tokens as of October 2026, are: Claude Haiku 4.5 (claude-haiku-4-5) at $1/$5 with a 200K context window, Claude Sonnet 5 (claude-sonnet-5) at $2/$10, and Claude Opus 4.8 (claude-opus-4-8) at $5/$25, both with 1M-token context windows. There is also Claude Fable 5 (claude-fable-5) at $10/$50 for the hardest reasoning work; nothing in this guide needs it. Use those exact IDs. claude-haiku-4-5 is an alias for the pinned snapshot claude-haiku-4-5-20251001, which works too, but a dated ID copied from an old tutorial may name a retired model and fail. Prices move, so check platform.claude.com before trusting any number you read anywhere, including here.
Since this guide was first published, Anthropic has released newer models, and its docs now mark Haiku 4.5, Sonnet 5 and Opus 4.8 as legacy. They still work: Haiku 4.5 retires not sooner than October 15, 2026, Sonnet 5 and Opus 4.8 not sooner than mid-2027, and Anthropic gives at least 60 days' notice before retiring a model, so watch its deprecations page if your workflows pin Haiku 4.5. The current lineup is Claude Haiku 5.5 (claude-haiku-5-5, released October 7, 2026) from $0.10/$0.50 for prompts up to 100,000 tokens and $0.50/$2.50 above that, Claude Sonnet 5.5 (claude-sonnet-5-5) at $2/$10, Claude Opus 5.5 (claude-opus-5-5) at $4/$20, and Claude Fable 5.1 (claude-fable-5-1) at $10/$50. Haiku 5.5's tokenizer counts the same text as roughly 30% more tokens than Haiku 4.5, so compare real per-run costs on the Console's usage page, not list prices alone.
The habit to build: pick the model per node, not per platform. Classification, extraction, summarization, routing, the bread and butter of automation, run beautifully on Haiku at half of Sonnet's list price and a fifth of Opus's. Reserve Sonnet for agents and multi-step reasoning, Opus for the rare workflow where a wrong answer costs more than the tokens. A workflow with five Claude nodes can and should mix models.
The two Claude nodes, and which to use where
n8n ships two distinct Anthropic integrations, and picking the wrong one is the most common beginner detour.
The Anthropic node is a regular app node: one request in, one response out. Its Text resource has a Message a Model operation, plus operations for analyzing images and documents. Use it whenever the workflow logic lives in n8n, trigger, Claude call, next node. Workflows 1 and 2 below use it or its chain equivalent.
The Anthropic Chat Model node is a sub-node, a small attachment that supplies the model to a root node like AI Agent or Basic LLM Chain. It has no trigger and no output of its own; it exposes the model picker plus sampling options like Maximum Number of Tokens and Sampling Temperature. One caveat from the n8n docs worth memorizing: expressions inside sub-nodes always resolve against the first input item, not each item, put per-item expressions in the root node's prompt fields, not in the sub-node. And one from Anthropic's side: on Claude 4.7 and later models, which is every model in this guide except Haiku 4.5, setting temperature, top_p or top_k to a non-default value returns a 400 error, so leave Sampling Temperature, Top K and Top P unset on those models.
Workflow 1: webhook in, summary out
The hello-world of AI automation: anything POSTed to a URL gets summarized and lands in Slack or your inbox.
- Webhook node, HTTP Method POST, path
summarize. n8n gives you a test URL and a production URL; the production one only listens once the workflow is published. - Anthropic node, Message a Model, model
claude-haiku-4-5, Max Tokens around 300. - Slack node (or Send Email), post the response text to a channel.
The prompt is where n8n expressions meet Claude. A POST body lands under $json.body, so the user message field looks 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 in the node's system prompt field, not the user message, the system prompt stays constant while the payload varies, which keeps behavior stable and makes the prompt legible six months from now. Test it from the 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..."}'Per-run cost on Haiku: a 1,200-token payload plus prompt is about $0.0012 in, 300 tokens out is $0.0015, roughly a quarter of a cent. A thousand runs a month is under $3. The same node pointed at Opus 4.8 is about five times that. That ratio, multiplied by every workflow you build, is why the per-node model habit matters.
Workflow 2: scheduled RSS to structured rows
Now something on a clock, with structured output: read an RSS feed hourly, classify each item, append rows to a sheet.
- Schedule Trigger, every hour.
- RSS Read, the feed URL. Outputs one item per article.
- Basic LLM Chain, with an Anthropic Chat Model sub-node set to
claude-haiku-4-5, and a Structured Output Parser sub-node holding a JSON schema. - Google Sheets (or Postgres), append a row per item.
The Structured Output Parser is what turns "Claude, please return JSON" from a hope into a contract: it validates the model's reply against your schema and fails the item loudly instead of writing garbage rows. A 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 the chain's prompt references the feed item:
Classify this article for a VPS hosting audience.
Title: {{ $json.title }}
Content: {{ $json.contentSnippet }}Cost math changes shape here: this is per-item, not per-run. Fifty articles an hour, twenty-four hours a day, is 36,000 Claude calls a month, on Haiku maybe $40–90 depending on article length, on Opus about five times that. Deduplicate before the LLM node (a simple IF against previously seen links, or n8n's Remove Duplicates node) and the number collapses, because most hourly polls contain nothing new. The cheapest token is the call you never make.
Workflow 3: an AI Agent that uses tools
The first two workflows are pipelines, you decide the steps. An AI Agent node inverts that: you give Claude a goal and tools, and it decides which tools to call, in what order, until it is done. n8n requires a chat model sub-node and at least one tool sub-node attached.
A concrete build, an ops assistant that answers "what's down and why" from your monitoring:
- Chat Trigger (or webhook), the question comes in.
- AI Agent, with an Anthropic Chat Model sub-node set to
claude-sonnet-5. Agents plan and chain tool calls; Haiku can drive simple single-tool agents, but Sonnet is the sensible floor once tools multiply. - HTTP Request node attached as a tool, pointed at your Uptime Kuma status API or Zabbix endpoint. A second HTTP tool can hit anything else with a REST API.
Two settings do most of the work. The agent's System Message defines the job: "You are an ops assistant. Use the status tool to check current monitor state before answering. Report only monitors that are down, with duration." And each tool's description is not documentation for humans, it is how Claude decides when to call it. "Returns current up/down state for all monitored services as JSON" gets called at the right moments; "status API" gets ignored or misused. When you attach the HTTP Request node as a tool, enable its Optimize Response option and select the JSON fields that matter, otherwise every verbose API response is shoveled into the model's context as input tokens you pay for.
Set Max Iterations on the agent (the default is 10) to the smallest number that works, it is the difference between "the agent gave up after 4 tool calls" and a loop of a dozen model round-trips. And understand the billing shape: each iteration re-sends the full conversation so far, system message, question, every prior tool result, as input tokens. A six-iteration agent run can easily total 20,000 cumulative input tokens and 2,000 output: on Sonnet 5 at $2/$10 about $0.06, call it twenty times a simple summarization run. If you find yourself bolting many tools onto one agent, that is the point where running MCP servers on your VPS becomes the cleaner architecture.
Cost guardrails, because nobody is watching
An unattended workflow needs the controls a human at a keyboard provides implicitly. Four layers, cheapest first.
Max Tokens on every Claude node. It is a hard output cap. A summarizer needs 300, a classifier 100. This bounds the expensive side of the ledger (across the models in this guide, $5–$50 per million output tokens versus $1–$10 for input, output at five times the input price on each) and doubles as a runaway brake, a prompt bug that makes Claude ramble costs 300 tokens, not 8,000.
Model per node. Covered above; between Haiku 4.5 and Opus 4.8 it is a fivefold price lever, tenfold up to Fable 5, and across the current lineup, from Haiku 5.5 to Fable 5.1, it reaches a hundredfold for prompts up to 100,000 tokens. It takes ten seconds to set.
Bound the loops. Max Iterations on agents. A workflow timeout in the workflow's settings so a wedged execution dies instead of spinning. And be careful with per-node Retry On Fail: it is the right tool for transient errors, but retries multiply cost, Max Tries of 3 with Wait Between Tries of 5000 ms means a persistent failure bills you up to three times per item before giving up. Never wrap a retry around a node that already succeeded expensively.
An error workflow as the backstop. Create a workflow starting with the Error Trigger node that posts the failed workflow's name and error to Slack, then set it as the Error Workflow in each AI workflow's settings. The failure mode this catches is the ugly one: a schedule-triggered workflow erroring on every run, every hour, for a week, each run burning tokens before it dies. Pair it with a monthly spend limit in the Anthropic Console and check the Console's usage page the first few days after activating anything scheduled. If you want to understand exactly what you are being billed for, the token-usage guide dissects it.
Failure modes, with the strings you will see
The node fails instantly with "Authorization failed - please check your credentials." The API returned 401. The underlying body has this shape (current responses also carry a request_id field):
{"type": "error", "error": {"type": "authentication_error", "message": "invalid x-api-key"}}A mispasted key, truncated, trailing whitespace, or the placeholder from a tutorial. Recreate the n8n credential and paste again; if it worked yesterday, check whether the key was revoked or reached its expiration date in the Console, or whether a volume restore rolled back to a credential encrypted with a different N8N_ENCRYPTION_KEY.
Executions fail in bursts with a 429 rate_limit_error, message along the lines of "Number of request tokens has exceeded your per-minute rate limit." Rate limits are per-minute buckets, and n8n makes it very easy to fire fifty webhook or RSS executions simultaneously. Fix it structurally: process items in sequence (Loop Over Items) rather than parallel, and set Retry On Fail with Max Tries 3 and Wait Between Tries at its 5000 ms maximum, n8n caps that field at 5000 ms. When you need a longer backoff so retries land in the next minute window, put a Wait node in the error path or process items one at a time. The response carries a retry-after header telling you exactly how long to wait, n8n's fixed wait cannot read it, so build the longer pause yourself. One exception: a 429 with no retry-after header and an error_code of enforced_spend_limit_reached means your organization hit its usage tier's monthly spend cap, and no retry succeeds until the next month or a tier increase.
404 not_found_error naming your model. The message names the model ID you sent, along the lines of:
{"type": "error", "error": {"type": "not_found_error", "message": "model: claude-haiku-4.5"}}Dots instead of hyphens (4.5 for 4-5), a mistyped or invented date suffix, or a retired model from an outdated blog post. Fix the ID against the current list, this bites people who type into the model field as an expression instead of picking from the dropdown.
Claude answers a question you did not ask. No error anywhere, the run is green. An n8n expression that references a missing field, like {{ $json.body.text }} when the payload used message, interpolates the literal string undefined into your prompt, and Claude gamely responds to a prompt about nothing. If the referenced node did not execute at all, n8n stops with an error saying the expression references a node that "hasn't been executed yet", but a missing field is silent. Before activating, always run once with real data and read the actual rendered prompt in the node's input panel, the expression editor previews the resolved value, and undefined is right there if you look.
FAQ
How do I connect Claude to n8n?
Create an API key in the Anthropic Console at platform.claude.com, then in n8n add a credential of type Anthropic and paste it into the API Key field. Every Claude node, the Anthropic app node and the Anthropic Chat Model sub-node, references that stored credential. n8n encrypts it with N8N_ENCRYPTION_KEY, so back that key up or your credentials are lost with the volume.
What does an AI workflow cost per run?
Estimate tokens per run, then multiply by the model's per-million prices, as of October 2026, Haiku 4.5 is $1/$5 per million input/output tokens and Sonnet 5 is $2/$10. A webhook summarization on Haiku runs about a quarter of a cent; an agent run on Sonnet with several tool calls lands nearer $0.06–$0.10 because every iteration re-sends the whole conversation as input. Verify the run in the Console's usage page rather than trusting estimates.
Which Claude model should I use for n8n automations?
Haiku 4.5 for classification, extraction, summarization, and routing, high-volume work where speed and price dominate. Sonnet 5 for AI Agent nodes and multi-step reasoning. Opus 4.8 only where a wrong answer is expensive enough to justify its $5/$25 list price, five times Haiku, two and a half times Sonnet. Anthropic's newer Haiku 5.5, Sonnet 5.5 and Opus 5.5 fill the same roles at equal or lower list prices. Set the model per node, not per workflow, one workflow can mix all three.
How do I stop an n8n workflow from overspending on the Claude API?
Layer the guardrails: a low Max Tokens on every Claude node, Max Iterations on agents, a workflow timeout, and conservative Retry On Fail settings so failures do not multiply token spend. Then add an Error Trigger workflow that alerts you in Slack when any AI workflow fails, and set a monthly spend limit in the Anthropic Console as the hard ceiling nothing on the VPS can override.
Do AI Agent tool calls cost extra?
There is no separate tool fee, but tools are not free: every tool result is fed back to the model as input tokens, and each agent iteration re-sends the entire conversation so far. A chatty API response passed through unfiltered can dwarf your actual prompt, enable Optimize Response on HTTP Request tools and return only the fields the agent needs.