How to Get a Claude API Key and Make Your First Call
Get a Claude API key in the Console, add credits and make your first call with Python or curl. Steps checked against Anthropic docs on 16 October 2026.
You get a Claude API key in the Claude Console: open the API keys page at platform.claude.com/settings/keys and click Create key. Anthropic's docs say the full key starts with sk-ant- and is shown only once. A first call then takes one request to https://api.anthropic.com/v1/messages.
Quick answer: Sign in at platform.claude.com, click Create key on the API keys page, add credits under Settings > Billing, then run the Python or curl example below. Free? No. Anthropic bills API use through prepaid credits.
What do you need before you start?
You need a Claude Console account, an API key and credits on the account. The quickstart lists a Console account and an API key as its two prerequisites.
Your claude.ai chat login is not the same thing. Anthropic's Help Center says a Claude account and a Console account can share one email address but operate independently. Sign in to the Console with the same email you use for Claude to keep things simple.
For the Python method you also need Python 3 and a terminal. For the curl method you need only a terminal. If a terminal is new to you, our guide to installing Claude Code on Mac and Windows shows how people open one.
How do you get a Claude API key? (Method 1: the Console)
Create the key on the API keys page of the Claude Console. The steps below follow Anthropic's Get your Claude API key page.
- Go to the Claude Console at platform.claude.com and sign in. If you have no account, create one.
- Open the API keys page at
platform.claude.com/settings/keys. - Click Create key.
- Name the key, for example "first-test".
- Choose an expiration. The authentication docs list presets of 3 hours, 1 day, 7 days or 30 days, a custom duration, or Never. For a test, pick a short one.
- Set Linked account to yourself. You can also pick a workspace to scope the key to.
- Copy the key and store it somewhere safe, such as a password manager or secrets manager. The Console shows it only once. If you lose it, create a new key.
Anthropic describes three key types. A personal key acts as you and stops working if you leave an organization. A service account key is for workloads such as CI pipelines or production services. A workspace key is a legacy key with no owner. The docs say to use a personal key for your own development and a service account key for anything shared.
If the Create key button is disabled, your role may not allow it. Ask an organization admin to change your role or to create a service account key.
How do you add credits so the call works?
Buy credits on the Billing page. Anthropic says API and playground usage is billed through prepaid usage credits, and you can't call the API after they run out. The steps come from the Help Center billing article.
- Log in to the Console with an Admin or Billing role.
- Go to Settings > Billing.
- Click Buy credits.
- Enter the amount and confirm. Purchased credits are available immediately.
Anthropic's Academy course says you need to purchase some credits before you start. The Help Center article for new Console organizations says to add usage credits and enter payment details.
How do you make your first Claude API call with Python? (Method 1 continued)
Install the anthropic package, set your key as an environment variable and run a short script. The commands follow the Get started with Claude quickstart. The SDK reads ANTHROPIC_API_KEY automatically, per the key docs.
- Open a terminal.
- Set your key. On Mac or Linux, run the first line below with your own key in place of the placeholder.
- Create a project folder and a virtual environment, then install the SDK (the next three lines).
- Create a file called
quickstart.pyand paste the script from the second block. - Run
python quickstart.py.
export ANTHROPIC_API_KEY="your-api-key-here"
mkdir claude-quickstart && cd claude-quickstart
python3 -m venv .venv && source .venv/bin/activate
pip install anthropic
On Windows, verify this step: Anthropic's quickstart shows only the Mac and Linux export command. PowerShell uses a different command to set an environment variable, so confirm the syntax in Microsoft's documentation.
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from your environment
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1000,
messages=[
{
"role": "user",
"content": "In two sentences, explain what an API key is.",
}
],
)
for block in message.content:
if block.type == "text":
print(block.text)
Every call uses messages.create with three things, per the Academy course: a model, a token limit and a list of messages. The response content is a list of blocks, so the script loops through them and prints the text ones.
The quickstart uses claude-opus-5-5. This script uses claude-sonnet-5-5, a model ID listed in the models overview, because it costs less per token. Swap in any ID from that page.
Method 2: How do you make the first call with curl?
Send a POST request to https://api.anthropic.com/v1/messages with your key and the anthropic-version header. This needs no Python. Anthropic's API overview marks anthropic-version (for example 2023-06-01) and content-type: application/json as required.
- Set the key with the
exportline from the Python method. - Paste the command below into the same terminal and press Enter.
curl https://api.anthropic.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1000,
"messages": [
{"role": "user", "content": "In two sentences, explain what an API key is."}
]
}'
The key docs say direct HTTP requests send the key in the x-api-key header. The API overview also lists an Authorization: Bearer <token> header and calls x-api-key a legacy fallback that is still supported. Both appear in current docs, so use x-api-key as above, and switch only if Anthropic retires it.
You can also try the API in a browser first. The overview points to the Console playground for that.
Once you have a working call, you can send its output into other tools. See how to write Apps Script with Claude or how to pull API data into Google Sheets.
Which method should you choose?
Use Python if you plan to build something, and curl if you only want to confirm the key works. Both hit the same endpoint with the same key.
| Method | Cost | Difficulty | Limits | Best for |
|---|---|---|---|---|
| Python SDK | Pay per token from prepaid credits | Low, needs Python 3 | SDK retries transient errors twice by default | Building scripts and apps |
| curl | Pay per token from prepaid credits | Lowest, one command | You handle retries yourself | Checking a key in one minute |
| Console playground | Billed through credits, per the Help Center | Lowest, no code | Browser only | Trying prompts before coding |
The retry detail comes from Anthropic's error docs. The playground billing detail comes from the Help Center, which says playground usage is billed through prepaid credits.
What's free and what costs money?
Creating a key is a Console action with no price listed in the docs. Calls cost money, billed per million tokens (MTok). A token is a small chunk of text, roughly a word fragment.
Prices below are from the models overview, as of 16 October 2026.
| Model | API ID | Input per MTok | Output per MTok |
|---|---|---|---|
| Claude Fable 5.1 | claude-fable-5-1 | $10 | $50 |
| Claude Opus 5.5 | claude-opus-5-5 | $4 | $20 |
| Claude Sonnet 5.5 | claude-sonnet-5-5 | $2 | $10 |
| Claude Haiku 5.5 | claude-haiku-5-5 | From $0.10 | From $0.50 |
What does the example cost? With max_tokens set to 1000 and Sonnet 5.5 output at $10 per MTok, the reply can cost at most 1,000 / 1,000,000 x $10 = $0.01. A prompt of about 20 tokens adds 20 / 1,000,000 x $2 = $0.00004. So a test call costs about one cent or less.
Other money rules, per the Help Center:
- Failed requests are not charged. A request that your client abandons mid-way may still be charged.
- Purchased credits expire one year after purchase, and purchases are non-refundable.
- Auto-reload buys credits when your balance falls below a threshold you set. Find it under Set up auto-reload in the Credit balance section of the Billing page.
- Max and Team plans include monthly API credits, claimed by linking a Console organization. No payment method is needed to claim them, per the Console setup article.
Spend caps also apply. As of 16 October 2026, the rate limits page lists monthly caps of $500 (Start tier), $1,000 (Build) and $200,000 (Scale). New organizations may begin in an Evaluation tier with lower limits. You can set your own lower cap: on the Billing page, find Spend limits and click Adjust limit (or Set limit).
Last checked: 16 October 2026.
What can go wrong, and how do you fix it?
Most first-call failures are key or billing problems. The error docs define each code.
| Error | What it means | Fix |
|---|---|---|
401 authentication_error | Problem with your API key, such as malformed, revoked or expired | Re-copy the key. If it expired, create a new one. Expired keys cannot be reactivated. |
402 billing_error | Problem with billing or payment information | Check payment details in the Claude Console. |
403 permission_error | Your key lacks permission for the resource | Check organization access and workspace settings in the Console. |
429 rate_limit_error | Rate limit hit, or the tier's monthly spend cap reached | Slow down. A spend-cap 429 has no retry-after header and keeps failing until access resumes. |
400 invalid_request_error | Bad format or content. Also returned when you hit a spend limit you set | Check the JSON body. Raise or remove your own spend limit if that is the cause. |
529 overloaded_error | The API is temporarily overloaded | Retry after a short wait. |
Two more points. If you have multiple workspaces and your key works on more than one, you must also send the anthropic-workspace-id header on each request, per the key docs. And if your balance hits zero, calls stop until you add credits.
Is this allowed, and how do you keep the key safe?
Yes, calling the API with your own key is the intended use. Treat the key like a password, because anyone holding it can spend your credits.
- Do not paste the key into code you share. The Academy course says to keep it in a
.env.localfile so it stays out of version control, and that hardcoded keys are how they end up leaked on GitHub. - Use a personal key for your own work. Anthropic says to use a service account key for anything shared.
- Short expirations limit the damage of a leak, but the authentication docs say expiration is not a substitute for secret hygiene. Disable or delete any key you suspect has leaked.
- Your use is governed by Anthropic's Commercial Terms and Usage Policy, which the Console docs link in their footer. Read them before building a product on the API.
What's still unclear?
A few details are not pinned down in Anthropic's public pages.
- Header choice. The key docs name
x-api-key, while the API overview listsAuthorization: Bearerfirst. Both are described as working. - Model names change. The quickstart uses
claude-opus-5-5, and the models overview recommends starting with Opus 5.5 for most workloads. Older guides online show earlier model IDs and pricing. Check the models overview before copying an ID. - Tier rules. Some third-party guides describe tiers that depend on deposits. Anthropic's rate limits page now lists Start, Build and Scale tiers. Check the Rate limits page in your Console (
platform.claude.com/usage/limits) for your own tier. - Windows setup. Anthropic's quickstart does not show the Windows environment variable step, so confirm it on your own machine.
This guide is based on Anthropic's documentation. We have not run each step ourselves.
Frequently asked questions
Where do I find my Claude API key?
Claude API keys are created and managed in the Claude Console, on the API keys page at platform.claude.com/settings/keys. Anthropic's docs say the full key, which starts with sk-ant-, is shown only once at creation. If you lose it, you cannot view it again, so create a new key instead.
Does my Claude Pro or Max subscription include API access?
A Claude account and a Console account use the same email but operate independently, per Anthropic's Help Center. API use is billed through prepaid credits. Max and Team plans include monthly API credits, which you claim by linking a Console organization to your plan. Those credits cannot be used in Claude Code or the Claude apps.
Which model ID should I use for a first call?
As of 16 October 2026, Anthropic's models overview lists claude-fable-5-1, claude-opus-5-5, claude-sonnet-5-5 and claude-haiku-5-5. The quickstart uses claude-opus-5-5. This guide uses claude-sonnet-5-5 because it is priced at $2 per million input tokens and $10 per million output tokens, below Opus 5.5.
Why does my call return a 401 error?
A 401 authentication_error means there is a problem with your API key. Anthropic's error docs give malformed, revoked and expired as examples. Keys have an expiration chosen at creation, and an expired key cannot be reactivated. Check that the key was copied in full, then create a new key if needed.
Do Claude API credits expire?
Yes. Anthropic's Help Center says purchased credits expire one year from the purchase date, the expiration date cannot be extended, and all credit purchases are non-refundable. Monthly credits that come with Max and Team plans are separate: they expire at the end of each billing cycle.
Sources
- Get your Claude API key, Anthropic (Claude Platform Docs) (2026-10-16)
- Get started with Claude, Anthropic (Claude Docs) (2026-10-16)
- API overview, Anthropic (Claude Platform Docs) (2026-10-16)
- Models overview, Anthropic (Claude Platform Docs) (2026-10-16)
- How do I pay for my Claude API usage?, Anthropic (Claude Help Center) (2026-10-16)
- I created a Claude Console organization - how do I start using the Claude API?, Anthropic (Claude Help Center) (2026-10-16)
- Can I have a Claude account and a Console account?, Anthropic (Claude Help Center) (2026-10-16)
- Authentication, Anthropic (Claude Platform Docs) (2026-10-16)
- Rate limits, Anthropic (Claude Platform Docs) (2026-10-16)
- Claude API errors, Anthropic (Claude Platform Docs) (2026-10-16)
- Your first API call (Claude Platform 101), Anthropic Academy (2026-10-16)