Lesson

Getting Your First API Key

To talk to the Anthropic API, you need a VIP pass that tells Anthropic who you are and who to bill. This VIP pass is called an API Key.

Creating the Key

  1. Go to the Anthropic Console (console.anthropic.com). This is different from the main claude.ai chat interface. The Console is specifically for developers.
  2. Sign up or log in.
  3. You will need to add a payment method. Unlike the web interface, the API is not free to use indefinitely, though Anthropic often provides a small amount of free credits to new developers.
  4. Navigate to the API Keys section.
  5. Click Create Key. Give it a descriptive name like "Local Dev Environment."
  6. A long string of characters (starting with sk-ant-) will appear on your screen. Copy it immediately. For security reasons, you will never be able to see the full key again once you close that window.

The Number One Rule of API Keys

Never, ever, ever commit your API key to GitHub.

If you paste your API key directly into your code (e.g., const apiKey = 'sk-ant-123...') and push that code to a public GitHub repository, bots will scrape your key within seconds. Malicious actors will use your key to generate millions of tokens, and you will wake up to a massive credit card bill.

Storing Your Key Securely

Instead of putting the key in your code, you should store it in an Environment Variable.

If you are using Node.js, the standard practice is to use a .env file.

  1. Create a file named exactly .env in the root of your project.
  2. Add your key to this file like this: ANTHROPIC_API_KEY=sk-ant-123456789...
  3. Crucially: Create a .gitignore file and add .env to it. This tells Git to ignore your secret file so it never gets uploaded to GitHub.
  4. In your Node.js code, you will use a package like dotenv to read the key from the file into your code at runtime using process.env.ANTHROPIC_API_KEY.

Treat your API key exactly like you treat your bank password. If you ever suspect someone else has seen it, go back to the Anthropic Console and delete (revoke) the key immediately.

Ready to test your understanding? Take the quiz to reinforce what you learned.

© 2026 Ant Skillsv.26.07.07-23:01
Ant Skills - Lesson