How to Use Claude API for Free (Step by Step)


The Claude API gives you programmatic access to Anthropic’s Claude models — the same AI behind the claude.ai chat interface. This guide walks you through everything from signing up to making your first API call.

Good news: Anthropic gives new accounts $5 in free credits to get started. No credit card required for the initial signup.


What You’ll Need

  • A free Anthropic account
  • Basic knowledge of Python or JavaScript (or just copy-paste the examples below)
  • A text editor or IDE

Step 1: Create an Anthropic Account

  1. Go to console.anthropic.com
  2. Click Sign Up and create a free account
  3. Verify your email address

You’ll land on the Anthropic Console dashboard.


Step 2: Get Your API Key

  1. In the Console, click API Keys in the left sidebar
  2. Click Create Key
  3. Give it a name (e.g., “my-first-key”)
  4. Copy the key — you won’t be able to see it again

Store your API key somewhere safe. Never commit it to a public GitHub repo.


Step 3: Check Your Free Credits

New accounts get $5 in free API credits. To check your balance:

  1. Go to Billing in the Console
  2. You’ll see your remaining credits

$5 gets you roughly 5 million tokens with Claude 3 Haiku (the cheapest model) — that’s a lot of testing.


Step 4: Install the SDK

Python:

pip install anthropic

Node.js:

npm install @anthropic-ai/sdk

Step 5: Make Your First API Call

Python example:

import anthropic

client = anthropic.Anthropic(api_key="your-api-key-here")

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain what an API is in simple terms."}
    ]
)

print(message.content[0].text)

JavaScript/Node.js example:

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({ apiKey: 'your-api-key-here' });

const message = await client.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  messages: [
    { role: 'user', content: 'Explain what an API is in simple terms.' }
  ],
});

console.log(message.content[0].text);

Step 6: Use Environment Variables (Best Practice)

Never hardcode your API key. Use environment variables instead:

Python:

import anthropic
import os

client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))

Set the environment variable in your terminal:

# Mac/Linux
export ANTHROPIC_API_KEY="your-key-here"

# Windows (CMD)
set ANTHROPIC_API_KEY=your-key-here

Available Models (2026)

ModelSpeedCostBest For
claude-3-5-sonnet-20241022Fast$$Most tasks
claude-3-5-haiku-20241022Fastest$High volume, simple tasks
claude-3-opus-20240229Slower$$$$Complex reasoning

For most use cases, Claude 3.5 Sonnet is the best balance of speed and quality.


Useful API Features

System Prompts

System prompts let you give Claude a persona or set of instructions:

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    system="You are a helpful assistant that always responds in bullet points.",
    messages=[
        {"role": "user", "content": "What are the benefits of exercise?"}
    ]
)

Multi-turn Conversations

messages = [
    {"role": "user", "content": "What is machine learning?"},
    {"role": "assistant", "content": "Machine learning is..."},
    {"role": "user", "content": "Can you give me a simple example?"}
]

response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=messages
)

How Much Does It Cost?

After your free $5 credits run out, pricing is pay-as-you-go:

  • Claude 3.5 Haiku: $0.80 per million input tokens / $4 per million output tokens
  • Claude 3.5 Sonnet: $3 per million input tokens / $15 per million output tokens

For context: a typical blog post is about 1,000 tokens. $5 in credits = roughly 1,600 blog posts with Haiku.


Next Steps

The Claude API is one of the most capable and developer-friendly AI APIs available. The free credits make it easy to experiment without any upfront cost.