The Claude API is the door to automation: automatic reports, email processing, moderation, content generation at scale. This guide takes you from zero to your first working automation.
Advertisement
Getting started
You need a console.anthropic.com account and an API key. Install the official SDK:
# Python
pip install anthropic
# Node.js
npm install @anthropic-ai/sdk
Your first call
from anthropic import Anthropic
client = Anthropic(api_key="your-key")
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Summarize in 3 bullets: [text]"}]
)
print(message.content[0].text)
Pattern 1: batch processing
import csv
from anthropic import Anthropic
client = Anthropic()
with open("emails.csv") as f:
for row in csv.DictReader(f):
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=200,
messages=[{"role": "user", "content": f"Classify: {row['body']}"}]
)
print(row['id'], response.content[0].text)
Pattern 2: agent with tool use
tools = [{
"name": "get_weather",
"description": "Returns current weather for a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}]
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in Miami?"}]
)
Pattern 3: streaming for fast UX
with client.messages.stream(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "..."}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
Pattern 4: prompt caching
messages = [{
"role": "user",
"content": [
{"type": "text", "text": long_manual, "cache_control": {"type": "ephemeral"}},
{"type": "text", "text": user_question}
]
}]
Advertisement
Pattern 5: webhooks
Receive external events (new email, form, ticket) and respond with Claude automatically. Combine API with Zapier/Make, AWS Lambda, or n8n.
Typical mistakes to avoid
- API key on frontend: NEVER. Only from backend.
- No retry or backoff.
- Too low max_tokens.
- No logging.
Cost and monitoring
Set budgets in Anthropic console. Log tokens per request. Use Haiku for tasks not needing Sonnet.
Conclusion
Claude API is the door to real automation. Start small: a script processing 50 items automatically gives you an idea of the power. Scale from there with confidence.