← Back to Home
Lesson 3
Connecting n8n to Claude API
Getting Your Claude API Key
- Go to console.anthropic.com
- Sign up / log in
- Navigate to "API Keys"
- 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:
- Install the n8n AI module (built-in since v1.0)
- Add AI Agent or Basic LLM Node
- Select "Anthropic" as provider
- Enter your API key
Configuration
- Model: claude-sonnet-4-5
- Temperature: 0.7 (creative) or 0.1 (precise)
- Max Tokens: 2048
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
- Use system prompts — Set behavior context once
- Chunk large data — Claude has context limits (200K for Sonnet)
- Set temperature — 0.1-0.3 for tasks, 0.7+ for creative
- Cache common prompts — Save as workflow templates
Security Note
- Never commit API keys to git
- Use n8n's Credentials system
- Rotate keys periodically
- Consider IP allowlisting in Anthropic console
Next: Lesson 4: Claude Code (CLI) →