To get an API key for Claude Code, sign in to the Claude Console, open the API Keys screen under Account Settings, generate a new key, and connect it to Claude Code by setting it as an environment variable — a value your terminal remembers and shares with programs. This guide walks through the whole process, from creating a Console account to confirming the connection works, and takes about 10 minutes.
🟢 Model references match the current lineup · model notice · Fable subscription
Fable 5 and 5.1 subscription (updated September 7, 2026): Claude Fable 5.1, released September 1, 2026, is the current Fable model and Fable 5 is now legacy. Plan terms are the same for both — Max and Team Premium plans include Fable at up to 50% of the weekly usage limit; Pro and Team Standard use usage credits (
What you'll be able to do
By the end of this guide you'll have your own API key generated in the Claude Console, connected to your terminal, and running Claude Code without the interactive login screen. The whole process — Console sign-up, key creation, environment variable setup, and verification — takes roughly 10 minutes.
Before you start
Check these items first so you don't get stuck partway through.
- A Claude account you can create with an email address (you can sign up right from the Console login screen if you don't have one)
- A computer where you can open a terminal — macOS, Linux, WSL, or Windows
- The Claude Code CLI (command-line tool) installed, or ready to install — instructions are in the steps below
- No existing Claude Pro or Max subscription is required. An API key can be issued and used entirely on its own, separate from a subscription
Quick terms
- API (Application Programming Interface) — a defined set of rules that lets programs exchange data with each other.
- API key — a secret string you submit with every request to prove who you are. Treat it like a password and never expose it publicly.
- Console — the web dashboard for generating API keys and checking usage and limits. This guide uses the address platform.claude.com; the same account system is also referred to by the name console.anthropic.com.
- Environment variable — a value stored in your terminal session that any program running there can read. Keeping your API key as an environment variable, rather than hardcoding it, is the safer approach.
- CLI (Command Line Interface) — a tool you operate by typing commands instead of clicking. Claude Code's terminal program is a CLI.
Step-by-step: generate the key and connect it
- Sign in to the Claude Console — go to platform.claude.com in your browser and sign up or log in with your email. Success looks like: you land on the Console dashboard.
- Open the API Keys page under Account Settings — find the API Keys section inside Account Settings (path: platform.claude.com/settings/keys). The exact menu wording may shift slightly as the Console's UI changes, so look for whatever button lets you create a new key.
Success looks like: you see a list of existing keys (empty if this is your first one).Console path: platform.claude.com/settings/keys - Create a new key — click the create-key button, name the key, and choose its expiration when you create it. Success looks like: the new key's full string is displayed once on screen.
- Copy the key and store it safely — copy the full key string immediately and save it somewhere secure, such as a password manager. Warning: once you navigate away from this screen, you may not be able to view the full key again, so copy it now.
- Set it as an environment variable in your terminal — open a terminal and run the following, replacing the placeholder with the key you just copied (macOS/Linux shown).
Success looks like: runningexport ANTHROPIC_API_KEY="paste-your-key-here"echo $ANTHROPIC_API_KEYin the same terminal window prints the key you just set. - Install Claude Code (if you haven't) and run it — install with the command for your OS, then move into your project folder and run
claude.
Then run:OS / method Install command macOS, Linux, WSL curl -fsSL https://claude.ai/install.sh | bashWindows PowerShell irm https://claude.ai/install.ps1 | iexWindows CMD curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmdHomebrew (macOS) brew install --cask claude-codeWinGet (Windows) winget install Anthropic.ClaudeCode
Success looks like: since ANTHROPIC_API_KEY is set, Claude Code skips the interactive login screen and instead asks you to approve the key. Approve it, and the Claude Code prompt appears, ready for your first request.cd your-project claude
Subscription login vs. API key: what's the difference
Claude Code can authenticate either with a Claude subscription (Pro/Max) login or with an API key — you only need one of the two. For everyday personal use in a terminal, subscription login alone is enough; for automation, CI/CD (pipelines that build and test code automatically), or connecting multiple services, an API key is what you need.
Common sticking points and fixes
Most install and connection problems trace back to mixing up Windows shells or forgetting to set the environment variable.
- Install command fails on Windows — seeing
The token '&&' is not a valid statement separatormeans you ran the CMD command in PowerShell. Seeing'irm' is not recognized as an internal or external commandmeans you ran the PowerShell command in CMD. Your prompt showsPS C:\in PowerShell and justC:\in CMD — check that, then rerun the matching command. - Claude Code keeps showing the login screen — the environment variable isn't set in your current terminal session. Check with
echo $ANTHROPIC_API_KEY(macOS/Linux) or$env:ANTHROPIC_API_KEY(PowerShell); if it's empty, rerun the export command from step 5. Opening a new terminal window resets this, so you'll need to set it again each time. - API calls return an authentication error — often caused by stray whitespace pasted around the key, or by pasting a key created under a different organization or workspace. Recheck the key on the Console's API Keys page, and generate a fresh one if needed.
Next steps: what else you can do with this key
The same API key works for Claude Code and for calling the Messages API directly in your own programs. For example, you can try a direct call from your terminal with curl:
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-opus-5",
"max_tokens": 1000,
"messages": [
{"role": "user", "content": "Hello, is this working?"}
]
}'
If you want to split keys across projects, use the Console's Workspaces feature to segment them, and check your organization's current request limits (requests per minute, tokens per minute, and monthly spend) on the Console's Limits page — the same page lets you request a higher limit if you need one. Browse the guides section for more on getting the most out of Claude Code.
Frequently asked questions
Q. Do I need an API key to use Claude Code at all?
No, not necessarily. If you're using Claude Code personally in a terminal, logging in with a Claude subscription (Pro/Max) is enough. An API key is what you need for automation or CI/CD scenarios that call for pay-per-use authentication.
Q. Can I view my API key again after I create it?
You can always see the list of keys on the Console's API Keys page, but the full key string is typically shown only once, right after creation. Copy it before leaving that screen and store it somewhere safe.
Q. Is API usage billed separately from a subscription plan?
Yes. The API charges per token used, which is a different pricing model from a flat monthly Claude Pro or Max subscription. Exact per-model rates can change, so check the official pricing page for current numbers.
Q. Where can I check the usage limits on my key?
The Console's Limits page shows your organization's current requests-per-minute, tokens-per-minute, and monthly spend limits, and lets you request a higher limit from the same page if you need one.
Related articles
- Claude API Keys: Getting a Key, Pricing & Usage (2026)
- Getting Started with the Claude API: Your First Call (Developer Intro)
- Claude API Error Handling, Retries & Rate Limits: Complete Guide
- Claude API Vision — How to Send Images and PDFs as Input
- Is the Claude API Free? Free Credits, Free Alternatives & Pricing (2026)