How to Connect n8n to OpenAI, Claude, and Local LLMs
By Abhishek Patoliya · 2026-08-12
An n8n workflow that calls a language model needs the same thing regardless of which provider you pick: a credential, a chat model node, and a prompt. What changes between OpenAI, Anthropic's Claude, and a self-hosted model through Ollama is the connection details and a few behavioral quirks — not the shape of the workflow around it. Building that connection cleanly, so switching providers later doesn't mean rebuilding the workflow, is the actual skill here.
OpenAI
Add an OpenAI credential in n8n with your API key, then use it in either a dedicated OpenAI node or as the model input to an AI Agent / Basic LLM Chain node. Set the model name explicitly (rather than leaving a default) so a provider-side model deprecation doesn't silently change which model your workflow is actually calling. Rate limits are per-organization by default — a workflow processing a batch of records in a tight loop can hit them faster than expected, which is worth testing before relying on it for anything time-sensitive.
Anthropic's Claude
The setup mirrors OpenAI's: an Anthropic credential with your API key, connected to a chat model node. The practical difference worth knowing is in how each provider's models handle structured tool calls and long system prompts — if you're building an AI Agent node with several tools, it's worth testing tool-selection accuracy on your specific tool set with whichever model you choose, rather than assuming behavior transfers identically from one provider to another.
Local Models via Ollama
Ollama runs open models (Llama, Mistral, and others) on your own hardware, and n8n connects to it as just another model endpoint — no external API key required, since the model runs locally or on a server you control. This removes per-token API cost and keeps data from leaving your infrastructure, which matters for high-volume, lower-stakes tasks like basic classification or simple extraction. It's a weaker fit for complex reasoning or precise instruction-following, where most current local models still trail the larger hosted models — test against your specific task before committing to it for anything accuracy-sensitive.
Building a Workflow That Doesn't Lock You to One Provider
- Keep the model connection isolated. Use one dedicated chat model node (or a small number of them) that the rest of the workflow calls into, rather than scattering provider-specific API calls across multiple Code nodes.
- Externalize the prompt. Store prompts as a variable or a separate node output rather than hardcoding them inline everywhere they're used, so updating a prompt for a new model doesn't mean hunting through the whole workflow.
- Validate the output shape, not just eyeball it. If a step expects structured JSON back, check that a new provider still returns it in the same shape before trusting it in production — some models are more consistent about following strict formatting instructions than others.
A Practical Pattern: Cheap Model for Volume, Strong Model for Judgment
A common cost-saving pattern once you have multiple providers connected: route high-volume, low-complexity steps (initial ticket classification, simple field extraction) to a smaller, cheaper model or a local one via Ollama, and reserve a stronger hosted model for the step that actually needs deeper reasoning — drafting a nuanced reply, or making a judgment call with real consequences. This can meaningfully cut per-execution cost on a workflow that calls a model at every step, without weakening the step that actually needs the stronger model's reasoning.
Common Pitfalls
- Assuming a prompt performs identically across providers. It usually gets you most of the way there, but tool-calling reliability and instruction-following strictness genuinely differ by model — always test after a switch.
- Hardcoding model names without a fallback. A model version can be deprecated by the provider; pin a specific version where the provider supports it, and know what you'll switch to if it's retired.
- Sending more data to a hosted API than the task needs. If a step doesn't need the full customer record to do its job, don't pass the full record — smaller payloads are cheaper, faster, and lower-risk from a data-handling standpoint.
Handling Rate Limits and Timeouts Consistently Across Providers
Each provider enforces rate limits differently — requests per minute, tokens per minute, or both, with different response codes and headers signaling it. A workflow built for one provider's error shape and swapped to another provider without adjustment often fails to recognize a rate limit as a rate limit at all, treating it as a generic error instead of something to back off and retry.
Normalize provider responses to a common shape immediately after the API call, before any downstream logic has to know which provider produced them:
// n8n Code node — normalizing rate-limit signals across providers
const status = $json.statusCode;
const provider = $json.provider; // 'openai' | 'anthropic' | 'ollama'
const isRateLimited =
status === 429 ||
(provider === 'anthropic' && $json.body?.error?.type === 'rate_limit_error');
const retryAfter = $json.headers?.['retry-after']
? parseInt($json.headers['retry-after'], 10)
: 5; // sensible default if the provider doesn't send one
return [{ json: { isRateLimited, retryAfter, provider } }];
This is also exactly the layer where the fallback-chain pattern covered elsewhere on this blog plugs in — once rate limits and timeouts are normalized to one shape, deciding "retry this provider" versus "switch to the backup provider" becomes a single piece of logic instead of provider-specific branches scattered through the workflow.
Local models via Ollama are worth a specific mention here since they don't rate-limit the same way — the constraint is local hardware throughput, not an API quota. A workflow mixing a local model with hosted providers needs to treat "the local instance is currently overloaded and responding slowly" as its own condition to detect and handle, separate from the rate-limit and outage handling built for the hosted providers, since a slow local response looks nothing like a 429 or a connection timeout.
A simple, separate timeout tuned specifically for the local model — shorter than what you'd allow a hosted provider, since local hardware limits are more predictable — catches this case cleanly without needing the same rate-limit detection logic built for the hosted side.
Document which timeout applies to which provider directly in the workflow, since this is exactly the kind of detail that's easy to forget six months later when debugging a slow response.
A one-line comment on the relevant node, naming the provider and the reasoning behind its specific timeout value, is enough to save that future debugging session real time.
Getting Started
Pick one provider to start, build the workflow with the model connection cleanly isolated, and treat adding a second provider later as a validation exercise rather than a rebuild. The workflow logic around the model call is almost always more durable than the specific model you started with.
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.