Lesson 2 of 6
Get Ready: Accounts, API Access and Safety
On this page
- What you will learn
- The website and the developer platform are different
- Getting developer access and an API key
- Create the project folder and virtual environment
- Store the key in a .env file and ignore it in Git
- Safety habits to keep for the whole course
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- References
Before you can write a line of agent code you need three things: access to Claude through the developer platform, a clean folder to work in, and a safe place for your secret key. None of this is difficult, but each step has a trap that catches beginners. The most costly trap is also the most common: pasting an API key into a file that later ends up in a public repository.
This lesson walks through the set-up path in the order that avoids those traps. You will create the project folder claude-order-helper, a Python virtual environment, a .env file that holds your key, and a .gitignore file that keeps that .env file out of version control. Finally you will run a tiny script that confirms the key is visible to Python without ever printing it.
What you will learn
- Explain the difference between the Claude website and the developer platform.
- Follow the current official path to developer access and create an API key.
- Explain why API access may need billing and is separate from a chat subscription.
- Store the key in a
.envfile, load it from an environment variable and keep it out of Git.
Before you start
- Python 3.10 or later installed. Check with
python --version(on some systemspython3 --version). - A terminal: Terminal on macOS or Linux, PowerShell or Windows Terminal on Windows.
- An email address to create an account, and possibly a payment method if the platform requires one for API use.
- A text editor such as Visual Studio Code, or any editor you like.
The website and the developer platform are different
Claude is available in several ways. You may already use it in a browser or a phone app to chat. That chat product has its own account, its own plans and its own usage limits. The developer platform is where you get programmatic access: you create an API key there and your own programs use that key to send requests.
The two are separate. Being signed in to the chat app does not give your program access, and a chat subscription does not pay for API requests. API usage is set up and billed through the developer platform, typically on a pay-for-what-you-use basis. Plans, free credits, limits and prices change over time, and they can differ by account and region, so this course quotes none of them. Read the current terms on Anthropic's own pages before you add a payment method.
Getting developer access and an API key
Websites change their layouts, so this lesson does not describe individual buttons. Instead, follow Anthropic's current getting-started guide, which is the official source for the account and key steps. You are aiming for one outcome: a secret API key shown to you once, which you copy somewhere temporary.
Step 1: Open the official getting-started guide
Use the link in this lesson's references: Anthropic getting started (opens in a new tab). It links to the developer Console and explains the current sign-up path.
What you should see: You have the guide open in one tab and the developer platform in another.
Step 2: Create or sign in to a developer account
Follow the guide. If it asks you to add billing or credits before API calls work, read the terms first and add only what you are comfortable with.
What you should see: You can see the developer Console's dashboard.
Step 3: Create an API key
Find the API keys area, create a new key and give it a descriptive name such as claude-order-helper-learning. The key is a long secret string. It is usually displayed only once, so copy it now.
What you should see: You have a key in your clipboard. Do not paste it anywhere public: not into a chat, an email, a screenshot or a code file.
Step 4: Note how to revoke the key
Find where keys are listed and how to delete or disable one. If a key is ever exposed, revoking it immediately is the correct response.
What you should see: You know where the revoke control is before you need it.
Create the project folder and virtual environment
A virtual environment is a private copy of Python's package area that belongs to one project. It stops this project's packages from clashing with others on your computer. Python ships the tool for this, called venv. See the venv documentation (opens in a new tab) for details.
Step 1: Create the folder
Choose a place that is not inside another Git repository. Then create the folder and move into it.
Bash mkdir claude-order-helper cd claude-order-helperWorks in macOS, Linux and Windows PowerShell.
What you should see: Your terminal prompt now shows you are inside claude-order-helper.
Step 2: Create the virtual environment
This makes a hidden folder called .venv that holds the project's Python packages.
Bash python -m venv .venvOn some macOS or Linux systems use python3 instead of python.
What you should see: A new .venv folder appears. The command prints nothing when it works.
Step 3: Activate it on macOS or Linux
Activation tells your terminal to use the project's Python and packages instead of the system ones.
Bash source .venv/bin/activateWhat you should see: Your prompt gains a (.venv) prefix.
Step 4: Or activate it on Windows
Use the first command in PowerShell and the second in Command Prompt. If PowerShell refuses to run the script because of an execution policy, read Microsoft's guidance on execution policies before changing anything, or use Command Prompt instead.
PowerShell # PowerShell .venv\Scripts\Activate.ps1 # Command Prompt (cmd.exe) .venv\Scripts\activate.batWhat you should see: Your prompt gains a (.venv) prefix.
Step 5: Install the two packages you need
The first is the official Anthropic Python SDK, which sends requests to the API for you. The second, python-dotenv, reads a .env file. Package versions change, so this installs whatever is current; the lesson on first requests explains how to record the versions you ended up with.
Bash pip install anthropic python-dotenvWhat you should see: pip prints 'Successfully installed' followed by package names.
Store the key in a .env file and ignore it in Git
An environment variable is a named value that lives outside your code and is available to the programs you run. Storing the key as ANTHROPIC_API_KEY is the convention the Anthropic SDK looks for, so its client can find the key without you writing it in code. This idea follows the twelve-factor approach to configuration (opens in a new tab): keep secrets in the environment, not in the code.
A .env file is a plain text file that lists variables, one per line. The python-dotenv package reads it when your program starts and adds the values to the environment. Because the file contains a secret, it must never be committed to Git, and a .gitignore file is how you tell Git to skip it. For more on this pattern see managing API keys locally and the gitignore documentation (opens in a new tab).
Step 1: Create .gitignore first
Do this before you create the .env file, so there is never a moment when the secret could be staged by accident. The second and third lines also keep Python's virtual environment and cache out of your repository.
Text.gitignore # Secrets: never commit these .env # Python housekeeping .venv/ __pycache__/What you should see: A file named .gitignore exists in claude-order-helper.
Step 2: Create the .env file
Replace the placeholder with your real key. There are no quotes and no spaces around the equals sign. The placeholder below is not a real key.
Text.env ANTHROPIC_API_KEY=paste-your-key-hereWhat you should see: The file has one line, and your editor shows it as a plain text file.
Step 3: Write a check script that never prints the key
This program confirms that Python can see the key, and reports only whether it is present and how long it is. Printing a secret to a terminal can leak it into logs or screenshots, so the script deliberately does not.
Pythoncheck_setup.py import os from dotenv import load_dotenv # Read the .env file in this folder and add its values to the environment. load_dotenv() key = os.environ.get("ANTHROPIC_API_KEY") if not key: print("No ANTHROPIC_API_KEY found. Check the name and the .env file.") elif key == "paste-your-key-here": print("The .env file still has the placeholder. Paste in your real key.") else: # Report presence and length only. Never print the key itself. print("Key found. Length:", len(key), "characters.")What you should see: Running it prints one line, described below.
Step 4: Run the check
Make sure the (.venv) prefix is showing, then run the script.
Bash python check_setup.pyWhat you should see: You see a 'Key found' line. If you see a different message, use the troubleshooting section below.
Key found. Length: 108 characters.Safety habits to keep for the whole course
- Keep the key on your own computer or on a server you control. Never in code that runs in a web browser, because anyone can read browser code.
- Never commit
.env. Confirm.gitignorelists it before your first commit. - Never paste your key into a prompt, a chat or an issue. If you need help, share the error message with the key removed.
- Use one key per project and give it a clear name so you can revoke just that one.
- Check your usage page regularly and set any spending limit the platform offers.
These habits matter far beyond this course. The agent launch safety checklist returns to them in a broader setting.
Common errors and how to fix them
The check script says 'No ANTHROPIC_API_KEY found'.
Why it happens: The .env file is in the wrong folder, is misnamed (for example .env.txt), or the variable name is misspelled.
Fix: Make sure .env is in the same folder as check_setup.py and is named exactly .env. The variable must be spelled ANTHROPIC_API_KEY. On Windows, turn on file extensions in File Explorer to catch a hidden .txt ending.
ModuleNotFoundError: No module named 'dotenv'.
Why it happens: The virtual environment is not active, or the package was installed into a different Python.
Fix: Activate .venv so the (.venv) prefix shows, then run pip install anthropic python-dotenv again. The package name for pip is python-dotenv even though you import dotenv.
PowerShell says running scripts is disabled when you activate the environment.
Why it happens: Windows has an execution policy that blocks unsigned scripts.
Fix: Use Command Prompt and .venv\Scripts\activate.bat, or read Microsoft's documentation on execution policies before changing the policy for your user.
You pasted the key into a code file or committed it.
Why it happens: The secret was placed where Git can see it.
Fix: Revoke the key in the developer platform immediately and create a new one. Deleting the file afterwards is not enough, because Git history keeps old versions.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Prove that .env is ignored
Without making any commit you will keep, confirm that Git would ignore your .env file. Initialise a repository in the project folder and ask Git whether it would ignore .env.
You will need
- Your claude-order-helper folder with .gitignore and .env in place.
Acceptance criteria
Your work is done when every one of these is true.
Hints (2)
- Run git init once inside claude-order-helper if it is not already a repository.
- If .env appears in git status, check the spelling in .gitignore and that the file is named exactly .env.
Show a model answer
After git init, git status should show .gitignore and check_setup.py as untracked but not .env. The command git check-ignore -v .env prints the file and line of the rule that matched, which is direct evidence that the secret is excluded. If .env was added or committed before the rule existed, the ignore rule will not remove it from history, which is why the order of steps matters.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. The chat app and the developer platform are separate products with separate access and billing. The first option is a natural assumption, but a subscription does not cover requests made with an API key.
Show the answer and explanation
Answer: A. A .env file kept out of Git keeps the secret outside your code. A constant in agent.py is tempting for convenience, but code gets committed and shared. Browser code is readable by everyone.
Show the answer and explanation
Answer: C. Once a key has been public it must be treated as compromised, and revoking it stops anyone using it. Deleting the file is tempting but Git history, forks and caches may still hold the old version.
- Written by
- PromptFable Editorial
- Last updated 13 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- Anthropic: Get started(opens in a new tab)
Anthropic · Official documentation · The current official path for developer access and API keys.
- Python venv: creation of virtual environments(opens in a new tab)
Python Software Foundation · Official documentation
- gitignore documentation(opens in a new tab)
Git · Official documentation
- The Twelve-Factor App: Config(opens in a new tab)
12factor.net
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.