API Keys in Claude

API Keys in Claude

An API key is the secret password that lets your software talk to Claude. This guide explains what a key is, how it differs from your normal Claude login, how to create and protect one, how to limit the damage if it leaks, and the habits that keep your account and your budget safe.

Imagine a hotel key card. It does not carry your name or your face, yet it opens the door to your room, and anyone who finds it can walk in and use the room at your expense. An API key behaves the same way. It is a long string of characters that proves a request to Claude is allowed, and the system does not ask who is holding it. That is why a key is powerful, convenient, and dangerous in the wrong hands. Treating it like a hotel key, or better, like a credit card number, is the foundation of using it well.

1What an API Key Is

It is a secret credential that identifies and authorizes the software making a request.

API stands for application programming interface. It is a way for one program to ask another program to do something. When a developer wants an app, a website, or a script to use Claude, the program sends requests to the Claude API. Each request must prove that it is allowed to use the service, and the usual proof is an API key.

Anthropic’s documentation describes API keys as static secrets that you generate in the Claude Console and send with every request. Because the key is the proof, whoever holds it can use the service as you, and the usage is billed to your organization. This is why keys must be kept private.

Simple Analogy

A library card lets you borrow books, and the library records the loans on your account. If someone steals your card, they can borrow books in your name and you are responsible for the late fees. An API key is a library card for Claude, with money instead of late fees.

i
Remember

A key is not a username or a hint. It is the whole proof of identity, so anyone who has it can act as you.

2Two Doors: Claude Chat and the Claude API

Your Claude login and an API key are different things.

Many people first meet Claude through the chat apps, where you sign in with an account and type into a conversation. Developers who build their own products use a different route, the Claude API, which is managed through the Claude Console. The API uses keys, not your chat login. The two are set up separately, and they have separate billing. A paid chat subscription does not automatically give you API access, and usage through the API is generally billed through the Console. Anthropic has offered some plans with included API credits, but these details change, so check the current pricing and help pages.

