← Back to Home Lesson 3

Connecting n8n to Claude API

Getting Your Claude API Key

  1. Go to console.anthropic.com
  2. Sign up / log in
  3. Navigate to "API Keys"
  4. Create a new key (save it securely!)
Cost: ~$3-15/M1 tokens depending on model

The HTTP Request Method

Since n8n doesn't have a native Claude node yet, we use the HTTP Request node:

POST https://api.anthropic.com/v1/messages
Headers:
  x-api-key: YOUR_API_KEY
  anthropic-version: 2023-06-01
  content-type: application/json
Body:
{
  "model": "claude-sonnet-4-5",
  "max_tokens": 1024,
  "messages": [
    {"role": "user", "content": "{{ $json.prompt }}"}
  ]
}

n8n AI Module (Easier Way!)

n8n has an AI module with LLM nodes:

  1. Install the n8n AI module (built-in since v1.0)
  2. Add AI Agent or Basic LLM Node
  3. Select "Anthropic" as provider
  4. Enter your API key

Configuration

Practical Example: Email Summarizer

[Webhook Trigger] 
    → [HTTP Request (Get Email)] 
    → [LLM Node (Claude)] 
    → [Slack Notification]

Prompts you can use:

Summarize this email in 3 bullet points. Identify if it requires urgent action.

Handling Responses

Claude returns structured JSON. In n8n:

{{ $json.content[0].text }}

Or use Edit Fields node to parse and transform.

Tips for Claude + n8n

  1. Use system prompts — Set behavior context once
  2. Chunk large data — Claude has context limits (200K for Sonnet)
  3. Set temperature — 0.1-0.3 for tasks, 0.7+ for creative
  4. Cache common prompts — Save as workflow templates

Security Note

Next: Lesson 4: Claude Code (CLI) →