SSD Nodes Learn
Guides Matt ConnorBy Matt Connor

Claude + n8n: build AI workflows on a VPS

Wire the Claude API into self-hosted n8n: credentials, model choice per node, three worked AI workflows, per-run cost math, and the errors that bite.

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. Fund the account or set up billing; API usage is pay-per-token and entirely separate from any Claude.ai subscription.

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 edit workflows on your instance can make requests with your Anthropic key. 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. As of July 2026 the lineup and API pricing per million input/output tokens is: Claude Haiku 4.5 (claude-haiku-4-5) at $1/$5 with a 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. 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 — a date-suffixed variant you remember from an old tutorial will 404, and prices move, so check platform.claude.com before trusting any number you read anywhere, including here.

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 a third 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.

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.

  1. 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 active.
  2. Anthropic node — Message a Model, model claude-haiku-4-5, Max Tokens around 300.
  3. 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.

  1. Schedule Trigger — every hour.
  2. RSS Read — the feed URL. Outputs one item per article.
  3. 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.
  4. 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:

  1. Chat Trigger (or webhook) — the question comes in.
  2. 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.
  3. 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's introductory pricing about $0.06, roughly $0.09 at the standard $3/$15 — 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 ($5–$25 per million output tokens versus $1–$5 for input) and doubles as a runaway brake — a prompt bug that makes Claude ramble costs 300 tokens, not 8,000.

Model per node. Covered above; it is a five-to-tenfold price lever across the current lineup and 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 is:

{"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 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 of 10000 ms or more so retries land in the next window. The response carries a retry-after header telling you exactly how long to wait — n8n's fixed wait cannot read it, so size the wait generously.

404 not_found_error naming your model. The body echoes the 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 an outdated blog post, or a retired model. 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 you get "Referenced node is unavailable", 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 July 2026, Haiku 4.5 is $1/$5 per million input/output tokens and Sonnet 5 is $3/$15 ($2/$10 introductory through August 2026). 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, a bit under twice Sonnet. 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.