Skip to main content
Back to blog

Integrate Claude into n8n: real AI-powered automations

Ray MartínRay Martín
11 min read
Integrate Claude into n8n: real AI-powered automations

Automating tasks is valuable. Automating judgment is transformative. n8n already lets you chain APIs, send emails, and move data between systems without writing a single line of code. But when you connect n8n with Claude — Anthropic's language model — you make the leap from "this flow executes predefined actions" to "this flow reasons, classifies, summarizes, and decides." In this post you'll see how to make that connection with the HTTP Request node, how to enforce structured JSON output so your flows can branch on it, and two real-world use cases ready to adapt.

Why Claude in your workflows?

Modern AI models are not just text generators; they are reasoning engines you can embed at any point in a workflow. Claude in particular stands out for three practical reasons in automations:

  • Complex instruction following: You can give it detailed context — a category system, a company policy, a brand voice — and it will apply that context consistently across thousands of executions.
  • Structured output: Using tool use (Anthropic's API tool-calling technique) you can make Claude return JSON with an exact schema you define. This eliminates fragile free-text parsing.
  • Multilingual and context-aware: Claude understands and generates Spanish, English, and dozens of other languages. If your company receives emails in multiple languages, Claude classifies them equally well without extra configuration.

Common use cases in n8n flows: classifying support tickets, summarizing long emails, extracting structured data from unstructured text, drafting replies, validating content before publishing, translating with brand context.

Calling the Claude API with the HTTP node

Claude does not have a native node in n8n (yet), but the HTTP Request node is all you need. The Anthropic API follows the standard REST convention: one endpoint, a POST method, authentication headers, and a JSON body.

HTTP Request node configuration in n8n:

  • Method: POST
  • URL: https://api.anthropic.com/v1/messages
  • Authentication: Generic Credential Type → Header Auth → Name: x-api-key, Value: your ANTHROPIC_API_KEY (store it as a credential in n8n, never hardcoded).
  • Additional headers: anthropic-version: 2023-06-01 and content-type: application/json.
  • Body: JSON, with the following object.

The request body looks like this:

json
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "system": "You are a support assistant that classifies tickets. Always respond in English.",
  "messages": [
    {
      "role": "user",
      "content": "Ticket received: The customer cannot log in to their account since yesterday. They tried resetting the password but the email is not arriving."
    }
  ]
}

The curl equivalent (useful for testing outside of n8n):

bash
curl -X POST https://api.anthropic.com/v1/messages   -H "x-api-key: $ANTHROPIC_API_KEY"   -H "anthropic-version: 2023-06-01"   -H "content-type: application/json"   -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "system": "You are a support assistant that classifies tickets. Always respond in English.",
    "messages": [
      {
        "role": "user",
        "content": "The customer cannot log in to their account since yesterday."
      }
    ]
  }'

The API response has this structure:

json
{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "This ticket corresponds to an account access issue..."
    }
  ],
  "model": "claude-sonnet-4-6",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 67,
    "output_tokens": 89
  }
}

In n8n, the response text is at $json.content[0].text. You can access it directly in the next node with an expression, or parse it with the Code node.

Enforcing structured output (JSON)

Free text is hard to process automatically. If you want n8n's Switch node to route by category, you need Claude to return an exact category field, not a paragraph that mentions it. The robust way to achieve this is using tool use.

With tool use, you tell Claude: "you have this function available with this JSON schema; use it to return the result." The model then returns its answer within the schema you defined — guaranteed, without format hallucinations.

Request body with tool use:

json
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "tools": [
    {
      "name": "classify_ticket",
      "description": "Classifies a support ticket and extracts its priority.",
      "input_schema": {
        "type": "object",
        "properties": {
          "category": {
            "type": "string",
            "enum": ["access", "billing", "bug", "inquiry", "other"],
            "description": "Main category of the ticket"
          },
          "priority": {
            "type": "string",
            "enum": ["high", "medium", "low"],
            "description": "Estimated priority"
          },
          "summary": {
            "type": "string",
            "description": "One-sentence summary of the problem"
          }
        },
        "required": ["category", "priority", "summary"]
      }
    }
  ],
  "tool_choice": { "type": "tool", "name": "classify_ticket" },
  "messages": [
    {
      "role": "user",
      "content": "Ticket: The customer cannot log in to their account since yesterday. They tried resetting the password but the email is not arriving."
    }
  ]
}

When you use tool_choice: { "type": "tool", "name": "..." }, you force Claude to use that tool. The response does not come in content[0].text but in content[0].input:

json
{
  "content": [
    {
      "type": "tool_use",
      "id": "toolu_01A09q90qw90lq917835lq9",
      "name": "classify_ticket",
      "input": {
        "category": "access",
        "priority": "high",
        "summary": "The customer cannot log in and is not receiving the password reset email."
      }
    }
  ]
}

In n8n, you parse this with a Code node (JavaScript):

typescript
// Code node (JavaScript) after the HTTP Request
// $json is the complete response from the Claude API
const toolResult = $json.content[0].input;

