How to Connect n8n to Anthropic Claude: Build Smarter AI Workflows (2025)

Claude is Anthropic's family of large language models, and it is one of the most capable engines you can plug into an n8n automation for reasoning, classification, and long-form writing. This guide shows you exactly how to connect n8n to Anthropic Claude — getting an API key, wiring Claude in through both the HTTP Request node and n8n's native AI nodes, choosing between Opus, Sonnet, and Haiku, and building a real workflow that classifies incoming messages and drafts replies. It is written for people who run automations to get work done, not to admire the plumbing.

Why use Claude inside n8n

n8n moves data between apps; Claude decides what that data means. Together they let you automate the judgment-heavy steps you used to do by hand: reading a support ticket and routing it, summarizing a long PDF into three bullet points, extracting structured fields from messy text, or drafting a first-pass reply in your tone of voice. Because n8n runs on your own schedule and triggers, you can drop Claude into a pipeline that already knows about your inbox, your CRM, and your database — no glue code, no server to babysit.

Claude is a strong fit for these tasks specifically because it follows instructions closely and handles large inputs (its current models accept very large context windows), so you can feed it an entire email thread or document and get a coherent answer back in one call.

Step 1: Get an Anthropic API key

Everything starts with a key. Head to the Anthropic Console (console.anthropic.com), sign in, and open Settings → API Keys. Click Create Key, give it a name you will recognize later (for example n8n-production), and copy the value immediately — the console shows the full key only once.

  • Add billing credit. API access is pay-as-you-go and separate from any Claude.ai chat subscription. Add a small amount of credit under Billing or requests will fail.
  • Store it in n8n as a credential, never pasted into a node body. In n8n, go to Credentials → New and either pick the built-in Anthropic API credential type or create a Header Auth credential if you are using the raw HTTP approach.

Step 2 (easy path): the native Anthropic Chat Model node

The fastest way to connect n8n to Claude is n8n's built-in LangChain-based AI nodes. You do not call the API directly — you attach a model node to an agent or chain node.

  1. Add an AI Agent node (or a Basic LLM Chain node if you just want a single prompt-in, text-out step).
  2. On its Chat Model connector, add the Anthropic Chat Model node.
  3. Select your Anthropic API credential and pick a model from the dropdown (see the model section below).
  4. Type your prompt into the agent or chain, referencing incoming data with expressions like {{ $json.body }}.

This path handles authentication, retries, and message formatting for you, and it plugs straight into n8n's tools and memory features. For most workflows, this is the node you want.

Step 3 (control path): the HTTP Request node

When you need a parameter the native node does not expose — a specific system prompt structure, custom max_tokens, or a newer model string before it appears in the dropdown — call Claude's Messages API directly with an HTTP Request node.

  • Method: POST
  • URL: https://api.anthropic.com/v1/messages
  • Authentication: your Header Auth credential (or set headers manually).
  • Headers: x-api-key = your key, anthropic-version = 2023-06-01, and content-type = application/json.
  • Body (JSON):

{ "model": "claude-sonnet-5", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Summarize this ticket in one sentence: {{ $json.body }}" } ] }

Three fields are always required: model, max_tokens, and messages. The response comes back with the generated text under content[0].text, which you reference downstream as {{ $json.content[0].text }}. An optional top-level system field lets you set persistent instructions ("You are a support agent for Acme; reply in Portuguese") separately from the user turn.

Skip the build — grab the ready-to-import template

Route each task to the cheapest capable model automatically — Haiku for simple jobs, Opus for hard ones — and cut your AI bill up to 60%.

Get the LLM Router template →

Choosing a model: Opus, Sonnet, or Haiku

Anthropic ships Claude in three tiers, and picking the right one is the single biggest lever on cost and speed. They share the same API — you change one string.

  • Haiku (e.g. claude-haiku-4-5) — the fastest and cheapest tier. Use it for high-volume, low-judgment work: classification, tagging, short extractions, yes/no routing.
  • Sonnet (e.g. claude-sonnet-5) — the balanced default. Near the top tier's quality on coding and reasoning at a lower price. Good for drafting replies, summarizing, and most production workloads.
  • Opus (e.g. claude-opus-4-8) — the most capable tier for hard, long-horizon reasoning. Reserve it for the tasks that genuinely need it, because it is the priciest per token.

The trap most teams fall into is running everything on the top model. A ticket that just needs a category does not need Opus — Haiku answers it for a fraction of the cost. Matching each task to the smallest model that still does the job well is where the real savings live.

A concrete workflow: classify, then draft

Here is a two-stage pattern that pays for itself in support and sales inboxes:

  1. Trigger. A Gmail or webhook node fires when a new message arrives.
  2. Classify (Haiku). An HTTP Request or Anthropic node sends the message to Haiku with a prompt like: "Classify this message as one of: billing, technical, sales, spam. Reply with only the label." Cheap and instant.
  3. Route. A Switch node branches on that label — spam gets archived, billing goes to finance, technical continues.
  4. Draft (Sonnet). For the branches that need a human-quality reply, a second call to Sonnet takes the original message plus a system prompt describing your tone and policies, and returns a draft.
  5. Deliver. The draft lands in a Slack channel or a Gmail draft for a human to approve and send.

Notice the model split: the cheap model does the triage on every message; the more capable model only runs on the subset that reaches the drafting stage. That is exactly the kind of routing that keeps AI costs sane at volume.

Cost and latency tips

  • Cap max_tokens to what you need. You are billed on output. A one-line classifier does not need 1024 tokens — set it to 20 and responses return faster too.
  • Push instructions into system, not every user message. It keeps prompts clean and, with prompt caching, repeated context gets cheaper on follow-up calls.
  • Batch where you can. One call that classifies five items beats five separate calls for both latency and overhead.
  • Route by difficulty. Send easy tasks to Haiku and hard ones to Opus rather than sending everything to one model.

Common errors and how to fix them

  • 401 Unauthorized. The API key is missing, wrong, or malformed. Check that x-api-key holds the actual key (not a Bearer token) and that the credential is attached to the node.
  • 400 — missing max_tokens or bad model. Both max_tokens and a valid model string are required. A typo in the model ID (or a retired model) returns a 404/400 — copy the exact string from the console.
  • 429 Rate limit. Too many requests or tokens per minute. Add a Wait node or enable retry-on-fail with backoff in the HTTP node; the native node retries for you.
  • Truncated output. If a reply cuts off mid-sentence, you hit the max_tokens ceiling — raise it. The response's stop_reason tells you whether it ended naturally or was capped.
  • Empty or refused response. Check stop_reason for refusal; rephrase the prompt or add a clearer system instruction.

With the key stored, the node wired, and the right model chosen per task, Claude becomes just another reliable step in your n8n canvas — one that reads, decides, and writes.

Ready to automate?

Once Claude is running inside n8n, the next win is making sure every call hits the cheapest model that can still do the job — Haiku for triage, Sonnet for drafting, Opus only when it earns it. The LLM Router template wires that decision logic in for you as a ready-to-import n8n workflow, so you get the cost savings without building the routing by hand. Import it, point it at your Anthropic key, and start cutting your AI bill today.

Ready to automate? Get this template on Gumroad →