How to Set Up Claude API From Scratch

I spent three hours one afternoon trying to connect Claude’s API to a simple script that would auto-draft property descriptions from my listing notes. I had the API key. I had the endpoint. I had no idea why nothing was working. Turns out I had the authorization header formatted wrong — one missing word, “Bearer”, before my key. Three hours. One word. That afternoon convinced me to write the guide I wish had existed when I started.

If you’re a solo operator — a consultant, a freelancer, someone running a one-person business — and you want to stop copying and pasting into Claude’s chat interface and actually build something that works automatically, the API is where that happens. This is a complete beginner’s walkthrough. No coding background assumed. By the end, you’ll have a working API call that returns real output from Claude.

What You’ll Build by the End of This Tutorial

A working Claude API setup that can accept a text prompt and return a Claude-generated response. Specifically, you’ll run your first successful API call from your computer — no web interface, no third-party tool in between. Once that’s working, I’ll show you how I use this exact setup in my real estate business to automate property description drafts.

This tutorial uses Python because it’s the most beginner-friendly option and the one Anthropic’s own documentation leads with. You don’t need to be a developer. You need to follow steps carefully.

Prerequisites: What You Need Before Step 1

Prerequisites What You Need Before Step 1
  • An Anthropic account (free to create at console.anthropic.com)
  • A credit card to add to your Anthropic account (API usage is pay-as-you-go; you won’t be charged until you use tokens)
  • Python 3.8 or higher installed on your computer (python.org/downloads)
  • A code editor — VS Code is free and what I use, but even a basic text editor works for this
  • About 45 minutes of uninterrupted time

The API is not free. But for light usage — say, drafting 20–30 property descriptions a month — you’re looking at pennies. I’ll cover the real cost numbers below.

Step 1: Create Your Anthropic Account and Get Your API Key

Go to console.anthropic.com and sign up. Use your business email. Once you’re in, look at the left sidebar and click API Keys.

Click Create Key. Give it a name — I call mine “madeira-listings-bot” so I remember what it’s for. Copy the key immediately. Anthropic only shows it once. If you close the window without copying it, you’ll need to generate a new one.

Store it somewhere safe. I use a password manager. Do not paste it into a Google Doc. Do not share it with anyone. This key is what authorizes charges to your account.

Adding Credits to Your Account

Before your API calls will work, you need to add credits. Go to Settings → Billing and add a payment method. Then purchase credits — $5 is enough to test with extensively. For context: Claude Haiku (the cheapest model) costs $0.25 per million input tokens. A typical property description prompt from me is about 300 tokens. That’s $0.000075 per call. You could run 66,000 calls for $5. You’re not going to break the bank testing this.

Step 2: Install Python and the Anthropic Library

Step 2 Install Python and the Anthropic Library

Open your terminal (Mac: search “Terminal” in Spotlight; Windows: search “Command Prompt” or “PowerShell”).

Check that Python is installed by typing:

python --version

You should see something like Python 3.11.4. If you see an error, go install Python from python.org before continuing.

Now install the official Anthropic Python library:

pip install anthropic

Wait for it to finish. You’ll see a confirmation line that says something like Successfully installed anthropic-0.x.x.

Step 3: Set Up Your API Key as an Environment Variable

This is the step most beginners skip, and it’s what causes the security headaches later. Don’t hard-code your API key directly into your script. Use an environment variable instead.

On Mac or Linux

In your terminal, run:

export ANTHROPIC_API_KEY="your-key-here"

Replace your-key-here with the actual key you copied in Step 1. To make this permanent (so you don’t have to re-run it every time), add that line to your ~/.zshrc or ~/.bash_profile file.

On Windows

Search for “Environment Variables” in the Windows search bar. Click “Edit the system environment variables.” Under “User variables,” click New. Set the variable name as ANTHROPIC_API_KEY and paste your key as the value. Click OK. Restart your terminal.

Step 4: Write and Run Your First API Call

Step 4 Write and Run Your First API Call

