
What we are actually doing here.
Right. So you have used Claude in the chat window. You have asked it to explain things. Maybe you have used it to draft emails. That is one way to use Claude. There is another way. You can write a tiny Python program on your computer that sends a message to Claude and prints the reply back. Once you can do that, you can do almost anything — build a script that summarises your inbox, classify a thousand customer reviews while you make coffee, or wire Claude into a tool you already use. The chat window is the demo. The API is where the real work happens.
I am going to be honest with you. The actual code at the end of this tutorial is maybe twelve lines. The thing that takes longest is the setup — getting an account, getting an API key, installing the right library. None of it is hard. It just has a lot of small steps, and if you have never done any of them before, it feels like a lot. Take your time. Do not skip steps. You will be fine.
Step 1: Get an account, add some credits.
Go to console.anthropic.com and create an account. This is the developer console, different from the chat product. You will need to add a payment method and put some credits on the account. Five or ten dollars is plenty for learning — the kind of small requests you will make in this tutorial cost fractions of a cent each. The money you add does not expire quickly, so do not overthink the amount.
One thing the documentation does not always make clear: taxes are calculated on top of whatever you add, so the credit balance you see in the dashboard will be slightly less than what your card was charged. Not a big deal. Just do not panic when the numbers do not match exactly.
Step 2: Create an API key.
In the same console, go to the API keys section and click Create Key. Give it a name — something like “learning” or “first-project” is fine. When the key is created, Anthropic will show it to you once and never again. Copy it immediately and paste it somewhere safe. A password manager is ideal. A sticky note on your laptop is not. If you lose it, you have to make a new one. It is not the end of the world but it is annoying.
A note on security. This key is essentially a password that can spend your money. Do not paste it into a public GitHub repository. Do not share it on Discord. Do not hardcode it into a script that you might later share with a friend. Anyone with this key can run requests against your account until you delete it. The most common way beginners burn a few hundred dollars by accident is by accidentally publishing their key. Take the warning seriously.
Quick reference
Which Claude model should a beginner use?
| Model | Speed & Cost | Best for |
|---|---|---|
| Claude Haiku | Fast, cheap | Practice, simple tasks, your first scripts |
| Claude Sonnet | Balanced | Most production work, longer reasoning |
| Claude Opus | Slower, more expensive | Hard tasks where quality matters most |
For a beginner tutorial, start with Haiku. It is fast, it is cheap, and the answers are perfectly good for learning. You can swap the model name in your code anytime you want to try the others.
Step 3: Install the library.
Open a terminal — on a Mac it is the Terminal app, on Windows it is PowerShell — and run this:
pip install anthropic
That command installs the official Python library that talks to Claude. If you get an error that says pip is not recognised, you probably need to install Python first — head to python.org, install the latest version, restart your terminal, and try again. If you have Python installed already and pip still does not work, try pip3 install anthropic instead. On some systems it is called pip3, on others just pip.
Step 4: Write the script.
Create a new file called hello_claude.py anywhere on your computer. Open it in a text editor — VS Code is free and excellent for this. Paste in this code:
import os
from anthropic import Anthropic
client = Anthropic(api_key="paste-your-key-here")
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=500,
messages=[
{"role": "user", "content": "Tell me a one-sentence joke about programmers."}
]
)
print(response.content[0].text)
Replace paste-your-key-here with the API key you saved earlier. Save the file. In your terminal, navigate to the folder where you saved it and run:
python hello_claude.py
If everything worked, Claude will reply with a one-sentence joke about programmers and your terminal will print it. That is it. You just called the Claude API from Python.
Now what?
Change the message. Ask Claude to summarise an article, draft a tweet, classify the sentiment of a customer review, translate something into Swedish. The pattern is always the same: change the string inside "content" and run the script again. That is genuinely most of what beginner Claude work looks like.
Once you are comfortable with that, the next thing worth learning is how to store your API key as an environment variable instead of pasting it directly into the script. It keeps your key out of your code, which matters when you start saving files to GitHub or sharing scripts with colleagues. We will cover that in a follow-up post. For now, what you have is enough to start being dangerous in a good way.
Common Questions
FAQ — what beginners actually ask me.
How much will this actually cost me to learn?
Honestly, almost nothing. A typical beginner script with Claude Haiku costs less than a tenth of a cent per request. If you run hundreds of test requests while you learn, you might spend a dollar or two. Add five dollars to your account and you will be fine for weeks.
I copied the code and got an error. What now?
First, copy the error message and paste it back into Claude (the chat one). Tell it what you were trying to do and ask what is wrong. It is shockingly good at debugging beginner errors. Second, check the most common culprits: did you replace the API key placeholder? Did you spell the model name exactly right? Did you actually save the file before running it?
What is the difference between the API and ChatGPT or the Claude chat app?
The chat app is a finished product designed for humans typing in a browser. The API is the raw interface developers use to build their own products on top of the same underlying model. The API costs slightly different prices, has different limits, and gives you full control over the model parameters. Most companies you have heard of that use AI are using the API behind the scenes.
Should I memorise the code?
No. Genuinely no. Every senior engineer I have ever worked with looks up boilerplate code constantly. What matters is that you understand what each line is doing, not that you can write it from memory. The pattern is: import the library, create a client, call the messages endpoint, print the response. That is the shape of every Claude API call.
What does max_tokens mean?
It is the maximum length of the response, measured in tokens (which are roughly three quarters of a word each). Setting max_tokens=500 means Claude will stop after about 375 words even if it has more to say. It is a safety control that stops a runaway response from costing you money. For beginner work, a few hundred is fine.
Can I have a back-and-forth conversation with Claude through the API?
Yes, but you have to manage it yourself. The API does not remember previous messages between calls — each request is fresh. To have a conversation, you append each new message to the messages list and send the whole history every time. We will cover this properly in a follow-up post.
What if I do not want to write code at all?
Then this post is not for you, and that is okay. Vogue and Code covers no-code paths too — tools like Zapier and Make can call the Claude API for you without writing a single line of Python. Worth knowing both routes exist. Some problems are better solved one way, some the other.
Is it safe to paste my API key into the script like this?
For learning, on your own computer, in a file you will never share — yes, it is fine. For anything more serious, you should use environment variables to keep the key out of the code. The reason is that the moment you save the file to GitHub or send it to someone, your key is exposed. We will write a follow-up post on environment variables specifically because they are important enough to deserve their own walkthrough.
