๐ŸŽ“Iris Courses
โ† AI Automation Mastery
Day 15 of 21

Building with the Claude API

Claude API Architecture for Automation

The Claude API is the most capable AI integration available for automation workflows. Understanding how to structure API calls, manage costs, and handle edge cases will determine whether your AI-powered automations are robust or brittle. Core API concepts: Messages API is the primary interface โ€” you send a conversation (list of messages with roles) and receive a completion. The system prompt is where you define Claude's role, output format requirements, and any constraints. The model selection determines capability vs cost vs speed tradeoffs. Model selection guide: claude-haiku-4-5 (fastest, cheapest, good for classification and simple extraction), claude-sonnet-4-5 (balanced, excellent for most automation tasks), claude-opus-4-5 (most capable, highest cost, reserve for complex reasoning). For most automation tasks, start with claude-haiku-4-5 and only upgrade if you see quality issues. Token management: each API call uses input tokens (your prompt + conversation history) and output tokens (Claude's response). Costs scale with tokens. For automation at volume, aggressive prompt engineering saves real money. A 500-token prompt vs a 2000-token prompt is a 4x cost difference at scale. Compress your prompts โ€” every word costs money. Streaming vs non-streaming: for user-facing applications, stream the response so users see output as it generates. For automation workflows, non-streaming is simpler โ€” wait for the complete response before proceeding. N8n's HTTP Request node handles non-streaming natively.

Prompt Engineering for Reliable Automation

Prompt engineering for automation is different from prompt engineering for interactive use. In automation, consistency and parsability matter more than creativity. Here are the patterns that produce reliable results. Structured output enforcement: put the output format requirement at both the beginning and end of your prompt. Models are more likely to follow the format when it's the first and last thing they see. Few-shot examples dramatically improve consistency. Provide 2-3 examples of input/output pairs in your prompt. Models learn the exact format and edge case handling from examples much better than from instructions alone. ``` You are a lead qualifier. Given a company description, return ONLY JSON: {"tier": "A"|"B"|"C", "reason": "one sentence", "next_action": "call"|"email"|"nurture"} Examples: Input: "Enterprise SaaS company, 200 employees, Series B" Output: {"tier": "A", "reason": "Enterprise size and funded signals high deal value", "next_action": "call"} Input: "Freelancer looking for project management tool" Output: {"tier": "C", "reason": "Individual user, low deal value potential", "next_action": "nurture"} Now classify: {{$json.company_description}} ``` Temperature control: for deterministic tasks (classification, extraction, formatting), set temperature to 0. For creative tasks (email writing, content generation), use 0.7-1.0. In the Claude API, pass `temperature: 0` in your request. Always log your prompts and responses in production. Store the input, prompt version, response, and timestamp. This enables debugging when outputs are wrong and lets you measure quality improvements when you update prompts.

โšก Today's Action

Build a Claude-powered email classifier that reads your Gmail inbox, classifies each email into 5 categories (urgent/to-do/FYI/newsletter/spam), and applies the corresponding Gmail label automatically. Run it on demand first, then schedule it to run every 30 minutes.

๐Ÿ’ก Pro Tip

Version your prompts like you version code. Store them in a database or config file with a version number. When you update a prompt, increment the version and log which version produced each output. This makes A/B testing prompt changes possible.