Build Your First AI Automation With Python, Step by Step
A beginner-friendly, step-by-step guide to building your first AI automation in Python with the Claude API: setup, a working script and a human check.
Once you can write a little Python, one of the most useful things you can build is an AI automation: a script that does a repetitive thinking task for you, dozens of times, without you sitting there doing each one by hand. This guide walks through your first one end to end — the tools you need, a working script, and the one step most beginners skip. You can type every line yourself in an afternoon.
What an "AI automation" actually is
It is not a robot and it is not magic. It is ordinary Python code that, at one point, sends some text to an AI model and uses the answer. The model does the fuzzy part — reading a sentence, sorting it, summarising it — and your code does everything around it: loading the data, looping through it, and saving the result. If you can read a file and call a function, you can build this.
A good first project is small and boring on purpose. We will build a customer-feedback triage tool: given a list of comments, it labels each one (Bug, Praise, Feature request or Other) and writes a one-line summary. Swap in support emails, survey replies or form submissions and the same shape works.
What you need before you start
- Python installed and the basics: variables, functions, loops and reading a file.
- An API key. An automation talks to the model through an API, so you need a developer account with an AI provider. We use Anthropic's Claude here; the idea is the same with other providers.
- A terminal to install a package and run your script.
If the first point does not sound familiar yet, start with Python fundamentals and come back — this will make far more sense once loops and functions are comfortable.
Step 1: Install the SDK and set your key
A "software development kit" (SDK) is a small library that handles the connection for you. Following Anthropic's official quickstart, install it and set your key as an environment variable so it never sits inside your code:
python3 -m venv .venv
source .venv/bin/activate
pip install anthropic
export ANTHROPIC_API_KEY="your-api-key-here"
Keeping the key in an environment variable, not in the file, is a habit worth forming now: it means you can share or publish your code without leaking a secret.
Step 2: Make one API call
Before automating anything, get a single call working. Create test.py:
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
message = client.messages.create(
model="claude-haiku-5-5",
max_tokens=300,
messages=[
{"role": "user", "content": "Summarise this review in one line: 'Great classes, but the website was slow.'"}
],
)
print(message.content[0].text)
Run it with python test.py. If a one-line summary prints, your key, your install and your connection all work. This matches the Python example on Anthropic's Claude Docs quickstart, which uses the same client.messages.create(...) call and reads the result from message.content.
Step 3: Turn one call into an automation
An automation is just that call wrapped in a function and run over many inputs. Put your comments in a file called feedback.csv with a comment column, then:
import csv
import anthropic
client = anthropic.Anthropic()
def triage(comment):
message = client.messages.create(
model="claude-haiku-5-5",
max_tokens=200,
system=(
"You sort customer feedback. Reply with a category "
"(Bug, Praise, Feature request or Other) and a one-line summary."
),
messages=[{"role": "user", "content": comment}],
)
return message.content[0].text
with open("feedback.csv") as f:
for row in csv.DictReader(f):
print(row["comment"], "→", triage(row["comment"]))
That is the whole idea. The system instruction sets the model's job once; the loop feeds it each comment. Three things make it sturdier in real use:
- Write the output to a file (another CSV) instead of printing, so you can hand it to someone.
- Handle errors with
try/exceptaround the call, so one bad row does not stop the batch. - Ask for a fixed format — for example, "reply as
Category:thenSummary:" — so your code can split the answer reliably.
Step 4: Keep a human in the loop
This is the step beginners skip, and it is the most important one. An AI model can be confidently wrong: it might mislabel a comment or miss sarcasm. So the automation should assist a decision, not make an unchecked one. For a triage tool that means a person skims the labels before anything acts on them; if the script ever took a real action — closing a ticket, emailing a customer — a human should approve it first. Treat the model's output as a draft, not a verdict.
Choosing a model and watching cost
You pay per unit of text, measured in "tokens" (roughly, pieces of words), split into input and output. For a sorting job like this, Anthropic's Claude Docs describe Claude Haiku 5.5 (claude-haiku-5-5) as being "for high-volume, latency-sensitive tasks such as classification, extraction, and routing" — exactly our case — and list it from $0.10 per million input tokens and $0.50 per million output tokens. For harder reasoning you change one line, the model= value:
| Model | Good for | Price (per million tokens) |
|---|---|---|
| claude-haiku-5-5 | Classification, extraction, routing | from $0.10 in / $0.50 out |
| claude-sonnet-5-5 | A balance of speed and intelligence | $2 in / $10 out |
| claude-opus-5-5 | The hardest reasoning and coding | $4 in / $20 out |
All three currently offer a one-million-token context window, so you can hand them long inputs. Figures above are from Anthropic's Claude Docs models overview (platform.claude.com), checked 19 October 2026. Start on the cheapest model that is good enough and move up only if the quality needs it.
Common questions
Do I need to know machine learning to build this?
No. You are using a trained model through an API, not building one. Comfortable Python — functions, loops, files — is enough to start. Machine learning helps later if you want to train your own models.
Is it free to run?
Providers charge per token, though the amounts for small projects are small, and most offer some free credit to begin. Test on a handful of rows first and watch your usage before running thousands.
What else can I automate the same way?
Anything that is "read some text, decide something, write a result": sorting emails, drafting replies, extracting fields from documents, summarising reports. The pattern — load, loop, call the model, save, let a human check — stays the same.
Want to build these with a trainer beside you? Our Python Certification Course (4 months, ₹17,999, GST included) covers the foundations, and the Claude AI Automation course focuses on automations with a review step. Book a free demo class at our Rohini centre or online. New to the language? Start with our step-by-step Python for AI roadmap.
Sources: Anthropic, Claude Docs — "Get started with Claude" (Python quickstart) and "Models overview", platform.claude.com, checked 19 October 2026.
Admissions
Request a call back
Tell us which course you are interested in and the counselling desk will call you about fees, batches and a free demo class.
18008913982 (toll free) · +91 9899-355-335
[email protected]
Open the enquiry form in a separate window ↗
Your enquiry goes to Coding Bytes through ViaCRM so the counselling team can respond. Please share only the details needed for your question, not passwords, payment details or sensitive documents. Privacy & enquiries · Before enrolling
