Artificial IntelligenceAnthropicClaude API

How to Get Your Anthropic API Key and Set Up the Console

TT
TopicTrick
How to Get Your Anthropic API Key and Set Up the Console

Every Claude integration — whether it is a simple script, a production web application, or a sophisticated AI agent — starts with the same thing: an API key. The API key is what authenticates your requests to Anthropic's servers and tells the platform who is making each call.

If you have used other cloud APIs before — AWS, Stripe, Twilio — the process here will feel very familiar. If this is your first experience with an AI API, do not worry. The setup is genuinely simple, and this guide will take you through every step.

By the end, you will have a working API key, a working development environment, and the knowledge to make your first Claude API call.


What You Need Before You Start

The prerequisites for this setup are minimal:

  • An email address: Used to create your Anthropic account
  • A payment method: The API is not free — you pay per token used. You will add a credit card and set a usage limit. Anthropic will not charge you until you have actually used the API.
  • A code editor: Visual Studio Code is the most widely used choice. Any editor that supports your preferred language works fine.
  • Python or Node.js installed: For your first API call. Python 3.8+ or Node.js 18+ are both supported.

Cost Control from the Start

The Anthropic API is pay-as-you-go with no monthly minimum. A typical development session — hundreds of test API calls — costs well under $1. Set a monthly spend limit in the Console to ensure you never receive an unexpected bill regardless of how much you experiment.


    Step 1: Create Your Anthropic Account

    If you already have a Claude.ai account, you can use the same credentials for the Console. If not, create a new account.

    1. Go to console.anthropic.com in your browser
    2. Click Sign Up if you do not have an account, or Log In if you do
    3. Sign up using your email address or your Google account
    4. Verify your email if you signed up with email and password

    Once logged in, you will land on the Anthropic Console — the developer dashboard that gives you access to your API keys, usage statistics, billing, and the Workbench tool.


    Step 2: Navigate the Console

    The Anthropic Console has several sections worth knowing from the start.

    Workbench

    The Workbench is the Console's built-in prompt testing tool. It lets you send messages to Claude directly from your browser without writing any code. You can choose which model to use, write a system prompt, adjust parameters like max_tokens and temperature, and see the exact API request and response.

    The Workbench is invaluable for developing and testing prompts before you hard-code them into your application. Always prototype here first.

    API Keys

    The API Keys section is where you create and manage your authentication credentials. Each key is a long string beginning with sk-ant- that you include in every API request.

    Usage

    The Usage section shows your token consumption broken down by model, date, and API key. This is how you monitor what your application is actually spending.

    Settings

    Settings contains your organisation details, workspace configuration, and spend limit controls.


    Step 3: Generate Your API Key

    1. In the Console, click API Keys in the left navigation menu
    2. Click Create Key
    3. Give your key a descriptive name — for example dev-local for your development machine or production-app for a deployed application
    4. Click Create Key to generate it
    5. Copy the key immediately. Anthropic shows you the full key only once at creation time. If you lose it, you must create a new one.

    Never Commit API Keys to Version Control

    An API key is a secret credential. If you push it to a public GitHub repository, automated bots scan the internet for exactly these patterns and can begin using your key within minutes. Always store API keys in environment variables or a secrets manager — never in your source code.


      Step 4: Set a Spend Limit

      Before writing a single line of code, set a monthly spend limit to protect yourself from accidental runaway usage.

      1. In the Console, go to Settings then Limits
      2. Set a monthly spend limit appropriate for your current stage. For learning and development, £10–20 per month is generous. The API will stop accepting requests if you hit the limit, preventing unexpected bills.
      3. Consider also setting per-key limits if you are working in a team environment

      Step 5: Add Your Payment Method

      1. Go to Settings then Billing in the Console
      2. Add a credit or debit card
      3. Anthropic bills in arrears — you pay for what you used in the previous billing period, not upfront

      You will not be charged for simply having an account or an API key. Charges only accrue when your code makes actual API calls that consume tokens.


      Step 6: Set Up Your Local Environment

      Now that you have an API key, set up your development environment to use it securely.

      Store Your Key as an Environment Variable

      On your local machine, store the API key in an environment variable called ANTHROPIC_API_KEY. This is the name the official Anthropic SDKs look for automatically.

      On macOS or Linux, add this to your ~/.zshrc or ~/.bashrc file:

      export ANTHROPIC_API_KEY="sk-ant-your-key-here"

      Then run source ~/.zshrc to apply it to your current session.

      On Windows, set it via System Properties or PowerShell:

      [System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-your-key-here", "User")

      Install the Python SDK

      If you are using Python:

      pip install anthropic

      Install the Node.js SDK

      If you are using JavaScript or TypeScript:

      npm install @anthropic-ai/sdk

      Use a .env File for Projects

      For application projects, use a .env file rather than a global environment variable. Store your key as ANTHROPIC_API_KEY=sk-ant-... in the .env file, use a library like python-dotenv or dotenv for Node.js to load it, and add .env to your .gitignore file immediately. This keeps your key local to the project and out of version control.


        Step 7: Verify Your Setup

        Make a simple test call to confirm everything is working. Here is the minimal verification script in Python:

        python
        1import anthropic 2 3client = anthropic.Anthropic() 4 5message = client.messages.create( 6 model="claude-sonnet-4-6", 7 max_tokens=256, 8 messages=[ 9 {"role": "user", "content": "Say hello and confirm you are working."} 10 ] 11) 12 13print(message.content[0].text)

        If your environment variable is set correctly, this script will print a greeting from Claude. If it raises an AuthenticationError, your key is not being found — double-check the environment variable name and restart your terminal to ensure the variable is loaded.


        Understanding Workspaces and Multiple Keys

        As your usage grows, you may want to create multiple API keys for different purposes:

        • Separation of concerns: Keep separate keys for development, staging, and production environments. This way, if a key is compromised, only one environment is affected.
        • Usage monitoring: Separate keys generate separate usage reports, making it easy to understand which application or team is responsible for which costs
        • Key rotation: Security best practice dictates rotating API keys periodically. Having separate keys per environment makes rotation easier to manage without disrupting unrelated services

        Workspaces in the Console let you group keys and set spend limits at the workspace level — useful for teams where different projects should have independent budget controls.


        Rate Limits: What to Expect

        The Anthropic API enforces rate limits to prevent misuse and manage capacity. As a new account, you will start on a lower tier with the following kinds of limits:

        • Requests per minute (RPM): Maximum number of API calls per minute
        • Tokens per minute (TPM): Maximum number of tokens processed per minute
        • Monthly spend limit: The limit you set yourself in Settings

        For learning and development, the starting limits are more than sufficient. As your usage and spend grow, Anthropic automatically increases your limits. If you need higher limits for a specific launch or integration, you can request increases through the Console.


        Summary

        You now have everything you need to start building with the Claude API:

        • An Anthropic Console account with billing configured
        • An API key stored securely as an environment variable
        • A spend limit protecting you from runaway costs
        • The Anthropic SDK installed and verified

        The next step is understanding what to do with that API key — making real, structured API calls and understanding the response format.

        In our next post, we put this setup to work: Your First Claude API Call: Python and JavaScript Quickstart.


        This post is part of the Anthropic AI Tutorial Series. Don't forget to check out our previous post: Getting Started with Claude.ai: Your First Conversation.