# How to Get a Claude API Key (and What It Actually Costs)

By Ethan Rogers. Published 2026-11-25. 17 min read.
Canonical: https://ethanplus.ai/guides/how-to-get-claude-api-key

A Claude API key takes about two minutes to create. The part that trips people up is everything around it: the API is billed separately from your Claude subscription, the key is shown exactly once, and the price per request depends almost entirely on which model you pick.

I build agents and agent infrastructure every day, so I live on both sides of this. Some of what I build calls the Claude API directly and pays per token. Some of it, like Sellbird (my open source outreach platform, formerly called Harvey), is built to run on a Claude or Codex subscription instead. Knowing which bill a piece of work lands on is half of keeping costs sane. This guide covers getting the key, paying for it, testing it, and what it really costs, all checked against Anthropic's docs as of November 25, 2026.

> **The short version**
>
> 1. Sign in at [platform.claude.com](https://platform.claude.com/) and open **API keys** (`platform.claude.com/settings/keys`).
> 2. Click **Create key**, name it, pick an expiration, and copy the key. It starts with `sk-ant-` and is shown only once.
> 3. Buy credits on the **Billing** page (`platform.claude.com/settings/billing`).
> 4. Set `ANTHROPIC_API_KEY` in your environment and make a test call.
>
> | Model | Input / MTok | Output / MTok |
> | --- | --- | --- |
> | Claude Haiku 5.5 (prompts up to 100k tokens) | $0.10 | $0.50 |
> | Claude Sonnet 5.5 | $2 | $10 |
> | Claude Opus 5.5 | $4 | $20 |
> | Claude Fable 5.2 | $8 | $40 |
>
> Your Claude Pro or Max subscription does not pay for API calls. They are separate bills.

## What a Claude API key is

A Claude API key is a secret string that lets your code call Claude directly through the Claude API, instead of going through the chat app at claude.ai. Every request your code sends carries the key, and Anthropic bills the usage to the organization the key belongs to.

You need one if you are:

- **Building an app or agent** that calls Claude from your own code.
- **Using a tool that asks for an Anthropic key**, such as an IDE plugin, an automation platform, or an open source project.
- **Running Claude Code on pay-as-you-go billing** instead of a subscription.

You do not need one to chat with Claude, use Claude Code on a Pro or Max plan, or connect apps to Claude through connectors. Those all run on your claude.ai account.

## Subscription vs API: two different bills

This is the single biggest source of confusion, so I'll be blunt about it. A Claude subscription (Free, Pro, Max, Ultra, Team, Enterprise) and the Claude API are billed separately. Paying $20 a month for Pro gives you zero API credit.

| | Claude subscription | Claude API |
| --- | --- | --- |
| Where you manage it | claude.ai | Claude Console at platform.claude.com |
| How you pay | Flat monthly price per seat | Prepaid credits, charged per token |
| What it covers | Claude apps, Claude Code, Cowork | Your own code, tools that take a key, Claude Code with a key |
| Limits | Usage windows that reset | Rate limits by usage tier, and your credit balance |
| Credentials | Your claude.ai login | API keys (`sk-ant-...`) or other API credentials |

There is one overlap worth knowing. Per [Anthropic's support article on monthly API credits](https://support.claude.com/en/articles/17154008-monthly-api-credits-for-max-ultra-and-team-plans), Max, Ultra and Team plans include monthly Claude API credits once you link a Console organization: $100 a month on Max, $200 on Ultra, and on Team $20 per Standard seat and $100 per Premium seat, pooled and capped at $500 a month. Free, Pro and Enterprise are not eligible. Those credits expire at the end of each billing cycle, get used before any credits you buy, and per [the billing article](https://support.claude.com/en/articles/8977456-how-do-i-pay-for-my-claude-api-usage) can't be used in Claude Code or the Claude apps. You link the organization from claude.ai under Settings > Billing, and you can only link one.

If you are deciding which subscription to get in the first place, I broke that down in [Claude pricing explained](/guides/claude-pricing), and the Claude Code side specifically in [Claude Code pricing](/guides/claude-code-pricing).

## What you need before you start

- **An email address** to create a Claude Console account. This can be the same email as your claude.ai account, but the Console is its own product with its own billing.
- **A credit card.** Standard accounts pay by major credit card, per the [pricing docs](https://platform.claude.com/docs/en/about-claude/pricing).
- **The right role**, if you are joining an existing organization. If the **Create key** button is greyed out, your role probably doesn't allow key creation. Ask an admin.
- **A place to store the key.** A password manager or secrets manager, not a notes app and not your repo.
- **A terminal** for the test call, and Python 3 for the SDK example.

## Step 1: Create a Claude Console account

Go to [platform.claude.com](https://platform.claude.com/) and sign up, or sign in if you already have an account. The Console is where keys, billing, usage, workspaces and rate limits all live.

If your company already has a Console organization, ask to be invited instead of creating a new one. Two separate organizations means two separate bills and two sets of keys to track.


## Step 2: Open the API keys page

In the Console, go to **API keys**, or go straight to `platform.claude.com/settings/keys`. This page lists every key in the organization you can see, with its name, owner, workspace and expiration.


## Step 3: Create the key

Click **Create key** and fill in the dialog. Per [Anthropic's key docs](https://platform.claude.com/docs/en/get-api-key), you set four things:

- **Name.** Name it for what will use it: `sellbird-staging`, `laptop-dev`, `zapier-prod`. When you need to disable one later, you will be glad you did.
- **Expiration.** The presets are 3 hours, 1 day, 7 days or 30 days, plus a custom duration or **Never**. Expiration is set at creation and can't be changed afterward. Use **Never** only for keys you keep in a secrets manager and rotate yourself.
- **Linked account.** Yourself for a personal key, or a service account for anything shared. A personal key acts as you and stops working if you leave the organization. A service account key belongs to a workload, like a CI pipeline or a production agent, so it doesn't break when a person leaves.
- **Workspace.** Optional, but I recommend scoping the key to a workspace. Per the [authentication docs](https://platform.claude.com/docs/en/manage-claude/authentication), a key that isn't scoped to a workspace has to send an `anthropic-workspace-id` header on every request, or the API returns a 400 error.

There is also a legacy "workspace key" type. Anthropic recommends personal or service account keys instead, because those stop working automatically when the person or workload is removed.


## Step 4: Copy the key now

The Console shows the full key, which starts with `sk-ant-`, only once. Copy it straight into your password manager or secrets manager before you close the dialog. If you lose it, you can't view it again. You create a new one and disable the old one.

## Step 5: Add credits

A new key does nothing useful until the organization has money on it. Most organizations prepay. Per [Anthropic's billing article](https://support.claude.com/en/articles/8977456-how-do-i-pay-for-my-claude-api-usage):

1. Sign in with an Admin or Billing role.
2. Go to **Billing** (`platform.claude.com/settings/billing`).
3. Click **Buy credits** and enter an amount. Credits are available immediately.

Three details from the same article that are worth knowing before you load a big balance:

- **Credits expire one year from purchase**, and the date can't be extended.
- **Credit purchases are non-refundable.**
- **Auto-reload** buys more credits when your balance drops below a threshold you set. If your balance is already below the threshold when you turn it on, you are charged right away.

My advice: start small, turn on auto-reload with a modest target once you know your usage pattern, and set workspace spend limits for anything that runs unattended. An agent stuck in a loop is the classic way to burn a balance overnight.

What about free credits? Anthropic's pricing FAQ says "New users receive free credits to test the API." It does not publish an amount, so treat it as enough to test with, not to build on.


## Step 6: Set ANTHROPIC_API_KEY

The SDKs and the `ant` CLI read your key from the `ANTHROPIC_API_KEY` environment variable. On macOS or Linux:

```bash
export ANTHROPIC_API_KEY="sk-ant-api03-REPLACE-ME"
```

That lasts for the current terminal session. For a project, put it in a `.env` file that is listed in `.gitignore`, or better, load it from your secrets manager at runtime. For production, set it in your hosting provider's environment settings, never in code.

## Step 7: Make a test call with curl

This is the test request from [Anthropic's quickstart](https://platform.claude.com/docs/en/get-started), with a shorter prompt. It uses the current API version header and the current Opus model ID from the [models overview](https://platform.claude.com/docs/en/models/overview):

```bash
curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1000,
    "messages": [
      {"role": "user", "content": "Say hello in five words."}
    ]
  }'
```

The docs now also accept the key as `Authorization: Bearer <key>`. The `x-api-key` header still works and is what most examples you'll find use.

## Step 8: Make a test call with Python

Install the SDK in a virtual environment:

```bash
python3 -m venv .venv && source .venv/bin/activate
pip install anthropic
```

Then save this as `quickstart.py`:

```python
import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1000,
    messages=[
        {"role": "user", "content": "Say hello in five words."}
    ],
)

for block in message.content:
    if block.type == "text":
        print(block.text)
```

Run it with `python quickstart.py`. Notice there is no key in the file. The client picks it up from the environment, which is exactly how you want it.

## How you know it worked

- **curl returns JSON** with `"type": "message"`, a `content` array with Claude's text, and a `usage` block with `input_tokens` and `output_tokens`.
- **Python prints Claude's reply** and exits without an error.
- **The Console shows the request** in your usage and cost reporting shortly after.

If you get a 401, the key is wrong, expired or disabled. If you get a 400 about `anthropic-workspace-id`, the key isn't scoped to a workspace. Both are in the troubleshooting table below.

## Using your Claude API key in Claude Code

Claude Code can run on an API key instead of a subscription. Per the [Claude Code authentication docs](https://code.claude.com/docs/en/authentication):

- **Set `ANTHROPIC_API_KEY`** before you run `claude`. In interactive mode, Claude Code asks once whether to use the key and remembers your answer. You can flip it later with the "Use custom API key" toggle in `/config`, which only appears while the variable is set. In non-interactive mode (`claude -p`), the key is always used when present.
- **Or sign in with your Console account** at the `/login` prompt. The recommended option signs you in without creating an API key at all. The legacy option creates a Console key for you.
- **The key beats your subscription.** In Claude Code's credential order, `ANTHROPIC_API_KEY` ranks above your claude.ai login. If you have Max and also have the variable set in your shell profile, you are paying per token without realizing it once you approve the key. Run `/status` to see which credential is active, and `unset ANTHROPIC_API_KEY` to fall back to the subscription.

Two related settings worth knowing: `apiKeyHelper` runs a script that returns a key, which is the clean way to pull a short-lived key from a vault, and `/usage` shows an estimated session cost in dollars for API users.

For a full walkthrough of getting Claude Code itself running, see [how to install Claude Code](/guides/how-to-install-claude-code).


## Claude API pricing per model

All prices below are per million tokens (MTok), in USD, from [Anthropic's pricing page](https://platform.claude.com/docs/en/about-claude/pricing) on November 25, 2026. A token is a chunk of text, very roughly three quarters of a word in English.

| Model | API model ID | Input | Output | Cache hit | Batch input / output |
| --- | --- | --- | --- | --- | --- |
| Claude Fable 5.2 | `claude-fable-5-2` | $8 | $40 | $0.20 | $4 / $20 |
| Claude Opus 5.5 | `claude-opus-5-5` | $4 | $20 | $0.20 | $2 / $10 |
| Claude Sonnet 5.5 | `claude-sonnet-5-5` | $2 | $10 | $0.10 | $1 / $5 |
| Claude Haiku 5.5, prompt up to 100k tokens | `claude-haiku-5-5` | $0.10 | $0.50 | $0.01 | $0.05 / $0.25 |
| Claude Haiku 5.5, prompt over 100k tokens | `claude-haiku-5-5` | $0.50 | $2.50 | $0.05 | $0.25 / $1.25 |

Older models are still available at their own prices. Opus 5 and Opus 4.5 through 4.8 are $5 input and $25 output, Sonnet 5 is $2 and $10, Sonnet 4.5 and 4.6 are $3 and $15, and Haiku 4.5 is $1 and $5. Opus 4.1, Opus 4 and Sonnet 4 are retired on the Claude API.

What the table doesn't show:

- **All four current models have a 1M token context window** and 128K max output, per the [models overview](https://platform.claude.com/docs/en/models/overview). Long context is billed at the standard rate on Claude 4.6 and later models, except Haiku 5.5, which charges the higher rate once a prompt goes over 100,000 tokens.
- **The tokenizer changed.** Claude 4.7 and later models use a tokenizer that produces about 30% more tokens for the same text. Comparing per-token prices across generations undersells the difference a little.
- **Thinking is billed as output.** Current models use adaptive thinking, and those thinking tokens count at the output rate.
- **Tools add tokens.** Tool definitions and tool results count as input. Web search costs an extra $10 per 1,000 searches.
- **US-only inference costs 1.1x.** Setting `inference_geo` to `"us"` on Claude 4.6 and later models applies a 1.1x multiplier to everything.
- **Fast mode costs double.** Opus 5.5 fast mode is $8 input and $40 output; Fable 5.2 fast mode is $16 and $80.

### What a request actually costs

Plain arithmetic at list price, for a request with 2,000 input tokens and 500 output tokens:

| Model | Input cost | Output cost | Per request | Per 10,000 requests |
| --- | --- | --- | --- | --- |
| Haiku 5.5 | $0.0002 | $0.00025 | $0.00045 | $4.50 |
| Sonnet 5.5 | $0.004 | $0.005 | $0.009 | $90 |
| Opus 5.5 | $0.008 | $0.01 | $0.018 | $180 |
| Fable 5.2 | $0.016 | $0.02 | $0.036 | $360 |

The same job costs 80 times more on Fable than on Haiku. That ratio, not the absolute price, is what should drive your architecture.

## How to cut your Claude API costs

These are the levers, roughly in the order they matter.

### Pick the cheapest model that does the job

Anthropic's own guidance is Haiku for simple tasks, Sonnet for most production workloads and Opus for the most complex reasoning. The [models overview](https://platform.claude.com/docs/en/models/overview) currently suggests starting with Opus 5.5 for most workloads and reaching for Fable 5.2 only when Opus at higher effort still falls short.

In practice, the biggest savings I've seen come from splitting a workload by difficulty rather than picking one model for everything. Classification, extraction and routing go to Haiku. The bulk of the work goes to Sonnet or Opus. The expensive model only touches the judgment calls. I wrote about the same idea on the OpenAI side in [how I cut my Astra usage](/blog/how-i-cut-my-astra-usage): keep the expensive model on the decisions and hand the busy work to something cheaper. The principle carries over to the Claude API unchanged.

### Turn on prompt caching

If your requests share a long prefix (a system prompt, tool definitions, a document, a conversation history), cache it. Per the [pricing docs](https://platform.claude.com/docs/en/about-claude/pricing):

- A 5-minute cache write costs 1.25x the base input price. A 1-hour cache write costs 2x.
- A cache hit costs 0.1x the base input price on most models, and less on the newest ones: 0.05x on Opus 5.5 and Sonnet 5.5, and 0.025x on Fable 5.2.
- A 5-minute cache pays for itself after one read. A 1-hour cache pays for itself after two.

The easiest way in is automatic caching: add a single `cache_control` field at the top level of the request and the API manages the breakpoints as the conversation grows. For agents, which resend the whole conversation on every turn, caching is usually the largest single saving available.

### Use the Batch API for anything that can wait

The [Batch API](https://platform.claude.com/docs/en/build-with-claude/batch-processing) gives 50% off both input and output in exchange for asynchronous processing. Nightly enrichment, bulk classification, evals, content backfills: if a human isn't waiting on the answer, batch it. Batch and caching discounts stack. Fast mode is not available with batch.

### Keep prompts and outputs tight

Set `max_tokens` to what you actually need. Trim the system prompt. Don't send the full conversation history when a summary will do. Use the [token counting endpoint](https://platform.claude.com/docs/en/build-with-claude/token-counting) to see what a request will cost before you ship it at scale.

### Put a ceiling on spend

Set workspace spend limits in the Console, give each project its own workspace so you can see where money goes, and watch the Cost page for the first week of anything new.

## Keep your Claude API key safe

A leaked key is someone else running up your bill. Anthropic's [authentication docs](https://platform.claude.com/docs/en/manage-claude/authentication) are clear on the basics, and I'd add a few of my own.

- **Never commit a key.** Not to a private repo, not "just for now." Put `.env` in `.gitignore` before you create it, and use a pre-commit secret scanner.
- **Use a secrets manager** for anything beyond your own laptop: your hosting provider's encrypted environment variables, 1Password, Doppler, AWS Secrets Manager, or similar.
- **Never put a key in browser code.** Anthropic's docs say to call the API from your back end. Anyone can read a key shipped in a web page.
- **One key per app or environment**, named clearly, so you can kill one without breaking the rest.
- **Set an expiration.** Anthropic emails the creator before longer-lived keys expire, so short lifetimes are less painful than they sound.
- **Rotate safely.** Create the new key, deploy it, confirm requests succeed, then disable or delete the old one. On the API keys page, **Disable** is reversible and **Delete** is permanent.
- **If a key leaks, disable it first** and ask questions after. You can turn on IP allowlisting to limit where a key works at all.
- **Consider not using a static key.** For local development, Anthropic now recommends signing in with the `ant` CLI (`ant auth login`), which stores a short-lived token. For CI and cloud workloads, Workload Identity Federation swaps static keys for short-lived tokens from your identity provider.

## Common problems and fixes

| Problem | Fix |
| --- | --- |
| **Create key** button is disabled | Your role can't create keys. Ask an organization admin to change your role or create a service account key for you. |
| 401 `authentication_error` | The key is mistyped, expired, disabled or deleted. Check the API keys page. Expired keys can't be reactivated; create a new one. |
| 400 error about `anthropic-workspace-id` | The key isn't scoped to a workspace. Add the header with your workspace ID, or create a workspace-scoped key. |
| Requests fail after the key worked yesterday | Check your credit balance on the Billing page, then the key's expiration date. |
| `ANTHROPIC_API_KEY` is set but the SDK can't find it | You set it in a different terminal session or shell profile. Run `echo $ANTHROPIC_API_KEY` in the same shell that runs your code. |
| Claude Code is billing your API account instead of your Max plan | `ANTHROPIC_API_KEY` is set and you approved it. Run `unset ANTHROPIC_API_KEY`, then check `/status`. |
| Lost the key | You can't view it again. Create a new key, update your apps, and disable the old one. |
| Model not found | Use a current model ID from the [models overview](https://platform.claude.com/docs/en/models/overview), such as `claude-sonnet-5-5`. Retired models return errors on the Claude API. |
| Calls from a web page fail with a CORS error | Call the API from your server, not the browser. |

## Fine print

- Prices change. Everything above is from Anthropic's docs on November 25, 2026. Check the [pricing page](https://platform.claude.com/docs/en/about-claude/pricing) before you budget.
- Rate limits depend on your usage tier. See [rate limits](https://platform.claude.com/docs/en/api/rate-limits) for your account.
- Using Claude through Amazon Bedrock, Google Cloud or Microsoft Foundry means authenticating and paying through that platform instead.

## Frequently asked questions

### Is there a free Claude API key?

The key itself is free to create. Using it costs money. Anthropic says new users receive free credits to test the API, but it doesn't publish the amount. Max, Ultra and Team subscribers get monthly API credits once they link a Console organization. Pro and Free plans don't.

### Does my Claude Pro or Max subscription include API access?

No. The subscription and the API are billed separately. Max, Ultra and Team plans do include a monthly API credit allowance, but you have to link a Console organization to use it, and it expires each billing cycle.

### How much does the Claude API cost?

It depends on the model. Per million tokens, Haiku 5.5 is $0.10 input and $0.50 output for prompts up to 100,000 tokens, Sonnet 5.5 is $2 and $10, Opus 5.5 is $4 and $20, and Fable 5.2 is $8 and $40. Batch requests are half price, and cached input is a small fraction of the base price.

### What is the Claude token cost for a typical request?

A request with 2,000 input tokens and 500 output tokens costs about $0.009 on Sonnet 5.5 and $0.018 on Opus 5.5 at list price. On Haiku 5.5 it's under a tenth of a cent.

### Where do I find my Claude API keys?

In the Claude Console at `platform.claude.com/settings/keys`. You can see each key's name, owner and expiration there, but not the full secret, which is only shown once when the key is created.

### Can I use my Claude API key with Claude Code?

Yes. Set `ANTHROPIC_API_KEY` before you run `claude` and approve the key when asked. Usage is then billed per token to your Console organization instead of counting against a subscription.

### How do I rotate a Claude API key?

Create a new key, deploy it everywhere the old one was used, confirm requests succeed, then disable or delete the old key on the API keys page. Disabling is reversible; deleting is not.

### Why is my Claude API key not working?

The most common causes are a typo, an expired or disabled key, an empty credit balance, or a key that isn't scoped to a workspace and is missing the `anthropic-workspace-id` header. The troubleshooting table above covers each one.

## Need an agent built on the API?

Getting a key is the easy part. Designing an agent that picks the right model for each step, caches what it should, and doesn't quietly burn credits at 3 a.m. is where most of the work is. That's what I build. If you want a custom agent running on the Claude API for your business, [get in touch](/contact). And if you want to connect your own tools to Claude first, start with [how to connect any app to Claude with MCP](/guides/connect-apps-to-claude-mcp).
