Connecting Claude or GPT to n8n: the complete guide
Published 5 March 2026 · 3 min read
Since n8n shipped its LangChain-based AI nodes, plugging a large language model into a workflow takes about two minutes — once you know which of the half-dozen AI nodes to use. This guide covers the practical path: credentials, the two model nodes, when to use a chain versus an agent, and what it costs.
Step 1: create the credentials
OpenAI: generate a key at platform.openai.com → API keys. In n8n: Credentials → Add credential → OpenAI API, paste the key. Note that API usage is billed separately from ChatGPT subscriptions — you need billing enabled on the platform account.
Anthropic (Claude): create a key in the Anthropic console. In n8n: Credentials → Add credential → Anthropic API.
Two hygiene rules: create one credential per environment (dev/prod) so you can rotate independently, and never hardcode keys in HTTP Request nodes when a dedicated credential type exists.
Step 2: understand the node model
n8n's AI nodes follow a root node + sub-nodes pattern. The root node (an LLM chain, an agent, a RAG chain) carries the logic; the model is a sub-node attached underneath via a special ai_languageModel connection:
OpenAI Chat Model(lmChatOpenAi) — GPT modelsAnthropic Chat Model(lmChatAnthropic) — Claude models
This separation is the underrated superpower: swapping GPT for Claude in an existing workflow means replacing one sub-node, without touching prompts or wiring. All FlowKit workflows use this pattern, which is why the model is always a two-click swap.
Step 3: chain or agent?
Basic LLM Chain (chainLlm) — one prompt in, one completion out. Deterministic flow: the model can't decide to do anything else. Use it for classification, summarization, extraction, drafting. Paired with a Structured Output Parser, it returns strict JSON your downstream nodes can rely on — the pattern behind our email triage template in the AI Inbox Pack.
AI Agent (agent) — the model receives tools (HTTP calls, workflows, vector stores) and decides when to call them, with optional session memory. Use it when the path genuinely depends on the conversation: guided questionnaires, assistants that look things up. Agents are more powerful and less predictable; give them narrow tools and explicit protocols.
Retrieval Q&A Chain (chainRetrievalQa) — the RAG middle ground: retrieval is systematic, then a single completion. Predictable like a chain, document-grounded like an assistant.
Rule of thumb: start with a chain; move to an agent only when you need decisions, not just generation.
Choosing the model
For most business automations, small models are the right default:
- gpt-4o-mini: excellent cost/quality for classification, scoring, digests. Our default in most workflows.
- Claude Sonnet: noticeably strong at nuanced writing (customer replies, reports) and reliable tool-calling.
- Reserve the large flagship models for long, high-stakes documents — an audit report read by a client justifies it; sorting newsletters doesn't.
What it costs
Order-of-magnitude API costs observed for typical FlowKit-style usage, at the time of writing:
| Usage | Volume | Monthly cost |
|---|---|---|
| Email classification (mini model) | 100 emails/day | €0.50–2 |
| Daily digest | 1 call/day | < €0.20 |
| RAG chatbot | 50 questions/day | €1–4 |
| Audit report (Claude) | 20 reports/month | €1–3 |
The pattern is consistent: LLM cost is a rounding error next to the time saved, provided you truncate inputs (never send a 200-page PDF to a classifier) and keep small models on high-frequency tasks.
Debugging tips
- Test the model sub-node in isolation with pinned data before wiring the full flow.
- A
429error means rate limits or missing billing — check the provider dashboard first. - If structured output fails intermittently, tighten the JSON schema description; enums beat free text.
- Log prompts and outputs to a database table during the first weeks — it's the fastest way to improve prompts with real data. Our getting started with n8n's AI nodes guide walks through a first complete build.