Open your code editor. Create a new file called test_claude.py. Copy this exactly:

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Write a two-sentence property description for a 2-bedroom apartment with ocean views in Funchal, Madeira. Tone: professional, warm."}
    ]
)

print(message.content[0].text)

Save the file. Go back to your terminal, navigate to the folder where you saved it (use cd your-folder-name), and run:

python test_claude.py

If everything is set up correctly, you’ll see Claude’s response printed in the terminal within a few seconds. That’s your first working API call.

Understanding What You Just Wrote

model: Which Claude model to use. claude-opus-4-5 is the current capable option as of 2026. For faster, cheaper results, use claude-haiku-4-5. For the most capable output, use claude-opus-4-5.

max_tokens: The maximum length of Claude’s response. 1024 is a safe starting number. Increase it if you need longer outputs.

messages: The conversation you’re sending. The role is either user or assistant. For a single question, you only need one user message.

Step 5: Add a System Prompt to Control Claude’s Behavior

This is where the API becomes genuinely useful over the chat interface. You can give Claude a persistent role and set of instructions that apply to every call — without typing them each time.

Here’s the version I actually use for my listing descriptions:

import anthropic

client = anthropic.Anthropic()

SYSTEM_PROMPT = """You are a real estate copywriter specializing in luxury and mid-market 
residential properties in Madeira, Portugal. 

When given property details, write a compelling listing description that:
- Opens with the property's strongest feature
- Mentions location, size, and key amenities in the first paragraph
- Uses specific, sensory language (light, views, materials)
- Avoids clichés like "cozy," "charming," or "must-see"
- Ends with a line about lifestyle, not just features
- Target length: 120-150 words
- Tone: professional, warm, confident"""

property_notes = """
3 bed / 2 bath apartment
Area: Ponta do Sol, Madeira
Size: 95 sqm
Features: south-facing terrace, sea views, renovated kitchen, parking included
Price: €285,000
"""

message = client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    system=SYSTEM_PROMPT,
    messages=[
        {"role": "user", "content": f"Write a listing description for this property:nn{property_notes}"}
    ]
)

print(message.content[0].text)

Save this as listing_writer.py and run it. The system prompt does the heavy lifting. Every time I update the property_notes variable with a new listing’s details, I get a consistent, on-brand description in seconds.

Claude Model Comparison: Which One Should You Use?

Claude Model Comparison Which One Should You Use
Model Best For Input Cost (per 1M tokens) Speed
claude-haiku-4-5 High-volume, simple tasks (descriptions, summaries) $0.25 Very fast
claude-sonnet-4-5 Balanced quality and cost; most use cases $3.00 Fast
claude-opus-4-5 Complex reasoning, nuanced writing, analysis $15.00 Slower

For most solo business use cases — writing, summarizing, drafting — Haiku or Sonnet is the right call. I only use Opus when I need detailed market analysis or when the output genuinely requires more reasoning depth. For 90% of my listing work, Haiku is fast, cheap, and good enough.

My Real-World Experience Using the Claude API in My Madeira Real Estate Business

I set this up properly in January 2026, after 18 months of half-measures — copy-pasting into Claude’s chat, manually adjusting outputs, losing the prompt I’d carefully written because I’d closed the browser tab. The API changed how I actually work.

Here’s a concrete example. In February 2026, I had 14 new listings to write descriptions for — a mix of apartments in Funchal, a couple of rural quintas, and three holiday lets in Calheta. Before the API, my process was: open Claude chat, paste my property notes, paste the prompt I’d saved in a Notion doc, read the output, tweak it manually, copy to my listing sheet. Multiply that by 14. I was spending between 12 and 15 minutes per listing, mostly on the friction of the manual steps. Total: close to 3.5 hours for that batch.

With my listing_writer.py script, I update the property notes, run the script, copy the output. The system prompt is already embedded. No re-pasting. No tab-switching. Each listing takes me about 4 minutes now — mostly because I still read and lightly edit every output before it goes live. I won’t skip that step. But the actual generation and first pass dropped from 8–9 minutes per listing to under 90 seconds.

