Anthropic API Key: How to Create and Set Up the Console

Getting your Anthropic API key takes under five minutes. Go to console.anthropic.com, create an account, navigate to API Keys, click Create Key, and copy the key to your environment. That is the short version — the rest of this guide covers every step in detail, plus how to store your key securely, set spend limits, and verify your setup with a real API call.
What Is an Anthropic API Key?
An Anthropic API key is a secret credential — a long string beginning with sk-ant- — that authenticates your application's requests to Claude. Every API call you make must include this key in the request header. Without it, Anthropic's servers cannot identify who is making the request or which account to bill. Think of it as your password to the Claude API.
If you have used other cloud APIs before — AWS, Stripe, Twilio — the pattern here will feel very familiar. If this is your first experience with an AI API, do not worry. The setup is straightforward, and this guide covers every step from account creation to your first verified call.
What You Need Before You Start
The prerequisites for this setup are minimal:
- An email address: Used to create your Anthropic account
- A payment method: The API is not free — you pay per token used. You will add a credit card and set a usage limit. Anthropic will not charge you until you have actually used the API.
- A code editor: Visual Studio Code is the most widely used choice. Any editor that supports your preferred language works fine.
- Python or Node.js installed: For your first API call. Python 3.8+ or Node.js 18+ are both supported.
Cost Control from the Start
The Anthropic API is pay-as-you-go with no monthly minimum. A typical development session — hundreds of test API calls — costs well under $1. Set a monthly spend limit in the Console to ensure you never receive an unexpected bill regardless of how much you experiment.
Step 1: Create Your Anthropic Account
If you already have a Claude.ai account, you can use the same credentials for the Console. If not, create a new account.
- Go to console.anthropic.com in your browser
- Click Sign Up if you do not have an account, or Log In if you do
- Sign up using your email address or your Google account
- Verify your email if you signed up with email and password
Once logged in, you will land on the Anthropic Console — the developer dashboard that gives you access to your API keys, usage statistics, billing, and the Workbench tool.
Step 2: Navigate the Console
The Anthropic Console has several sections worth knowing from the start.
Workbench
The Workbench is the Console's built-in prompt testing tool. It lets you send messages to Claude directly from your browser without writing any code. You can choose which model to use, write a system prompt, adjust parameters like max_tokens and temperature, and see the exact API request and response.
The Workbench is invaluable for developing and testing prompts before you hard-code them into your application. Always prototype here first — then graduate to code. For advanced prompt patterns, see our guide on advanced prompting techniques for Claude.
API Keys
The API Keys section is where you create and manage your authentication credentials. Each key is a long string beginning with sk-ant- that you include in every API request.
Usage
The Usage section shows your token consumption broken down by model, date, and API key. This is how you monitor what your application is actually spending.
Settings
Settings contains your organisation details, workspace configuration, and spend limit controls.
Step 3: Generate Your API Key
- In the Console, click API Keys in the left navigation menu
- Click Create Key
- Give your key a descriptive name — for example dev-local for your development machine or production-app for a deployed application
- Click Create Key to generate it
- Copy the key immediately. Anthropic shows you the full key only once at creation time. If you lose it, you must create a new one.
Never Commit API Keys to Version Control
An API key is a secret credential. If you push it to a public GitHub repository, automated bots scan the internet for exactly these patterns and can begin using your key within minutes. Always store API keys in environment variables or a secrets manager — never in your source code.
Step 4: Set a Spend Limit
Before writing a single line of code, set a monthly spend limit to protect yourself from accidental runaway usage.
- In the Console, go to Settings then Limits
- Set a monthly spend limit appropriate for your current stage. For learning and development, £10–20 per month is generous. The API will stop accepting requests if you hit the limit, preventing unexpected bills.
- Consider also setting per-key limits if you are working in a team environment
Step 5: Add Your Payment Method
- Go to Settings then Billing in the Console
- Add a credit or debit card
- Anthropic bills in arrears — you pay for what you used in the previous billing period, not upfront
You will not be charged for simply having an account or an API key. Charges only accrue when your code makes actual API calls that consume tokens.
Step 6: Set Up Your Local Environment
Now that you have an API key, set up your development environment to use it securely.
Store Your Key as an Environment Variable
On your local machine, store the API key in an environment variable called ANTHROPIC_API_KEY. This is the name the official Anthropic SDKs look for automatically.
On macOS or Linux, add this to your ~/.zshrc or ~/.bashrc file:
Then run source ~/.zshrc to apply it to your current session.
On Windows, set it via System Properties or PowerShell:
Install the Python SDK
If you are using Python (refer to the official getting started guide for the latest SDK version requirements):
Install the Node.js SDK
If you are using JavaScript or TypeScript:
Use a .env File for Projects
For application projects, use a .env file rather than a global environment variable. Store your key as ANTHROPIC_API_KEY=sk-ant-... in the .env file, use a library like python-dotenv or dotenv for Node.js to load it, and add .env to your .gitignore file immediately. This keeps your key local to the project and out of version control.
Once you have the SDK installed and your key set, you are ready to make your first real call. Our Claude API first call quickstart walks through exactly what to send and what to expect back in the response.
Step 7: Verify Your Setup
Make a simple test call to confirm everything is working. Here is the minimal verification script in Python:
If your environment variable is set correctly, this script will print a greeting from Claude. If it raises an AuthenticationError, your key is not being found — double-check the environment variable name and restart your terminal to ensure the variable is loaded.
Understanding Workspaces and Multiple Keys
As your usage grows, you may want to create multiple API keys for different purposes:
- Separation of concerns: Keep separate keys for development, staging, and production environments. This way, if a key is compromised, only one environment is affected.
- Usage monitoring: Separate keys generate separate usage reports, making it easy to understand which application or team is responsible for which costs
- Key rotation: Security best practice dictates rotating API keys periodically. Having separate keys per environment makes rotation easier to manage without disrupting unrelated services
Workspaces in the Console let you group keys and set spend limits at the workspace level — useful for teams where different projects should have independent budget controls.
Common Setup Errors and How to Fix Them
Even with a valid API key, new developers regularly hit the same handful of errors. Here is what each one means and how to resolve it quickly.
AuthenticationError
This is the most common first-time error. It means Claude received your request but could not validate the API key. The causes are almost always one of three things:
- Wrong environment variable name: The SDK looks for
ANTHROPIC_API_KEYexactly — check for typos likeANTHROPIC_APIorCLAUDE_API_KEY - Variable not loaded in the current shell: After adding the export line to
~/.zshrc, you must runsource ~/.zshrcor open a new terminal. The variable does not take effect automatically in your current session. - Key was copied incorrectly: Trailing whitespace or a missing character is invisible but fatal. Copy the key fresh from the Console and paste it again.
RateLimitError
A RateLimitError means you have exceeded your requests-per-minute or tokens-per-minute limit. For development this is rare, but it can happen if you run a loop that fires many requests in quick succession. Add a short time.sleep(1) between calls in testing scripts, or implement exponential back-off for production use.
InvalidRequestError
This error indicates a problem with the request body itself — not the key. Common causes: passing an unsupported model ID, sending a max_tokens value above the model's limit, or structuring the messages array incorrectly. Read the error message carefully — it usually names the exact field that is wrong.
Windows PATH Issues
On Windows, environment variables set via PowerShell only persist for the current session by default. To make ANTHROPIC_API_KEY permanent, set it through System Properties → Advanced → Environment Variables, or use the PowerShell command shown in Step 6 with the "User" scope argument. Restart any open terminals after making the change.
API Key Security Best Practices
Your Anthropic API key is a billing credential. If it leaks, someone else can generate charges on your account. These practices eliminate the most common exposure vectors.
Never Hard-Code Keys in Source Files
The most common mistake is pasting the key directly into a script for a quick test — and then forgetting it is there before committing. Use environment variables or a .env file from day one, even for throwaway scripts. For a deeper look at how APIs handle authentication, see our API fundamentals guide.
Rotate Keys Periodically
Create a new key, update your environment, verify the new key works, then delete the old one. This limits the blast radius of any credential that may have been inadvertently exposed. The Anthropic Console makes it easy to manage multiple keys with descriptive names.
Use Separate Keys Per Environment
Keep dedicated keys for local development, staging, and production. If your production key needs to be rotated, you can do it without touching development. If a development key is accidentally pushed to a public repo, production is unaffected. Separate keys also give you clean per-environment usage data in the Console.
CI/CD Environments
For GitHub Actions, GitLab CI, or similar pipelines, store the key as a repository secret — never in your YAML configuration files. Reference it as ${{ secrets.ANTHROPIC_API_KEY }} in your workflow. Most CI platforms encrypt secrets at rest and mask them in logs automatically.
Public Repositories Are Scanned Automatically
Bots continuously scan GitHub, GitLab, and Bitbucket for API key patterns. A key beginning with sk-ant- will be found within minutes of being pushed. If you accidentally expose a key, delete it in the Console immediately and create a replacement — do not just try to overwrite the commit.
Rate Limits: What to Expect
The Anthropic API enforces rate limits to prevent misuse and manage capacity. As a new account, you will start on Tier 1 with the following limits (see the full rate limits documentation for the current figures across all tiers):
| Tier | Requirement | RPM | TPM (Input + Output) |
|---|---|---|---|
| Tier 1 | Valid payment method | 50 | 50,000 |
| Tier 2 | $40 cumulative spend | 1,000 | 100,000 |
| Tier 3 | $200 cumulative spend | 2,000 | 200,000 |
| Tier 4 | $400 cumulative spend | 4,000 | 400,000 |
For learning and development, Tier 1 limits are more than sufficient — 50 requests per minute is roughly one request every 1.2 seconds, which is faster than most manual testing loops. Understanding what tokens cost and how they accumulate is equally important; our Claude API pricing and token guide breaks this down in detail. As your cumulative spend grows, Anthropic automatically promotes your account to the next tier.
Summary
You now have everything you need to start building with the Claude API:
- An Anthropic Console account with billing configured
- An API key stored securely as an environment variable
- A spend limit protecting you from runaway costs
- The Anthropic SDK installed and verified
The next step is understanding what to do with that API key — making real, structured API calls and understanding the response format. Our Claude Messages API explained guide covers the full request and response structure in depth.
In our next post, we put this setup to work: Your First Claude API Call: Python and JavaScript Quickstart.
This post is part of the Anthropic AI Tutorial Series. Don't forget to check out our previous post: Getting Started with Claude.ai: Your First Conversation.