return [{
  json: {
    category: toolResult.category,
    priority: toolResult.priority,
    summary: toolResult.summary
  }
}];

Now you have clean fields that the Switch node can read directly.

Real use case: classify and route tickets

Imagine a support system where tickets arrive by email (Gmail node) or webhook. The complete flow has five nodes:

  1. Trigger: Gmail node (new email in the support inbox) or Webhook (call from your app).
  2. HTTP Request → Claude: You send the email subject and body. Claude classifies category, priority, and generates a one-sentence summary using tool use.
  3. Code: You extract content[0].input and expose it as flat fields on the item.
  4. Switch: Routes by category. Branch "access" → create Jira ticket + notify Slack #support-access. Branch "billing" → create ClickUp task + notify #support-billing. Branch "bug" → open GitHub issue + priority from the priority field. Default branch → create generic Notion record.
  5. Send Email / Slack: Confirms receipt to the customer with the summary Claude generated.

The power here is that the Switch operates on guaranteed structured data. No fragile regular expressions, no conditional logic over free text. Claude decides; your nodes act.

For the priority field you can add a second branch in the Switch or a subsequent IF node: if priority === "high" send a direct message to the on-call person in addition to creating the ticket.

Summarize and auto-reply

Another very useful pattern is the summarize-and-draft loop with human-in-the-loop review. The flow:

  1. Trigger: New email in the inbox (Gmail, Outlook…).
  2. IF: Filter emails from existing customers (by domain, label, or CRM field).
  3. HTTP Request → Claude: You ask for two things in a single prompt — an executive summary in 2–3 sentences and a draft reply in your company's tone. The system prompt defines the tone; the user message includes the full email.
  4. Set: Maps the result to summary and draft_reply fields.
  5. Wait for Approval: Use n8n's Wait node (mode "On webhook call") to pause the flow until a human approves. You send the draft to Slack with "Approve" / "Edit" / "Reject" buttons. When the agent clicks "Approve," the webhook wakes the flow and it continues.
  6. Gmail: Send Email: Sends the approved draft as a reply to the original thread.

The Wait node is key for flows that should not run 100% unsupervised. n8n stores the flow state until the approval arrives — it could be minutes, hours, or days. You only pay for actual execution time, not wait time.

A more advanced variant: if Claude estimates high confidence in the response (using a confidence field in the tool use schema) and the email is a routine "inquiry" category, the flow skips human approval and replies directly. If confidence is low or the category is "complaint," it always goes through a human.

Costs, limits, and best practices

Integrating an LLM into your flows adds a per-token cost that you should model before activating the flow in production.

Claude Sonnet cost structure: Claude models are priced per million input and output tokens. For short classification flows (system prompt ~200 tokens + ticket ~100 tokens = ~300 input tokens; structured response ~50 tokens), the cost per execution is fractions of a cent. For document summarization flows the cost scales proportionally. Always check the official Anthropic pricing page for current values — prices are updated periodically.

Rate limits: The Anthropic API has per-minute limits (requests and tokens). If your flow processes spikes of many items in parallel, enable the Split In Batches node in n8n to process in batches of 5–10 items and add a Wait node between batches. Exact limits depend on your usage tier; review them in the Anthropic console.

Error handling: The API can return 429 errors (rate limit) or 5xx errors (temporary server errors). Configure the HTTP Request node with automatic retries: in n8n you can enable "Retry On Fail" with a number of attempts and a wait interval. For persistent errors, chain the error output to a node that notifies via Slack and logs to a database.

Privacy and PII: Do not send unnecessary personal data. If you only need to classify the nature of an email, extract the subject and body without the sender's full name or email. If you must include them (to generate a personalized reply), ensure your agreement with Anthropic covers processing your customers' data under your jurisdiction. Anthropic does not use API data to train models by default.

Versioned prompts: Treat your system prompts like code. Store them in n8n environment variables or in a Set node at the start of the flow (easy to update without touching the logic). When you change a prompt, test with a representative set of cases before activating it in production.

Prompt caching: The Claude API supports prompt caching. If your system prompt is long and static (company policy, category catalog), you can cache it to reduce input token costs on repeated executions. Enable it by adding "cache_control": { "type": "ephemeral" } to the system block in the request.

The complete guide

This post covers the fundamentals for connecting Claude to n8n and building flows with real judgment. The PDF guide dives deep into everything you need to take this to production and scale:

  • System prompt templates by use case (support, sales, moderation, data extraction) with tone, format, and edge-case handling instructions.
  • Tool use with advanced JSON Schema: nested arrays, optional fields, conditional enums, and how to design schemas that minimize parsing errors.
  • Error handling and retries: complete strategy with exponential backoff, dead-letter queue, and automatic alerts when a flow fails repeatedly.
  • 5 ready-to-import AI flows: multi-category ticket classifier, email summarizer with human approval, invoice PDF data extractor, social media reply generator, and UGC content moderator.
  • Cost spreadsheet: token calculator to estimate the monthly cost of each flow based on your volume, with a Claude model comparison and selection strategy (when to use Haiku vs. Sonnet).
Share:

Related articles