Claude + n8n: How to Build AI Workflows for VPS
Connect Claude to n8n for 3 VPS workflows: webhook summaries, scheduled feed-to-spreadsheet rows, and an AI Agent with HTTP API calls, plus costs and errors.
Wetin you dey build
Three working AI workflows for the n8n instance wey you already dey run: one webhook wey dey summarize anything wey you send give am, one scheduled feed-reader wey dey turn articles into structured spreadsheet rows, and one AI Agent wey dey call HTTP API by itself to answer questions. This na the no-code version of calling Claude API from Python for your VPS, same API, same tokens, same bill, but orchestration dey happen for n8n nodes instead of script.
I assume say n8n don already dey run behind HTTPS according to the self-hosted n8n on Docker guide. If e never dey run, do that one first. Webhooks need real TLS endpoint, and the credential store wey you wan put API key inside needs the encryption-key backup wey that guide dey remind you about.
The main problems for here no be drag-and-drop. Na model selection for each node, prompt fields wey dey silently interpolate undefined, and the fact say automation dey run without person watching am. Workflow wey costs half a cent per run cheap until retry loop runs am four thousand times overnight. Most of this guide dey focus on those issues.
One credential wey you encrypt with the key wey you back up
Get API key from Anthropic Console for platform.claude.com. Go Settings, then API Keys, then create key wey you fit name something like n8n-vps. E go show only once. Console still go ask you to choose expiration when you create the key; note the date, because expired key go break unattended workflow with the same 401 wey failure modes below describe. Fund the account or set up billing; API usage na pay-per-token, and prepaid credits go pay for am. Pro subscription no cover am. But Claude Max and Team plans now include monthly Claude API credits ($100 for Max 5x, $200 for Max 20x, and pooled up to $500 for Team). You claim these credits by linking Console organization inside your claude.ai billing settings. The credits pay for API calls like the ones n8n dey make. Dem no cover Claude Code, and dem expire at the end of every billing cycle. If you dey hope to build these three workflows without paying anything, Anthropic pricing FAQ talk say new users receive small free credits to test the API. So, new Console account fit try these workflows with the starter credits before you add billing. Once dem finish, every Claude call go bill per token. Some things still no cost anything beyond tokens, like token counting endpoint and up to 1,550 free hours of code-execution time for each organization every month. But none of these three workflows use code execution. See wetin the free API credits cover go into the details.
For n8n: go Credentials, select Create credential, choose Anthropic, paste the key for API Key field, then save am. Every Claude node for every workflow go use this one stored credential. You no need paste the key inside any node.
Two operational notes. First, n8n dey encrypt stored credentials with N8N_ENCRYPTION_KEY. If you set that env var explicitly for your compose file according to the n8n guide, your credential go survive container rebuilds. If you allow n8n generate one and later lose the volume, every stored credential, including this key, go become ciphertext wey nobody fit recover. Back up the key now if you never do am. Second, treat n8n credential store as the blast radius: anybody wey fit use your Anthropic credential fit make requests with your key. For Community edition, na you and the instance owner; n8n docs put am like this: "Only the instance owner and the user who creates them can access workflows and credentials", so other Member accounts no fit reach am. Sharing workflows and credentials na paid feature for self-hosted n8n (Business or Enterprise). Once you share workflow, its editors fit use every credential wey that workflow use. So if anybody else dey log into this instance, read which access controls dey behind paid n8n licence before you give dem accounts. Set spend limit for Console under Settings, so compromised or runaway instance get a ceiling.
Model choice na per-node decision
The model dropdown for n8n's Claude nodes dey come live from the API, so e dey show wetin your key fit access. The models wey this guide use, with API pricing per million input/output tokens as of October 2026, na: Claude Haiku 4.5 (claude-haiku-4-5) at $1/$5 with 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 get 1M-token context windows. Claude Fable 5 (claude-fable-5) dey available too at $10/$50 for the hardest reasoning work, but nothing for this guide need am. Use those exact IDs. claude-haiku-4-5 na alias for the pinned snapshot claude-haiku-4-5-20251001, and e go work too, but dated ID wey person copy from old tutorial fit refer to retired model and fail. Prices dey change, so check platform.claude.com before you trust any number wey you read anywhere, including here.
Since dem first publish this guide, Anthropic don release newer models, and e docs now mark Haiku 4.5, Sonnet 5, Opus 4.8 and Fable 5 as legacy. Dem still dey work. The deprecations page list Haiku 4.5 retirement as no sooner than October 15, 2026; that date don pass, and as of October 20, 2026 the page still show Haiku 4.5 as active without deprecation notice. Sonnet 5, Opus 4.8 and Fable 5 no go retire before mid-2027. Anthropic dey give at least 60 days' notice before e retire any publicly released model, so monitor the deprecations page if your workflows pin Haiku 4.5. The current lineup na 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 tokenizer dey count the same text as roughly 30% more tokens than Haiku 4.5, so compare real cost per run for the Console's usage page, no be list prices alone.
The habit wey you need build na this: choose the model per node, no be per platform. Classification, extraction, summarization, routing, wey be the bread and butter of automation, dey run well-well for Haiku at half of Sonnet list price and one-fifth of Opus own. Keep Sonnet for agents and multi-step reasoning. Use Opus for the rare workflow where wrong answer cost pass the tokens. Workflow wey get five Claude nodes fit and suppose mix models.
Claude nodes wey exist, and which one to use for which work
n8n get two different Anthropic integrations, and choosing the wrong one na the commonest beginner mistake.
The Anthropic node na normal app node: one request enter, one response comot. Its Text resource get Message a Model operation, plus operations to analyze images and documents. Use am whenever workflow logic dey inside n8n: trigger, Claude call, next node. Workflows 1 and 2 below use am or the chain equivalent.
The Anthropic Chat Model node na sub-node, small attachment wey supplies model to root node like AI Agent or Basic LLM Chain. E no get trigger and e no get output by itself; e only exposes model picker plus sampling options like Maximum Number of Tokens and Sampling Temperature. One important warning from n8n docs wey you suppose remember: expressions inside sub-nodes always resolve against the first input item, no be each item. So put per-item expressions for the root node prompt fields, no be inside the sub-node. And one warning from Anthropic side: for Claude 4.7 and later models, wey include every model for this guide except Haiku 4.5, setting temperature, top_p or top_k to any non-default value go return 400 error. So leave Sampling Temperature, Top K and Top P unset for those models.
Workflow 1: webhook dey enter, summary dey come out
The hello-world for AI automation be this: anything wey POST to URL go get summary, then e go land for Slack or your inbox.
- Webhook node, HTTP Method POST, path
summarize. n8n go give you test URL and production URL; the production one go only listen after you publish the workflow. - Anthropic node, Message a Model, model
claude-haiku-4-5, Max Tokens around 300. - Slack node (or Send Email), post the response text go channel.
Na the prompt be where n8n expressions meet Claude. POST body go land under $json.body, so the 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 the node's system prompt field, no be user message. The system prompt dey remain constant while the payload dey change. This one keep the behavior stable and make the prompt easy to understand six months from now. Test am 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..."}'Cost for each run with Haiku: payload wey get 1,200 tokens plus prompt na about $0.0012 for input, while 300 tokens for output na $0.0015, roughly one quarter of a cent. 1,000 runs for one month go cost under $3. The same node wey point to Opus 4.8 na about five times this amount. When you multiply that ratio by every workflow wey you build, you go see why the per-node model habit matter.
Workflow 2: scheduled RSS to structured rows
Now we go do something wey follow clock, with structured output: read RSS feed every hour, classify each item, then append rows to sheet.
- Schedule Trigger, every hour.
- RSS Read, the feed URL. E go output one item for each article.
- Basic LLM Chain, with an Anthropic Chat Model sub-node wey set to
claude-haiku-4-5, and a Structured Output Parser sub-node wey get JSON schema. - Google Sheets (or Postgres), append one row for each item.
Na the Structured Output Parser dey turn "Claude, please return JSON" from mere hope into contract: e validate the model reply against your schema, and e make the item fail clearly instead of writing bad rows. Schema fit look like this:
{
"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"]
}The chain prompt dey reference the feed item:
Classify this article for a VPS hosting audience.
Title: {{ $json.title }}
Content: {{ $json.contentSnippet }}Cost calculation dey different here: na each item dey incur cost, no be each run. Fifty articles every hour, twenty-four hours every day, na 36,000 Claude calls every month. For Haiku, e fit cost around $40–90 depending on article length. For Opus, e fit cost about five times that. Remove duplicates before the LLM node (use simple IF against links wey you don see before, or n8n's Remove Duplicates node). This go reduce the number because most hourly polls no get anything new. The cheapest token na the call wey you no make.
Workflow 3: AI Agent wey dey use tools
The first two workflows na pipelines; na you dey decide the steps. An AI Agent node turn this arrangement upside down: you give Claude one goal and tools, then e decide which tools to call, the order to call dem, and when e don finish. n8n require one chat model sub-node and at least one tool sub-node wey you attach.
One practical build na ops assistant wey dey answer “wetin dey down and why” from your monitoring:
- Chat Trigger (or webhook), na here the question go enter.
- AI Agent, with one Anthropic Chat Model sub-node set to
claude-sonnet-5. Agents dey plan and chain tool calls; Haiku fit handle simple agents wey use one tool, but Sonnet na the sensible minimum once tools plenty. - HTTP Request node wey you attach as a tool, and point am to your Uptime Kuma status API or Zabbix endpoint. Another HTTP tool fit call anything else wey get REST API.
Two settings dey do most of the work. The agent System Message define the job: “You be an ops assistant. Use the status tool to check current monitor state before you answer. Report only monitors wey dey down, with duration.” The description of each tool no be documentation for humans; na how Claude dey decide when to call the tool. “Returns current up/down state for all monitored services as JSON” go make am call the tool at the correct time; “status API” fit make am ignore or misuse the tool. When you attach the HTTP Request node as a tool, enable the Optimize Response option and select the JSON fields wey matter. Otherwise, every verbose API response go enter the model context as input tokens wey you go pay for.
Set Max Iterations for the agent to the smallest number wey works (the default na 10). This na the difference between “the agent give up after 4 tool calls” and a loop of twelve model round-trips. Also understand how billing dey work: every iteration dey send the full conversation so far again, including system message, question, and every previous tool result, as input tokens. One six-iteration agent run fit easily reach 20,000 cumulative input tokens and 2,000 output tokens. For Sonnet 5 at $2/$10, this fit cost about $0.06; call am twenty times and e don cost like one simple summarization run. If you dey add plenty tools to one agent, na that point to run MCP servers for your VPS become the cleaner architecture.
Cost guardrails, because nobody dey watch
Workflow wey nobody dey monitor needs the controls wey human for keyboard dey provide without thinking. Na four layers, starting from the cheapest.
Max Tokens for every Claude node. Na hard limit for output. Summarizer fit need 300, classifier fit need 100. This limit the expensive side of the bill (for the models wey this guide cover, $5–$50 per million output tokens versus $1–$10 for input, and output cost na five times input price for each one) and e also stop runaway execution. If prompt bug make Claude dey talk too much, e go cost 300 tokens, no be 8,000.
Model for each node. We don cover this above; between Haiku 4.5 and Opus 4.8, na five times price difference, ten times up to Fable 5, and across the current lineup, from Haiku 5.5 to Fable 5.1, e reach hundred times for prompts up to 100,000 tokens. E go take ten seconds to set am.
Set limit for loops. Use Max Iterations for agents. Set workflow timeout for the workflow settings so wedged execution go stop instead of continuing to run. Also take care with per-node Retry On Fail: na the correct tool for temporary errors, but retries dey multiply cost. Max Tries of 3 with Wait Between Tries of 5000 ms means persistent failure fit bill you up to three times for each item before e give up. Never put retry around node wey don already succeed and cost plenty.
Use error workflow as final backup. Create workflow wey start with the Error Trigger node. Make am post the failed workflow name and error to Slack, then set am as the Error Workflow for each AI workflow settings. The failure wey this one catch na the serious one: workflow wey schedule trigger dey run, e dey fail every time, every hour, for one week, and each run dey burn tokens before e stop. Add monthly spend limit for Anthropic Console, and check the Console usage page during the first few days after you activate anything wey get schedule. If you want understand exactly wetin dem dey bill you for, this token-usage guide break am down.
Wetin fit spoil, plus the messages wey you go see
The node fail immediately with "Authorization failed - please check your credentials." API return 401. The body underneath get this shape (current responses still carry a request_id field):
{"type": "error", "error": {"type": "authentication_error", "message": "invalid x-api-key"}}Key fit get pasted wrong, cut short, get whitespace for the end, or na placeholder from tutorial. Create the n8n credential again and paste the key again. If e work yesterday, check whether person revoke the key or e don reach expiration date for Console. Also check whether volume restore bring back credential wey dem encrypt with different N8N_ENCRYPTION_KEY.
Executions dey fail in bursts with a 429 rate_limit_error, with message like "Number of request tokens has exceeded your per-minute rate limit." Dem measure rate limits per minute and enforce dem with token bucket wey dey refill continuously. n8n make am very easy to trigger fifty webhook or RSS executions at the same time. Fix the structure: process items one after another with Loop Over Items instead of running dem parallel. Set Retry On Fail with Max Tries 3 and Wait Between Tries to the maximum 5000 ms. n8n no allow that field pass 5000 ms. When you need longer backoff so the bucket fit refill before retry, put a Wait node for the error path or process items one at a time. Rate-limit 429 usually get a retry-after header wey tell you how many seconds to wait. Anthropic docs talk say no be every 429 get this header. n8n fixed wait no fit read the header, so build the longer pause by yourself. One exception: 429 wey no get retry-after header and get error_code of enforced_spend_limit_reached mean say your organization don reach the monthly spend cap for its usage tier. No retry go succeed until next month or until you increase the tier.
404 not_found_error when you name your model. The message show the model ID wey you send, something like:
{"type": "error", "error": {"type": "not_found_error", "message": "model: claude-haiku-4.5"}}Dots instead of hyphens (4.5 for 4-5), wrong or invented date suffix, or retired model from old blog post fit cause am. Correct the ID against the current list. This problem dey happen to people wey type inside the model field as expression instead of choosing from the dropdown.
Claude answer question wey you no ask. No error dey anywhere and the run green. If n8n expression reference field wey no dey, like {{ $json.body.text }} when payload use message, n8n go put literal string undefined inside your prompt. Claude go still respond to prompt wey no get useful question. If the referenced node no execute at all, n8n stops with error say the expression reference a node wey "hasn't been executed yet". But missing field no show error. Before you activate am, always run once with real data and read the rendered prompt for the node's input panel. Expression editor dey preview the resolved value, and undefined dey there if you check well.
FAQ
How do I connect Claude to n8n?
Create API key for Anthropic Console for platform.claude.com, then for n8n add credential wey get type Anthropic and paste am for API Key field. Every Claude node, the Anthropic app node and the Anthropic Chat Model sub-node, dey reference that stored credential. n8n dey encrypt am with N8N_ENCRYPTION_KEY, so back up that key, otherwise your credentials go lost with the volume.
Wetin one AI workflow run dey cost?
Estimate tokens per run, then multiply am by the model per-million prices. As of October 2026, Haiku 4.5 na $1/$5 per million input/output tokens, while Sonnet 5 na $2/$10. Webhook summarization for Haiku dey cost about quarter of one cent; agent run for Sonnet with several tool calls dey come near $0.06–$0.10 because every iteration dey send the whole conversation again as input. Verify the run for Console usage page instead make you no rely on estimates.
Which Claude model I suppose use for n8n automations?
Use Haiku 4.5 for classification, extraction, summarization, and routing, especially for high-volume work where speed and price matter pass. Use Sonnet 5 for AI Agent nodes and multi-step reasoning. Use Opus 4.8 only when wrong answer go cost enough to justify the $5/$25 list price: e cost five times Haiku and two and a half times Sonnet. Anthropic newer Haiku 5.5, Sonnet 5.5 and Opus 5.5 dey do the same roles with equal or lower list prices. Set the 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?
Put guardrails in layers: set low Max Tokens for every Claude node, set Max Iterations for agents, add workflow timeout, and use conservative Retry On Fail settings so failures no multiply token spending. Then add an Error Trigger workflow wey go alert you for Slack whenever any AI workflow fail. Set monthly spend limit for Anthropic Console too; na the hard ceiling wey nothing for the VPS fit override.
AI Agent tool calls dey cost extra?
No separate tool fee dey, but tools no be free: every tool result dey go back to the model as input tokens, and every agent iteration dey send the whole conversation so far again. Chatty API response wey you pass through without filtering fit cost far more than your actual prompt. Enable Optimize Response for HTTP Request tools and return only the fields wey the agent need.