Skip to main content

How to Get a Claude API Key (Step-by-Step with Screenshots)

· 16 min read
Jagdish Kumawat
Founder @ Dewiride

Every app that talks to Claude, from a ten-line script to a full AI agent, needs an API key. Getting one takes about two minutes in the Claude Console. This guide shows every screen, explains each setting, and covers what most guides skip: storing the key safely, paying for usage and replacing a key later.

What a Claude API Key Is​

The Claude API lets your own code send a message to Claude and get the answer back as data, instead of typing into a chat window. Every request your code sends must carry an API key: a long secret string that starts with sk-ant-. The key tells Anthropic two things:

  • who is calling, so only you can use your account, and
  • who pays, because API usage is charged per request.

Treat the key like a password to your bank card. Anyone who has it can send requests that you pay for.

Keys are created in the Claude Console at platform.claude.com, Anthropic's site for developers. That is a different place from the Claude chat app you may already use:

Claude app (claude.ai)Claude API (Claude Console)
What it isChat with Claude in a browser, desktop or mobile appCall Claude from your own code
How you payA monthly plan (Free, Pro, Max, Team, Enterprise)Pay as you go, per token used
Where you sign inclaude.aiplatform.claude.com

A paid Claude plan does not cover general API usage. Anthropic bills the API separately through the Console. Max and Team plans include some monthly API credits; see Anthropic's article Why is Claude API usage billed separately from my paid Claude plan? for the details.

Before You Start​

You need:

  • An email address or a Google account, to sign in to the Claude Console.
  • About five minutes.
  • A payment card, to keep using the API. Anthropic's pricing page says new users get a small amount of free credits to test the API. After that, you add credits on the Console's Billing page (covered later in this guide).

Creating the key itself is free. You only pay for the requests you make with it.

Step 1: Sign In to the Claude Console​

Go to platform.claude.com. The same page signs you in or creates a new account, so choose whichever method you prefer: Continue with Google, your email address, or Continue with SSO if your company uses single sign-on.

The Claude Console sign-in page with the heading Build on the Claude Platform, a Continue with Google button, an email address field and a Continue with email button

Follow the prompts for the method you choose. When you are signed in, the Console opens.

Use a work account for business projects

For a company project, use your work email, so the account, its keys and its bills belong to the business rather than to a personal account.

Step 2: Open the API Keys Page​

After signing in you land on the Dashboard. Select API keys in the left-hand menu. You can also go straight to platform.claude.com/settings/keys.

The Claude Console sidebar showing the Default workspace selector, a search box, and the menu items Dashboard, API keys, Build, Playground, Files, Skills and Batches

The box at the top of the menu, here showing Default, is the workspace selector. A workspace is a folder inside your account that groups API keys, usage and limits. Every account starts with one called Default, and that is all you need to begin.

The API keys page lists the keys in the selected workspace. On a new account the list is empty and the counter shows 0:

The API keys page with a count of 0, a workspace filter set to Default, a Create key button at the top right, and an empty state reading Create an API key

Select Create key.

Step 3: Choose an API Key Instead of Identity Federation​

Before the form opens, the Console may suggest a keyless option first:

A dialog titled With identity federation, you don't need an API key, listing benefits such as tokens that rotate automatically, with a Set up identity federation button and a Continue with an API key link

Identity federation (Workload Identity Federation) lets an app that already runs on a cloud platform (AWS, Google Cloud, Azure, GitHub Actions or Kubernetes) prove who it is with a short-lived token from that platform. Nothing secret is stored, and the tokens expire within minutes. It is the better choice for production workloads hosted on those platforms.

For code that runs on your own computer, such as a script, a tutorial project or local development, you need an API key. As the dialog itself says, "local scripts, third-party tools, and environments without an identity provider may still need an API key". Select Continue with an API key.

Step 4: Fill In the Key Details​

The Create API key form has four settings:

The Create API key form with Name set to dewiride-lead, Expires set to 30 days, Linked account set to the signed-in user, Scope set to Default workspace, and a Create key button

