A Claude API key (Anthropic’s docs also call it an Anthropic API key) is the secret that lets your own code call Claude through the API. This free setup helper walks you through getting one in the Claude Console, storing it safely as an environment variable, and making a first test call, with commands written for your computer and your language.
It never asks for your key. Every command uses a placeholder and reads the key from your environment, so the real key only ever lives on your machine or in your secret store.
Free setup helper
Get a Claude API key, store it safely and test it
Pick your computer, your language and where the key will live. You get the exact steps, copy-ready commands and a first test call. This page never asks for your key. You only ever paste it into your own terminal, file or secret store.
Your computer
Your language
Where the key will live
Get the starter project checklist and a safe .env template
Unlock a ready-to-copy .env, .env.example and .gitignore for the language you picked, plus a 10-point checklist for starting a Claude project the safe way.
Unlocked: your starter kit is just below. You are also on the weekly HOW TO // AI newsletter.
Free. You also get the HOW TO // AI newsletter once a week. Unsubscribe any time.
Troubleshooting: what the error means
Type the status code or the error type from the response (for example 401 or rate_limit_error) to jump to it.
Next: estimate what your calls will cost, install Claude Code or build a well-structured Claude prompt.
Sources: Anthropic's API key guide, authentication docs, quickstart, error reference, spend limits and key safety article; Microsoft Learn for Windows variables; GitHub Docs for Actions secrets. Checked October 18, 2026. Model IDs change when new models ship.
How to use the setup helper
- Pick your computer (macOS, Windows or Linux), your language (Python, TypeScript or curl) and where the key will live: your own computer, a .env file in a project, or GitHub Actions.
- Follow the steps in order and tick each one off. The copy buttons give you the exact commands.
- Run the test call. A one-line reply from Claude means your key works.
- Got an error instead? Type the status code into the troubleshooting box to see what it means and what to do.
How to get a Claude API key
API keys live in the Claude Console, not in a claude.ai chat plan. Sign in, open the API keys page, click Create key, give it a name, choose an expiration and set the linked account. You can also scope the key to one workspace.
Copy the key straight away. It starts with sk-ant- and the Console shows it only once. If you lose it, you can’t view it again, so create a new key and delete the old one.
Which kind of key you pick decides who it acts as and when it stops working:
| Key type | Acts as | Use it for |
|---|---|---|
| Personal key | You | Your own development. It stops working if you leave the organization. |
| Service account key | A service account | CI pipelines, servers, agents and anything shared |
| Workspace key (legacy) | The workspace, not a person | Older setups. Anthropic recommends the other two for new work. |
Is the Claude API free?
Creating a key is free, but API calls are paid for with credits you add on the Billing page in the Console. New users get a small amount of free credits to try it out.
If you pay for Claude Max or Team, those plans include monthly API credits once you link a Console organization: $100 a month on Max 5x, $200 on Max 20x, and up to $500 pooled on Team. Free, Pro and Enterprise plans don’t include API credits. To see what each model costs per token, see our Claude pricing guide.
How to keep your API key safe
- Keep it out of your code. Read it from the ANTHROPIC_API_KEY environment variable. The official SDKs pick it up automatically.
- Add .env to .gitignore before your first commit, and in the cloud use your host’s secret settings instead of a .env file.
- Set an expiration, then rotate on a schedule. Anthropic suggests a consistent schedule, for example every 90 days.
- Set a monthly spend limit on the Billing page. Workspaces can have their own spend and rate limits too.
- Use separate keys for development, testing and production, so you can switch off just one.
- If a key leaks, disable or delete it right away. Disable is reversible; delete is permanent. Anthropic is also part of GitHub’s secret scanning program: a Claude key pushed to a public GitHub repository is deactivated automatically, and the owner gets an email.
Common Claude API key errors
| Error | What it usually means |
|---|---|
| 401 authentication_error | The key is missing, malformed, revoked or expired |
| 403 permission_error | The key isn’t allowed to use that resource. Check your workspace settings. |
| 400 invalid_request_error | A problem with the request, or you reached a spend limit you set yourself |
| 402 billing_error | A problem with your billing or payment details |
| 429 rate_limit_error | A rate limit, or your usage tier’s monthly spend cap |
| 529 overloaded_error | The API is busy for everyone. Wait and retry. |
The most common one by far is 401 right after setup. It usually means the terminal you’re running from can’t see the variable yet: open a new terminal window and try again.
Related on HOW TO // AI
- Claude pricing: every plan and what the API costs per model.
- AI token calculator: see how many tokens your prompt uses before you send it.
- How to use Claude Code: a step-by-step beginner’s guide.
- Claude Developer study guide (CCDV-F): if you’re building on the API, the matching certification.
Checked against Anthropic’s API key, authentication, quickstart, errors, rate limits and pricing documentation and the Claude Help Center on October 18, 2026.
Frequently asked questions
Where do I find my Claude API key?
In the Claude Console, on the API keys page (platform.claude.com/settings/keys). The Console shows a key's full value only once, when you create it, so if you didn't save it, create a new key and delete the old one.
Is a Claude API key the same as an Anthropic API key?
Yes. Anthropic's docs say API keys for the Claude API are also called Anthropic API keys. Both names mean the key you create in the Claude Console.
Is the Claude API free?
Creating a key is free, but API calls use paid credits. New users get a small amount of free credits to test with, and Claude Max and Team plans include monthly API credits you can claim in the Console.
Does Claude Pro include API access?
No. API usage is billed separately through the Claude Console, and Pro is not one of the plans that include monthly API credits. Max 5x, Max 20x and Team are.
What should I do if my Claude API key leaks?
Go to the API keys page in the Claude Console right away and disable or delete the key. Then create a new key and update it everywhere the old one was stored.
