Claude API + n8n Self-Hosted Automation Guide
If you're running a self-hosted n8n instance and want to wire Claude into your workflows, the short answer is: there's no native Claude node in n8n, but you don't need one. You can call Claude from any n8n workflow using the HTTP Request node, pointed at either Anthropic's API directly or a gateway like SubToAPI. This gives you full access to Claude's text generation, tool use, and structured output inside triggers, loops, and conditional branches — without writing a custom n8n node or maintaining a separate microservice.
This matters because self-hosted n8n is popular precisely for automations that touch internal systems: databases, internal APIs, file systems, cron jobs tied to business logic. Teams running n8n on their own infrastructure (Docker, a VPS, Kubernetes) usually also want their AI calls to go through a controlled, auditable path rather than scattering raw API keys across workflow JSON files. Below is how to set this up properly, including the parts that trip people up: authentication, timeouts, and error handling inside n8n's execution model.
Why HTTP Request Node Instead of a Custom Node
n8n has a large community node ecosystem, but building and maintaining a custom node for Claude adds overhead: you'd need to handle n8n's node versioning, publish updates when Anthropic changes its API, and deal with credential storage separately. The HTTP Request node avoids all of that. It's part of core n8n, works identically on self-hosted and cloud instances, and gives you raw control over headers, body, and response parsing — which is exactly what you want for prompt engineering that changes often.
The tradeoff is you write the request body yourself instead of filling in a form. In practice this is a few lines of JSON that you template with n8n expressions ({{ $json.text }}), so it's not a real cost.
Setting Up the HTTP Request Node
In your n8n workflow, add an HTTP Request node after whatever trigger feeds it (webhook, schedule, database watcher, etc.):
- Method: POST
- URL:
https://api.subtoapi.app/v1/messages(or Anthropic's endpoint if calling directly) - Authentication: Generic Credential Type → Header Auth
- Header name:
Authorization - Header value:
Bearer {{your API key}} - Body content type: JSON
Body example, using n8n expressions to pull data from a previous node:
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Summarize this ticket in two sentences: {{ $json.ticketBody }}"
}
]
}
Store the API key as an n8n credential rather than pasting it into the node — this keeps it out of exported workflow JSON and version control, which matters a lot if your n8n workflows live in a git repo.
A Practical Workflow Example
A common self-hosted n8n pattern: a webhook receives a support ticket, Claude classifies and drafts a response, then the result is written back to a database or posted to Slack for review.
- Webhook node — receives the incoming ticket payload.
- HTTP Request node — calls Claude with the ticket text, asking for a JSON classification (
category,priority,draft_reply). - Code node — parses Claude's text response into structured fields, since Claude returns content as text even when you ask for JSON.
- IF node — branches on priority: high-priority tickets go to a Slack notification, low-priority ones get auto-filed.
- Database node (Postgres/MySQL) — writes the final record.
For step 3, if you need reliably structured output, use Claude's tool use feature instead of asking for JSON in plain text. Define a tool schema with the fields you want, set tool_choice to force that tool, and parse input from the tool call in the response — this is far more reliable inside an automation pipeline than regex-parsing free text.
Handling Timeouts and Retries in n8n
Self-hosted n8n gives you control over execution timeouts, which matters for longer Claude generations. Two settings to check:
- Workflow timeout (Settings → Workflow Settings) — make sure it's longer than your expected Claude response time, especially for longer
max_tokensvalues. - HTTP Request node retry options — enable "Retry On Fail" with a short wait time to handle transient 429s or network blips without failing the whole execution.
For workflows that need to process many items (batch summarization, bulk tagging), use n8n's Split in Batches node combined with a short delay between HTTP Request calls to avoid hitting rate limits. If you're on SubToAPI, usage and rate-limit headroom are visible in the dashboard, which makes it easier to size batch delays correctly instead of guessing.
Why Route Through an API Gateway Instead of Direct Anthropic Keys
If multiple n8n workflows (or multiple team members building workflows) call Claude, raw Anthropic keys get awkward fast: no per-workflow usage visibility, no easy key rotation, and if someone leaks a workflow export, the key goes with it. Routing n8n's HTTP Request nodes through SubToAPI gives each workflow or environment its own sub_live_... key, so you can see exactly which automation is consuming tokens and revoke one key without touching the others. Setup is identical to the example above — same endpoint shape, same JSON body — see the quickstart for the full request format. Plans start at Solo €9/month with a free trial at signup, and team usage across multiple workflows is covered under the Team plan at pricing.
Streaming in n8n Workflows
Claude supports streaming responses, but n8n's HTTP Request node is built around request/response, not SSE consumption. For automation use cases this is rarely a limitation — workflows process complete outputs, not live-typed text — so the non-streaming /v1/messages call is the right fit for nearly all n8n automations. If you need streaming output surfaced somewhere (like a chat UI), that's better handled in a dedicated frontend service rather than inside n8n itself.
Questions
Does n8n have a built-in Claude node? No. There's no official Claude/Anthropic node in n8n as of now. Use the core HTTP Request node with header authentication — it covers the full API surface including tool use.
Can self-hosted n8n call Claude without exposing API keys in workflow exports? Yes, if you store the key as an n8n credential (Header Auth type) rather than hardcoding it in the node's JSON body. Credentials are stored separately and excluded from workflow exports by default.
Is it better to call Anthropic directly or through a gateway like SubToAPI from n8n? Calling Anthropic directly works fine for a single workflow. A gateway becomes useful once you have multiple workflows or team members, since it gives per-workflow keys, usage tracking, and easier revocation — see /docs for setup details.