SettingWhat it meansWhat to choose
NameA label so you can recognize the key later. Only you see it.The app that will use it, for example dewiride-lead for a lead qualification app
ExpiresWhen the key stops working on its own. The choices are 3 hours, 1 day, 7 days, 30 days, a custom duration, or Never.The shortest period that suits you. 30 days is a good default for development.
Linked accountWho the key acts as. Linked to you, it is a personal key: requests act as you, and the key stops working if you leave the organization.Yourself, for your own development
ScopeWhich workspace the key works in.Default workspace. The form confirms the key "only works in the Default workspace and can't use the Admin API".

Select Create key.

Personal, service account and workspace keys

Anthropic offers three kinds of key:

  • A personal key acts as you. Use it for your own development and scripts.
  • A service account key belongs to a non-human identity that an organization admin creates in Settings → Service accounts. Use it for anything shared, such as a production server or a CI pipeline, so it keeps working when people come and go.
  • Older workspace keys belong to a workspace and have no owner. Anthropic now treats them as legacy.

For everything on this blog, a personal key is the right choice.

Step 5: Copy the Key and Store It Safely​

The Console shows the full key once:

The Save your API key dialog showing the key's expiry date and time, the new key starting with sk-ant-usr- (replaced here by X characters), a Copy key button and a Done button

  1. Select Copy key.
  2. Paste it straight into the place you will keep it. A password manager is ideal. For a project on your computer, the project's .env file works too (see the next step).
  3. Only then, select Done.

As the dialog warns, "You won't be able to view it again". If you close it before copying, the key is lost: create a new one, then delete the one you could not copy.

The real key in the screenshot above has been replaced with X characters. A real key is much longer and starts with sk-ant-. Personal keys like this one start with sk-ant-usr-.

Keep the key secret

Never paste your API key into a chat (including AI assistants), an email, a screenshot, a public forum or a support ticket. Never write it into your source code or commit it to Git. If a key ever leaks, delete it in the Console straight away and create a new one.

Step 6: Give the Key to Your Code​

