Claude API key: how to get an Anthropic API key, and what it costs
Get a Claude API key, also called an Anthropic API key, in five steps, see what a request costs on it, and run the same SDK code on one key for every model.
How to get a Claude API key
A Claude API key, also called an Anthropic API key, comes from the Claude Console at platform.claude.com. Creating one is free. Every request on it bills from prepaid credit, so the last step is buying some.
- Sign in to the Claude Console at platform.claude.com, or create an account. Keys live only in the Console; a Pro or Max plan on claude.ai does not create one.
- Open the API keys page (platform.claude.com/settings/keys).
- Click Create key. Name it, choose an expiration and set Linked account to yourself or a service account. You can also scope it to one workspace.
- Copy the key. It starts with
sk-ant-, and the Console shows it once. Put it in a secrets manager or an environment variable before you close the dialog. - Buy credit. In Settings, then Billing, click Buy credits. With no credit on the organization, requests stop until you add more.
Steps 1 to 4 are from Anthropic's Get your Claude API key docs and step 5 from its API billing article, both read 2026-10-18. If the Create key button is greyed out, your role in the organization can't create keys; an admin can change the role or make a service account key for you.
Which Anthropic API key type to pick
- Personal key. Acts as you and stops working if you leave the organization. Use it for your own development.
- Service account key. Belongs to a service account, for CI pipelines, production services and agents. Use it for anything shared.
- Workspace key. The legacy type: no owner, tied to the workspace it was made in, and it keeps working after its creator leaves. Anthropic's docs recommend the other two.
Use the key in code
Set it as an environment variable. Anthropic's SDKs read ANTHROPIC_API_KEY on their own, and a raw HTTP request sends it in the x-api-key header. A key that works in more than one workspace also needs the anthropic-workspace-id header on each request.
export ANTHROPIC_API_KEY="sk-ant-api03-..."import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY (and ANTHROPIC_BASE_URL if set)
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=256,
messages=[{"role": "user", "content": "Say ok."}],
)
print(message.content[0].text)import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic(); // reads ANTHROPIC_API_KEY (and ANTHROPIC_BASE_URL if set)
const message = await client.messages.create({
model: 'claude-sonnet-5-5',
max_tokens: 256,
messages: [{ role: 'user', content: 'Say ok.' }],
});
console.log(message.content);Use that exact name. The SDKs read ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and ANTHROPIC_BASE_URL; a variable called CLAUDE_API_KEY does nothing unless your own code reads it and passes it in as api_key.
An export lasts as long as the terminal it was typed in. To keep ANTHROPIC_API_KEY set, write it to your shell profile (~/.zshrc on macOS, ~/.bashrc on most Linux setups) or, on Windows, store it with setx. Open a new terminal afterwards; the old one keeps the old environment. In a project, a .env file listed in .gitignore does the same job for tools that load one.
# macOS and Linux: add the line to your shell profile
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-..."' >> ~/.zshrc
# Windows PowerShell: stored for new terminals
setx ANTHROPIC_API_KEY "sk-ant-api03-..."Claude API key or a Claude plan
A key and a plan pay for different things, and a plan doesn't come with a key.
| What it pays for | How it bills | Claude Code | |
|---|---|---|---|
| Pro or Max plan | Claude on web, desktop and mobile, plus Claude Code | Monthly, from $17, with 5-hour and weekly limits | Yes, by signing in |
| Anthropic API key | The API, the Console playground and Claude Code | Per token, from prepaid Console credit | Yes, through ANTHROPIC_API_KEY |
| UplinkSwitch key | The API for all 81 models on the list | Per token, from prepaid credit from $10 | Yes, with the Claude Code guide |
Plan and Console terms from claude.com/pricing and the billing article, read 2026-10-18.
What a request costs on a Claude API key
The key is free; the tokens are not. One chat request of 2,000 input and 500 output tokens, at Anthropic's list price and at ours, on the three current Claude models:
| Model | List in / out | Ours in / out | One request, list | One request, here |
|---|---|---|---|---|
| Claude Opus 5.5 | $4.00 / $20.00 | $2.10 / $6.00 | $0.018 | $0.0072 |
| Claude Sonnet 5.5 | $2.00 / $10.00 | $1.20 / $3.00 | $0.009 | $0.0039 |
| Claude Haiku 5.5 | $0.10 / $0.50 | $0.06 / $0.15 | $0.0005 | $0.0002 |
USD per million tokens, then USD for one request. Ours from the live catalog; list is the price on the developer's pricing page, the read date on each model page.
Sonnet 5.5 is $1.20 in and $3.00 out here, against $2.00 and $10.00 at list: 40% under on input and 70% on output. Every Claude model and its cached rate is on the Claude API pricing hub, and a long-document request is worked in Claude API cost per request.
Where to find your Claude API key
The API keys page lists every key with its name, but not the full secret. The Console shows that once, at creation, and even the Admin API returns only a partly redacted hint. A lost key can't be recovered: create a new one and replace it where the old one was set.
When a new Claude API key doesn’t work
The error type in the response says which part is wrong (Anthropic's API errors page, read 2026-10-18):
- 401 authentication_error. The key is malformed, revoked or past the expiration you chose. Check for a stray quote or space and that the variable is named
ANTHROPIC_API_KEY. - 402 billing_error. Something is wrong with the billing or payment details; Settings, then Billing in the Console shows what.
- 403 permission_error. The key can't use that resource. Check the organization and workspace settings, and send
anthropic-workspace-idif the key spans workspaces. - 400 invalid_request_error. On a key that worked before, usage may have reached a spend limit set on the organization or workspace.
Every response from an UplinkSwitch key, errors included, carries an x-uplink-request-id header to look the request up.
Keep the key safe
Anyone holding the key spends your credit. Keep it in an environment variable or a secrets manager, out of git and out of any code that runs in a browser. If it leaks, create a new key and remove the old one on the API keys page.
One key for Claude and every other model
An UplinkSwitch key runs the same Anthropic SDK code. Set ANTHROPIC_BASE_URL to ours and put our key in ANTHROPIC_API_KEY; the Python above runs unchanged. The Claude models answer Anthropic's Messages format, and all 81 models on the model list answer the OpenAI format, GPT, Gemini and DeepSeek included. A model costs the same in either SDK.
- Sign in to the console.
- Add credit, from $10. There is no subscription.
- Create a key. It is shown once, like Anthropic's, and can be paused, renamed or revoked later. A key can carry a monthly spend limit and a list of the models it may call.
- Set the two variables and run your code.
export ANTHROPIC_BASE_URL="https://api.uplinkswitch.com/v1"
export ANTHROPIC_API_KEY="sk-uplink-live-..."Check the key with one request that lists the models it can call:
curl https://api.uplinkswitch.com/v1/models -H "x-api-key: $ANTHROPIC_API_KEY"Every non-streamed answer carries a signed receipt naming the model that answered and what the request was billed, and /statements/verify checks it in the browser. Each model also gets a fixed test prompt once a day, with the results public on the real-model check.
A Claude API key in Claude Code
Claude Code reads ANTHROPIC_API_KEY too, and the variable wins over a Pro or Max login: with it set, Claude Code bills the key, not your plan (Anthropic's Help Center, read 2026-10-18). The Claude Code setup guide points it at an UplinkSwitch key, and Claude Code pricing puts each plan next to the per-token bill for the same month.
Questions
Is the Claude API key free? Creating it is. Requests bill from credit you buy first in the Console, and Anthropic's credit expires a year after purchase (its billing article). At list, $10 of credit is 1,111 chat requests of the size above on Sonnet 5.5; here it is 2,564.
How do I get a free Anthropic API key? The key costs nothing, but calls need credit. Max includes $100 or $200 a month of API credit and Team up to $500 pooled, once you link a Console organization to the plan (claude.com/pricing). That credit can't be spent in Claude Code.
Does Claude Pro come with an API key? No. Pro includes no API credit, and keys come only from the Console.
How do I find my Anthropic API key? On the API keys page, by name. The full key was shown only when it was created; if you didn't save it, create a new one.
Can one key call Claude, GPT and Gemini? Not an Anthropic key: it calls Claude. An UplinkSwitch key calls all 81 models on one prepaid balance.
Get a key in the console: prepaid from $10, no subscription, and each top-up locks its prices for 30 days.