TopicClaude chat appsClaude API
Who uses itPeople chatting and working with ClaudeDevelopers connecting Claude to their own software
How you sign inAn account loginAn API key created in the Claude Console
How it is billedBy subscription planBy usage, through the Console, with plan-specific exceptions
Where you manage itSettings inside the appThe Claude Console, under the API keys page
flowchart LR
    P["A person"] --> A["Claude chat app
account login"] D["A developer's software"] --> K["API key
from the Claude Console"] A --> C["Claude"] K --> C
FIG 1 — Chat uses an account login, and the API uses a key
!
Common Mistake

Looking for an API key inside the chat app’s settings. Keys are created in the Claude Console, which is a separate place.

3Why Keys Deserve Careful Protection

A leaked key can cost money, expose data, and be hard to trace.

Because a key acts as you, a leaked key lets a stranger run requests on your account. The first risk is cost: they can use Claude as much as the account allows, and you pay. The second risk is data: requests and responses that pass through your key may contain private information. The third risk is trust and reputation, since misuse of your key could be tied to your organization. Finally, finding out afterwards who used a leaked key and for what can take effort.

Risk 1

Unexpected Charges

Someone else can run up usage on your account until the key is stopped.

Risk 2

Exposed Information

Prompts and results sent through the key may contain customer or company data.

Risk 3

Service Disruption

Heavy misuse can use up limits and make your own application stop working.

Risk 4

Hard Investigations

It can be difficult to prove who used a stolen key, so prevention is far better than clean-up.

Simple Analogy

Leaving a signed blank cheque on a park bench is risky even if most passers-by are honest. You only need one dishonest person. A key left in a public place has the same problem.

4Getting a Key Step by Step

The process is quick, but each choice matters.

According to Anthropic’s documentation, you sign in to the Claude Console, open the API keys page under settings, and choose to create a key. You give the key a name, choose an expiration, and choose which account it is linked to. You can also choose a workspace to limit where the key works. After creating it, you copy the key and store it safely, because the full secret may not be shown to you again.

1

Sign in to the Claude Console

Use the Console, not the chat app, and make sure you are in the right organization.

2

Open the API keys page

Find the keys area in settings, where existing keys are listed and new ones are created.

3

Name the key by its purpose

Use a clear name such as the project and the environment, so it can be identified later.

4

Choose the account type and expiration

Pick a personal key for your own development or a service account key for shared work, and set an expiration that fits.

5

Scope it to a workspace if possible

Limit the key to the workspace it needs, so it cannot reach other projects.

6

Copy it straight into safe storage

Place it in a secrets manager or a protected environment setting, and do not leave copies lying around.

i
Practical Tip

If the button to create a key is greyed out, your role may not allow it. Ask an organization administrator to change your role or create a service account key for your work.

5Kinds of Keys

Different keys serve different purposes, and choosing the right one reduces risk.

Anthropic’s documentation describes personal keys, service account keys, and an older type called workspace keys. It also describes separate Admin API keys used for organization management. Personal and service account keys are generally preferred, because they stop working automatically when the linked account is removed from the organization, which prevents forgotten keys from lingering.

Key typeLinked toBest forGood to know
Personal keyYouYour own development and testingStops working if you leave the organization
Service account keyA non-person accountShared systems, servers, and automationDoes not depend on one individual staying employed
Workspace keyA workspace, with no ownerOlder setupsDescribed as legacy, and keeps working after its creator leaves
Admin API keyThe organizationManaging members, workspaces, and keys by automationNot used to call Claude, and it should be guarded even more carefully
Simple Analogy

A staff badge tied to one employee stops working when they leave. A shared master key does not, which is why it needs stricter rules. Personal and service account keys act like badges that expire with their owners.

!
Important

Admin keys can manage other keys and members, so they are more sensitive than ordinary keys. Only the people who truly need them should have them.

6Expiration and Rotation

Keys should not live forever.

When you create a key, the documentation says you can choose an expiration, from short presets to a custom duration or no expiration, and that the choice is set at creation and cannot be changed afterwards. A shorter life limits the window in which a stolen key is useful. Keys without an expiration are meant for cases where you store them in a secrets manager and rotate them yourself.

Rotation means replacing an old key with a new one on a schedule, and then retiring the old one. A regular rotation habit means that even a key you never knew was exposed will eventually stop working. The usual approach is to create the new key, deploy it to the application, confirm everything works, and then delete the old key.

flowchart TD
    A["Create a new key"] --> B["Deploy it to the application"]
    B --> C["Confirm everything still works"]
    C --> D{"Working?"}
    D -- "Yes" --> E["Delete the old key"]
    D -- "No" --> F["Fix the deployment
and keep the old key until ready"] F --> B
FIG 2 — A safe rotation replaces the key without breaking your application

Choose shorter lives for riskier uses

Use short expirations for testing and demos, and longer ones only where you have a managed process.

Keep a calendar for rotation

Set a regular reminder, such as every few months, and rotate on that schedule.

Remove keys no longer in use

Delete old keys from finished projects so there are fewer secrets to protect.

7Workspaces: Keeping Projects Apart

A workspace is a boundary that limits what a key can reach.

Workspaces let an organization separate teams, projects, or environments, such as testing and production. Keys can be scoped to a workspace, so that a key created for a test project cannot be used for the production system. This is the digital version of giving different keys to different rooms, instead of one master key for the building.

Benefit 1

Limited Blast Radius

If a key leaks, the damage stays within the workspace it belongs to.

Benefit 2

Clear Tracking

Usage can be seen by workspace, which makes it easier to understand where costs come from.

Benefit 3

Separate Environments

Testing keys and production keys can be kept apart, so experiments cannot disturb the real system.

Benefit 4

Tidy Access

Team members see only the workspaces and keys that are relevant to them.

i
Good Habit

Use one key per application and per environment. When something goes wrong, you can stop exactly one key without stopping everything.

8Roles and Who Can Create Keys

Not everyone in an organization should be able to create keys.

Organizations assign roles that decide what each member can do. Anthropic’s documentation notes that if the create-key button is disabled, your role may not allow it, and you should ask an administrator. This is a feature, not an obstacle. Limiting who can create keys reduces the number of secrets floating around and makes it easier to know who is responsible for each one.

Good practiceWhy it helps
Give key creation only to people who build with the APIFewer people hold secrets that could leak
Use service accounts for shared systemsKeys do not depend on one person and are easier to manage
Keep admin access smallAdmin keys and roles can control everything else
Review member access regularlyPeople who left or changed roles should lose access promptly

9Storing Keys Safely

The safest place for a key is somewhere that is not in your code.

Anthropic’s documentation shows keys being provided to programs through an environment setting, and notes that its software development kits read a standard setting named for the Anthropic API key automatically. This keeps the key out of the program’s source code. For larger systems, a dedicated secrets manager, which is a protected vault with controlled access, is the better choice, since it also supports rotation and records who accessed a secret.

Option 1

Environment Settings

Provide the key to the program from outside its code. Simple and widely used, but protect the machine and the files that hold them.

Option 2

A Secrets Manager

A protected vault with access control, logging, and support for rotation. Best for teams and production.

Option 3

Your Platform’s Secret Store

Many hosting and build platforms include a place to store secrets safely for deployments.

Avoid

Hard-Coding in Source Files

Writing the key inside code or configuration files that are saved, shared, or uploaded is one of the most common causes of leaks.

Simple Analogy

You keep valuables in a safe, not taped to the front door. A secrets manager is the safe, and hard-coding a key in a file is the tape on the door.

10How a Key Is Used, in Plain Words

You rarely type the key into requests by hand.

Most developers use official software libraries from Anthropic. These libraries read the key from the environment and attach it to each request automatically, so the key never needs to be written into the program. If you make requests directly, the key is sent with each request in a header, as the documentation describes. If your key works across several workspaces, you also have to say which workspace a request is for.

The key point for beginners is that the key travels with every request, over a secure connection, from a place you control to Claude’s servers. That is why the code that uses the key should run in a place you control, such as a server, and not in a place that strangers can inspect.

1

The key is stored safely outside the code

It lives in an environment setting or a secrets manager on your server.

2

Your program reads it when it runs

The official libraries pick it up automatically from the standard setting.

3

It is sent with each request

The key proves the request is allowed, over a secure connection.

4

Claude responds and usage is recorded

The work is counted against the key’s workspace and your organization’s account.

11Things You Should Never Do with a Key

Most leaks come from a small number of avoidable habits.

Never save a key in a public code repository

Public code hosting is scanned constantly by automated tools, including those run by bad actors. A key committed there can be found within minutes.

Never put a key in front-end or app code that users can inspect

Anything shipped to a browser or a phone can be opened and read. Keep keys on a server you control and let your front end talk to your server.

Never share a key in chat, email, tickets, or screenshots

Messages are copied, forwarded, and stored. A key pasted into a message may live for years in places you do not control.

Never reuse one key everywhere

A single key across many projects means one leak affects everything, and you cannot stop one project without stopping all.

Never send keys to people who do not need them

If a contractor or colleague needs access, create a separate key or use a service account, and remove it afterwards.

!
Watch Out

Private code repositories are safer than public ones, but they are still not secret vaults. Keys saved in code history can leak later if access changes.

12Keep Keys Out of AI Chats and Prompts Too

An AI assistant is a place where secrets get copied without anyone noticing.

When you ask an AI assistant to help debug your code, it is easy to paste in a whole file, including a key that is written in it. This puts the secret into a conversation history, and possibly into logs, shared chats, or exported documents. Even with good privacy practices, a secret should not be in a place that does not need to hold it. This applies to Claude and to any other AI tool.

The safer habit is to replace the real key with an obvious placeholder before sharing code, and to keep the real key in your environment. If you realize you have pasted a real key into a chat, treat it as exposed: replace it and delete the old one. Also check that files you upload do not contain keys hidden in settings or configuration.

Replace keys with placeholders

Before pasting code, swap the real secret for a clearly fake placeholder value.

Check configuration files before uploading

Settings files, notebooks, and logs often hold secrets in plain sight.

Treat a pasted key as exposed

If a real key ends up in a chat or a shared document, rotate it right away.

Use secret scanning tools

Tools that scan your files and history for secrets can catch accidents before they spread.

13Watching Usage and Spending

Early warning turns a disaster into a small problem.

Usage through the API is billed by how much you use, so unexpected activity shows up as unexpected cost. Make a habit of looking at usage in the Console, and set up any limits and alerts that the Console offers for your organization and workspaces. Look for sudden spikes, activity at odd hours, and usage from keys you do not recognize. Naming keys clearly helps you spot which one is behaving strangely.

Spikes
Sudden jumps in usage that you did not plan
Timing
Activity at hours when nobody is working
Unknown
Keys you do not recognize or no longer use
1

Review usage on a regular schedule

Check the Console weekly at first, and then monthly once you know what normal looks like.

2

Set limits and alerts where available

Use the controls the Console provides to cap spending and warn you early.

3

Investigate anything unusual immediately

If a key looks busy for no reason, assume it may be compromised until proven otherwise.

i
Helpful Idea

Billing for the API is separate from chat subscriptions, so check the Console, not just your chat account, when you look for charges.

14If a Key Leaks: Act Fast

Speed matters more than perfection when a secret is exposed.

If you think a key has been exposed, do not wait to confirm. Guidance in public security resources, and Anthropic’s own approach as described in third-party summaries, is to revoke the key right away, create a replacement, and store the new one safely. Anthropic is reported to take part in a secret scanning partnership with a major code hosting platform, which can deactivate keys found in public repositories, but that is a safety net and not a plan. Keys exposed anywhere else need your action.

1

Revoke the key at once

Delete it in the Console. Delete it rather than only disabling it.

2

Create a replacement

Make a new key with the right scope and a sensible expiration.

3

Remove the secret from where it leaked

Take it out of code, files, messages, and documents, and replace it with a reference to the secure store.

4

Deploy the new key safely

Update your applications and confirm they work before you consider the incident handled.

5

Check usage for the exposure window

Review activity during the time the key was exposed, and look for unusual use.

6

Learn and prevent a repeat

Find how it happened, and fix the process, for example by adding secret scanning to your workflow.

!
Important

Removing a key from a file does not remove it from history. A key that was ever public must be treated as compromised, even after the file is fixed.

15Beyond Static Keys: Shorter-Lived Credentials

For larger systems, there are safer patterns than a key that lives for months.

Anthropic’s authentication documentation describes more than one way to authenticate. Alongside API keys, it describes workload identity federation, where software proves its identity through a trusted platform and receives short-lived credentials instead of a long-lived key. Credentials that expire in minutes or hours leave an attacker very little time. The documentation suggests API keys as the quick way to start, and the other methods as options for more advanced setups.

ApproachStrengthTrade-off
API keySimple and quick to startA long-lived secret that must be protected and rotated
Short-lived credentials through federationCredentials expire quickly, so a leak is less usefulMore setup and a better understanding of your platform
Simple Analogy

A hotel key card that works for one night is less dangerous to lose than a permanent master key. Short-lived credentials are the one-night card.

16Good Habits for Teams

A team needs a few simple rules that everyone follows.

Habit 1

One Owner per Key

Every key has a named owner and a clear purpose, so someone is accountable for it.

Habit 2

An Inventory

Keep a list of keys, their workspaces, owners, and expiration dates, and review it regularly.

Habit 3

Automatic Secret Scanning

Scan code and history for leaked secrets as part of your normal workflow.

Habit 4

A Leak Response Plan

Write down who does what in the first hour after a suspected leak, and practice it.

Habit 5

Off-boarding Checks

When someone leaves, remove their access and rotate any shared keys they knew.

17Real-World Scenarios

Familiar situations show how the rules apply.

A student builds a small chatbot

The student creates a personal key with a short expiration, keeps it in an environment setting on their own computer, and never uploads the project with the key inside. When the project ends, they delete the key.

A startup launches a product

The team creates separate workspaces for testing and production, and a service account key for the production server. The key is stored in a secrets manager and rotated on a schedule.

A developer pastes code into a chat for help

They notice the file contains a real key, swap it for a placeholder before sharing, and keep the real one in their environment. Had they pasted it, they would have rotated the key straight away.

A key is found in a public repository

The team revokes it immediately, creates a new one, reviews usage during the exposure window, and adds secret scanning to prevent a repeat.

A contractor needs temporary access

The organization creates a separate, short-lived key scoped to one workspace for the contractor, and deletes it when the contract ends.

A manager notices an odd spike

Usage jumps overnight. The manager checks which key is responsible, revokes it, and investigates before restoring service with a new key.

18Advantages and Trade-offs of API Keys

Keys are simple and flexible, with responsibilities attached.

Advantages

  • Quick to create and easy to start building with.
  • Work with official libraries and standard tooling.
  • Can be scoped to workspaces and given expirations.
  • Easy to revoke and replace when something goes wrong.
  • Let each application and environment have its own credential.

Disadvantages / Trade-offs

  • A leaked key gives immediate access and costs money.
  • Long-lived keys need rotation and careful storage.
  • It is easy to leak a key by accident in code or chats.
  • Keys do not identify the person using them.
  • Larger systems may need more advanced credential methods.

19Common Mistakes and Anti-patterns

These habits cause most key leaks.

ANTI-PATTERN-01 Avoid
Problem

Writing the key directly in code or a configuration file that is saved with the project.

Why It’s Harmful

Anything saved with the project can be copied, shared, or uploaded, and the key travels with it.

Correct Approach

Keep keys in environment settings or a secrets manager, and keep them out of files that are committed or shared.

ANTI-PATTERN-02 Avoid
Problem

Using the same key for every project and every environment.

Why It’s Harmful

One leak exposes everything, and you cannot stop one project without disrupting the others.

Correct Approach

Create separate keys per application and environment, scoped to workspaces.

ANTI-PATTERN-03 Avoid
Problem

Putting a key in browser or mobile app code so the app can call the API directly.

Why It’s Harmful

Anyone can open the app’s code and read the key, then use it on their own account’s cost.

Correct Approach

Keep the key on a server you control, and let your app talk to that server instead.

ANTI-PATTERN-04 Avoid
Problem

Pasting code with a real key into chats, tickets, or screenshots.

Why It’s Harmful

The secret is copied into places you do not control and may remain for a long time.

Correct Approach

Use placeholders when sharing, and rotate any key that has been pasted anywhere by mistake.

ANTI-PATTERN-05 Avoid
Problem

Never checking usage, and leaving old keys active after projects finish.

Why It’s Harmful

Misuse goes unnoticed, and forgotten keys remain as open doors for years.

Correct Approach

Review usage regularly, set limits and alerts, and delete keys you no longer need.

20A Simple Routine for Key Safety

Follow these steps every time you use a key.

1

Create a key with a clear purpose

Name it, scope it to a workspace, and choose a sensible expiration.

2

Store it outside your code

Use an environment setting or a secrets manager, and never save it in shared files.

3

Use it only from places you control

Run the code on a server, not in a browser or app that users can inspect.

4

Keep it out of chats and screenshots

Use placeholders when you share code, and treat any pasted key as exposed.

5

Watch usage and rotate on schedule

Check the Console regularly, set limits where possible, and replace keys periodically.

6

Revoke fast and delete what you do not use

If a key leaks, delete it at once and make a new one, and remove old keys when projects end.

Store
Outside your code, in a safe place
Scope
One key per app and environment
Rotate
Replace on schedule and after any exposure

21Myths and Facts

A few popular beliefs about keys are only partly true.

MythFact
My Claude chat subscription includes an API key.Chat and API are separate. Keys are created in the Console, and API usage is generally billed separately, with plan-specific exceptions to check.
A private repository is a safe place for a key.It is safer than a public one, but it is not a vault. Keys can leak through history and changes in access.
If I delete the key from the file, I am safe.It remains in history and in any copies. Treat a once-exposed key as compromised and replace it.
Nobody would bother to find my small project’s key.Automated tools scan for keys all the time, regardless of how big the project is.
A key proves who I am as a person.A key proves only that the request carries the secret. Anyone with it can act as you.
I can safely put a key in my website’s code.Anything sent to a browser can be read. Keep keys on a server.
Keys never need to be replaced.Regular rotation and expiration limit the damage from unnoticed exposure.

22Frequently Asked Questions

Quick answers to the questions beginners ask most.

Q1What is a Claude API key?

It is a secret credential created in the Claude Console that lets your software make requests to the Claude API. Whoever holds it can use the API as your account.

Q2Where do I get one?

In the Claude Console, on the API keys page in settings. It is separate from the chat apps. Follow the current instructions in Anthropic’s documentation.

Q3Is it the same as my Claude login?

No. Your login is for the chat apps, and an API key is for software that calls the API. They are managed and billed separately.

Q4Which kind of key should I choose?

A personal key for your own development and a service account key for shared systems are generally preferred, since they stop working when the linked account is removed.

Q5Where should I store it?

In an environment setting or, better, a secrets manager. Never in source files that are shared, uploaded, or committed.

Q6Can I put the key in my website or mobile app?

No. Anything delivered to a user’s device can be inspected. Keep the key on a server and have your app talk to that server.

Q7Should I paste my key into an AI chat for debugging?

No. Replace it with a placeholder first. If you pasted a real one, rotate it right away.

Q8What do I do if my key leaks?

Revoke it immediately in the Console, create a replacement, remove the leaked copy from where it appeared, deploy the new key, and review usage for the exposure window.

Q9How often should I rotate keys?

On a regular schedule that fits your risk, and immediately after any suspected exposure. Choosing an expiration at creation also helps.

Q10Why can’t I create a key?

Your role may not allow it. Ask an organization administrator to change your role or to create a service account key for your work.

Q11Where can I see current details?

In Anthropic’s official documentation for the Claude Console and the API, since steps, roles, and options can change.

23Summary and Key Takeaways

An API key is the secret that lets your software use Claude, and it works like a credit card number: whoever holds it can spend as you. Keys are created in the Claude Console, separate from your chat login and usually billed separately. Choose the right type, give each key a clear purpose, scope it to a workspace, and set an expiration. Store it outside your code in an environment setting or a secrets manager, run the code that uses it on a server you control, and keep it out of public repositories, front-end code, chats, and screenshots. Watch usage, rotate on a schedule, and if a key ever leaks, revoke it at once and replace it. For larger systems, consider shorter-lived credentials, and always check Anthropic’s current documentation.

“Treat an API key like a credit card number, and never like a harmless label.”

Key Takeaways

  • A key is a full proof of access — anyone who holds it can use the API as your account and run up your bill.
  • Chat and API are separate — keys come from the Claude Console and are billed separately from chat subscriptions, so check the current terms.
  • Choose and scope carefully — prefer personal or service account keys, scope them to workspaces, and set expirations.
  • Store keys outside your code — use environment settings or a secrets manager, and keep keys out of repositories, front-end code, and shared files.
  • Keep keys out of chats — use placeholders when sharing code with people or AI tools, and treat any pasted key as exposed.
  • Watch and rotate — review usage, set limits and alerts, rotate on a schedule, and delete keys you no longer use.
  • Revoke fast when leaked — delete the key at once, create a replacement, clean up the leak, and review usage during the exposure window.