For those 14 listings: old process, roughly 3.5 hours. New process, about 56 minutes. That’s 2.5 hours recovered in one month from one script. My API cost for that batch? I checked my Anthropic console: $0.18. Not a typo. Eighteen cents for 14 listing descriptions using claude-haiku-4-5.

I’ve since built a second script that takes client inquiry emails, extracts the key requirements (budget, location preference, property type), and drafts a personalized follow-up response suggesting three matching listings from my inventory. That one runs through Sonnet because the matching logic requires more nuance. Still costs less than $0.01 per email processed.

What I didn’t expect: how much the consistency improved. When I was manually prompting through the chat interface, I’d sometimes forget to include a tone instruction, or I’d get a slightly different style because I’d rephrased something. The API with a fixed system prompt gives me the same baseline every time. I’m editing for content, not rewriting for style.

Troubleshooting: The 5 Most Common Errors and How to Fix Them

Troubleshooting The 5 Most Common Errors and How to Fix Them

Error: “AuthenticationError: 401”

Your API key is wrong or not being read. Check that your environment variable is set correctly. Run echo $ANTHROPIC_API_KEY (Mac/Linux) or echo %ANTHROPIC_API_KEY% (Windows) in your terminal to confirm it’s there. Make sure there are no extra spaces or quotation marks in the key.

Error: “PermissionDeniedError: 403”

You haven’t added billing credits to your account. Log into console.anthropic.com, go to Billing, and add funds. Even $5 will unblock you immediately.

Error: “RateLimitError: 429”

You’ve hit a rate limit. New accounts have lower limits that increase over time. For batch processing, add a small delay between calls: import time and then time.sleep(1) between requests.

Error: “ModuleNotFoundError: No module named ‘anthropic'”

The library isn’t installed in the Python environment you’re using. Run pip install anthropic again in the same terminal session where you run your script. If you use virtual environments, make sure you’ve activated the right one.

Output Is Blank or Shows “None”

You’re printing the wrong part of the response. The correct path is message.content[0].text. If you just print message, you’ll get the full response object, not the text. If you print message.content, you get a list. You need the first item’s text property.

One Real Limitation I’ve Run Into Personally

The API has no memory between separate calls. Each call is a fresh conversation. For my listing descriptions, that’s fine — each one is standalone. But when I tried to build a multi-step client intake flow where Claude would ask follow-up questions based on previous answers, I had to manually build the conversation history by storing each exchange and passing the full history array with every new call. It works, but it means your conversation history can get large and expensive quickly if you’re not managing it carefully.

This isn’t a deal-breaker, but it’s not obvious from the documentation when you’re starting out. Stateless by default. Plan for it.

Practical Summary: What You’ve Built and Where to Go Next

Practical Summary What Youve Built and Where to Go Next

You now have a working Claude API setup: account created, credits added, API key stored securely as an environment variable, Python library installed, and a script that runs real Claude completions from your own machine. That’s not a small thing. Most people who “want to use the API” never get past reading about it.

Three immediate next steps worth taking:

  1. Swap out the prompt for something relevant to your actual work. A client email draft. A social media post. A product description. The structure stays identical — only the system prompt and user message change.
  2. Test Haiku vs. Sonnet on the same prompt and compare the output quality against the price difference. For most text tasks, Haiku surprises you.
  3. Read Anthropic’s official prompt engineering guide at docs.anthropic.com. Their documentation is genuinely good and will save you hours of trial and error.

The setup I walked you through took me an embarrassing amount of time to get right because I was piecing it together from scattered sources. This is the guide I needed in early 2024. If you’re a solo operator who’s been living in Claude’s chat interface, the API is the version that actually fits into a working system — and it costs less than a coffee a month for the kind of volume I run.

Got your first call working? Drop a comment below with what you’re using it for — I read every one.

Robson Penassi

Robson Penassi

Real estate consultant in Madeira, Portugal. Solopreneur since 2012. Testing AI tools since 2023 to automate his one-person business. Writes about what actually works — and what does not.

More articles by Robson →

Leave a Comment