Skip to main content

How to Get a Claude Code API Key: Console Setup Guide

A step-by-step guide to generating an API key in the Claude Console and connecting it to Claude Code with an environment variable.

By
🌐 This article was machine-translated and may contain inaccuracies. Read the Korean original if in doubt.

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
🟢 Model references match the current lineup · Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). This notice changes only when Anthropic ships a new model.

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 (

🟢 Model references match the current lineup · Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). This notice changes only when Anthropic ships a new model.
0/M input, $50/M output tokens). The one-time
🟢 Model references match the current lineup · Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). This notice changes only when Anthropic ships a new model.
00 credit applied only to the Fable 5 transition and is not offered for 5.1. Some coding and debugging requests may be answered by an Opus model due to a security classifier (both models). See the Fable 5.1 guide and the Fable 5 availability guide for details.

① Sign in to Console ② API Keys page ③ Create Key click ④ Copy & store key ⑤ Set env variable ⑥ Approve in Claude Code

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

  1. 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.
  2. 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.
    Console path: platform.claude.com/settings/keys
    Success looks like: you see a list of existing keys (empty if this is your first one).
  3. 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.
  4. 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.
  5. 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).
    export ANTHROPIC_API_KEY="paste-your-key-here"
    Success looks like: running echo $ANTHROPIC_API_KEY in the same terminal window prints the key you just set.
  6. 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.
    OS / methodInstall command
    macOS, Linux, WSL
    curl -fsSL https://claude.ai/install.sh | bash
    Windows PowerShell
    irm https://claude.ai/install.ps1 | iex
    Windows CMD
    curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
    Homebrew (macOS)
    brew install --cask claude-code
    WinGet (Windows)
    winget install Anthropic.ClaudeCode
    Then run:
    cd your-project
    claude
    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.

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.

Subscription login Pricing: flat monthly (Pro/Max) Setup: just log in via claude Best for: everyday personal use Upkeep: session stays logged in API key Pricing: pay per token used Setup: Console key + env variable Best for: automation, CI/CD, teams Upkeep: reissue when it expires

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 separator means you ran the CMD command in PowerShell. Seeing 'irm' is not recognized as an internal or external command means you ran the PowerShell command in CMD. Your prompt shows PS C:\ in PowerShell and just C:\ 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.

Was this helpful?

Keep reading