How to Get a Claude API Key and Start Using It (With Examples)

Claude AI logo with the orange Anthropic starburst on a textured paper collage background

Claude, the AI model family from Anthropic, isn’t only available as a chat app. Developers can also use it through the Claude API to build chatbots, summarise documents, write code, analyse images and power their own apps. Getting started takes only a few minutes.

This guide shows you how to get an API key, choose a model, and send your first request using Python or a simple command-line call, with examples you can copy.

What you need

  • A Claude Console account (sign up at platform.claude.com).
  • An API key, which you create in the Console.
  • Credits or a payment method on your account, since API usage is billed separately from Claude’s chat subscriptions.
  • Python 3 installed, if you want to follow the Python example.

Step 1: Create your API key

  1. Go to platform.claude.com and sign up or log in.
  2. Add billing details or credits to your account.
  3. Open the API keys page in Settings.
  4. Click Create Key and give your key a name, so you can tell your keys apart later.
  5. Copy the key and store it somewhere safe. You won’t be able to see the full key again after you close the window.

Treat your API key like a password. Never paste it into public code, screenshots or GitHub repositories.

Step 2: Choose a model

Anthropic offers several models with different balances of intelligence, speed and cost. The current lineup includes:

  • Claude Opus: the most capable model, best for complex reasoning, coding and long tasks.
  • Claude Sonnet: a strong balance of intelligence and speed for most everyday applications.
  • Claude Haiku: the fastest and most affordable option, ideal for high-volume or real-time tasks.

Each model has an ID that you pass in your request, such as claude-opus-5-5. Models are updated regularly, so check the models overview in Anthropic’s documentation for the latest IDs and pricing.

Claude has come a long way since Anthropic introduced the Claude 3 family of Opus, Sonnet and Haiku models in 2024. If you’re curious how it all started, read our coverage of the Claude 3 AI models launch.

Step 3: Set your API key as an environment variable

The official SDKs read your key from an environment variable called ANTHROPIC_API_KEY. On macOS or Linux:

export ANTHROPIC_API_KEY="your-api-key-here"

On Windows (PowerShell):

$env:ANTHROPIC_API_KEY="your-api-key-here"

Step 4: Send your first request with Python

Install the official Python SDK:

pip install anthropic

Then create a file called quickstart.py:

import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY automatically

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1000,
    messages=[
        {"role": "user", "content": "Explain what an API is in two sentences."}
    ],
)

for block in message.content:
    if block.type == "text":
        print(block.text)

Run it with python quickstart.py and Claude’s answer will print in your terminal.

Example: using curl instead

If you prefer not to install anything, you can call the Messages API directly:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 500,
    "messages": [{"role": "user", "content": "Write a haiku about coffee."}]
  }'

Example: adding a system prompt

A system prompt sets Claude’s role and tone for the whole conversation:

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=500,
    system="You are a friendly tech support assistant. Keep answers short.",
    messages=[
        {"role": "user", "content": "My Wi-Fi keeps disconnecting. What should I check first?"}
    ],
)

Example: a multi-turn conversation

The API doesn’t remember earlier messages on its own. To continue a conversation, send the previous turns along with the new question:

messages = [
    {"role": "user", "content": "Suggest a name for a tech blog."},
    {"role": "assistant", "content": "How about 'Byte Sized'?"},
    {"role": "user", "content": "Give me three more options like that."},
]

message = client.messages.create(
    model="claude-opus-5-5", max_tokens=300, messages=messages
)

Tips for using the Claude API

  • Set max_tokens sensibly. It caps the length of each response and helps control costs.
  • Use the right model for the job. Smaller models are cheaper and faster for simple tasks like classification or short replies.
  • Watch your usage. The Console shows how many tokens you’ve used and what you’re spending.
  • Read the docs. Anthropic’s documentation covers features like image input, tool use, streaming and prompt caching.

Final thoughts

The Claude API is one of the easiest ways to add powerful AI to your own projects. Once you have a key and the SDK installed, a working request takes just a few lines of code, and the same pattern scales from quick scripts to full applications.

What are you planning to build with the Claude API? Let us know in the comments below!

Share this article
Shareable URL
Leave a Reply

Your email address will not be published. Required fields are marked *

Read next
0
Share