The official Claude SDKs (Python, TypeScript, Java, Go, C#, PHP and Ruby) look for the key in an environment variable called ANTHROPIC_API_KEY. An environment variable is a named value your terminal hands to every program it starts. Your code never has to contain the key.

You can set it in two ways.

Option A: In the Terminal, for the Current Session​

Replace sk-ant-your-key-here with your real key, then run the command for your system:

Terminal
export ANTHROPIC_API_KEY="sk-ant-your-key-here"

This lasts only until you close that terminal window. It is handy for a quick test, but you would have to repeat it every time.

Option B: In a .env File in Your Project​

Most projects keep settings in a file named .env in the project folder. It holds one NAME=value setting per line:

.env
ANTHROPIC_API_KEY=sk-ant-your-key-here

The app loads the file when it starts. In Python this is done by libraries such as pydantic-settings or python-dotenv. Because the file holds a secret, it must never reach Git. Add it to your project's .gitignore file:

.gitignore
.env
tip

Commit a copy named .env.example that lists every setting with an empty or fake value. Other developers then know which settings to fill in, and the real key never leaves your computer.

Add Credits and Set a Spend Limit​

API usage is paid in advance with credits. A new account starts with a small amount of free credit. When the balance runs out, requests are refused until you add more. Credits and limits live on the Billing page at platform.claude.com/settings/billing.

Two kinds of limit protect you from a surprise bill:

  • Your tier's monthly spend cap. Every organization is on a usage tier. Anthropic lists a cap of $500 a month for Start, $1,000 for Build and $200,000 for Scale. Your tier and its rate limits appear on the Rate limits page.
  • Your own spend limit. On the Billing page, in the Spend limits section, select Set limit (or Adjust limit if one is already set) and enter a monthly amount below your tier's cap. Setting one before you write any code is good practice. A bug that loops forever then costs you a few dollars, not a few hundred.

You pay per token. A token is a chunk of text of roughly three-quarters of a word, and input (what you send) and output (what Claude writes) have separate prices. As of October 2026, Anthropic's pricing page lists these prices per million tokens:

ModelInputOutput
Claude Opus 5.5$4$20
Claude Sonnet 5.5$2$10
Claude Haiku 5.5$0.10$0.50

On Claude Opus 5.5, a paragraph of text in and a paragraph out (about 200 tokens each way) costs roughly half a cent. The smaller models cost less.

Rotate, Disable or Delete a Key​

Keys do not need to live forever, and short-lived keys are safer. On the API keys page, each key's menu offers:

  • Disable pauses the key. It can be turned back on with Re-enable.
  • Delete removes the key for good. An expired key can only be deleted.

To rotate a key (swap it for a fresh one without downtime):

  1. Create a new key, as in Steps 2 to 5.
  2. Put the new key wherever your app reads it, for example your .env file, and restart the app.
  3. Check the app works, then delete the old key.

Rotate a key when it is about to expire, when someone who had it leaves the project, or whenever you think it may have leaked. Anthropic emails you 7 days before a key expires if the key was created to last at least 14 days, and 1 day before if it was created to last at least 7 days.

Common Mistakes​

MistakeWhat happensHow to avoid it
Expecting a Claude Pro or Max plan to cover API callsAPI calls fail or are billed separatelyTreat the Claude app and the Claude API as separate products, and add API credits in the Console
Selecting Done before copying the keyThe key can never be shown againCopy first, paste it somewhere safe, then select Done
Pasting the key into source codeAnyone who sees the code can spend your creditsRead it from ANTHROPIC_API_KEY or a .env file
Committing .env to GitThe key is published with your codeAdd .env to .gitignore before your first commit
Sharing one personal key with a team or a serverThe app stops working when that person leavesGive each developer their own key, and use a service account key for shared systems
Setting the variable in one terminal and running the app in anotherThe SDK cannot find the keyUse a .env file, or set the variable in the same terminal that runs the app

Troubleshooting​

ProblemLikely causeFix
Create key is greyed outYour role in the organization is not allowed to create keysAsk an organization admin to change your role, or to create the key for you
401 authentication_errorThe key is mistyped, disabled, deleted or expiredCheck you pasted the whole key with no spaces or quotes. If it is expired or deleted, create a new one.
Python says Could not resolve authentication method. Expected one of api_key, auth_token, or credentials to be set.The SDK found no key at allSet ANTHROPIC_API_KEY, or load your .env file before creating the client
400 invalid_request_error saying you reached your specified API usage limitsUsage hit the spend limit you set yourselfRaise or remove your spend limit on the Billing page
429 rate_limit_error with enforced_spend_limit_reachedYour organization reached its tier's monthly spend capWait until the 1st of next month (00:00 UTC), or use Request tier increase on the Rate limits page
A billing error, or requests refused with no credits leftThe credit balance is used upAdd credits on the Billing page

Frequently Asked Questions​

Is the Claude API free?​

Not beyond a trial amount. Anthropic gives new users a small amount of free credit to test the API. After that you pay per token, from credits you add in the Console. Creating API keys costs nothing.

Does my Claude Pro subscription include an API key?​

No. The Claude app plans and the Claude API are separate products with separate billing. Max and Team plans include some monthly API credits, but you still create keys and manage API usage in the Claude Console.

Can I see my API key again after I close the dialog?​

No. The Console shows the full key only once. If you lose it, create a new key and delete the old one.

How many API keys should I create?​

One per app, and per environment where it matters (for example, separate keys for development and production). Then you can see each app's usage and replace one key without breaking the others.

What does the sk-ant-usr- prefix mean?​

Every key starts with sk-ant-. In our tests, a personal key created from the API keys page started with sk-ant-usr-. Anthropic's documentation shows sk-ant-api03- in its examples. Either way, it is still a secret.

What is the Default workspace?​

A container for keys, usage and limits that every account has. You can create more workspaces later, for example one per client or per environment, and give each its own limits. Note that you cannot set custom limits on the Default workspace itself.

Conclusion​

Getting a Claude API key comes down to five moves:

  1. Sign in at platform.claude.com.
  2. Open API keys and select Create key.
  3. Choose Continue with an API key.
  4. Name the key, pick an expiry, link it to yourself and select Create key.
  5. Copy the key, which you see only once.

Keep it out of your code with an environment variable or a .env file, set a spend limit, and rotate it before it expires.

The key is the first thing you need for Build an AI Lead Qualification Agent with Claude and Python — Part 1: Overview, Architecture and Your Claude API Key. That series uses it to turn raw sales inquiries into structured, prioritized leads.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.