Claude API Quickstart Guide

Get up and running with the Anthropic Claude API in under 10 minutes. Covers authentication, first request, streaming, and tool use.

AI Tutorials · · Updated · 2 min read

Quick answer

To start using the Claude API: sign up at console.anthropic.com, install the SDK (pip install anthropic for Python or npm install @anthropic-ai/sdk for Node.js), set your API key as an environment variable, and make your first request. The API supports text generation, streaming, tool use, and vision. Pricing is per-token with no minimum spend.

Setup

1. Get an API Key

Sign up at console.anthropic.com and create an API key.

2. Install the SDK

# Python
pip install anthropic

# Node.js
npm install @anthropic-ai/sdk

3. Set Your API Key

export ANTHROPIC_API_KEY="your-key-here"

First Request

Python

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "What is machine learning in one paragraph?"}
    ]
)

print(message.content[0].text)

Node.js

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

const client = new Anthropic();

const message = await client.messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  messages: [
    { role: 'user', content: 'What is machine learning in one paragraph?' }
  ]
});

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

Streaming

For real-time output:

with client.messages.stream(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain neural networks"}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

System Prompts

Set behavior with system prompts:

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    system="You are a Python expert. Respond with code examples.",
    messages=[
        {"role": "user", "content": "How do I read a CSV file?"}
    ]
)

Tool Use

Give Claude access to functions:

tools = [{
    "name": "get_weather",
    "description": "Get current weather for a location",
    "input_schema": {
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "City name"}
        },
        "required": ["location"]
    }
}]

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}]
)

Available Models

ModelBest ForContext
claude-opus-4-20250514Most capable, complex tasks200K
claude-sonnet-4-20250514Best balance of speed and quality200K
claude-haiku-3-5-20241022Fastest, cheapest200K

Rate Limits

  • Free tier: 40 requests/minute
  • Build tier: 1,000 requests/minute
  • Scale tier: Custom limits

Next Steps

Frequently asked questions

How do I get started with the Claude API?
Three steps: 1) Create an account at console.anthropic.com and generate an API key. 2) Install the SDK (pip install anthropic for Python, npm install @anthropic-ai/sdk for Node.js). 3) Set your ANTHROPIC_API_KEY environment variable and make your first API call.
How much does the Claude API cost?
Claude API pricing is per-token with no minimum spend. Costs vary by model: Claude Haiku is cheapest for simple tasks, Claude Sonnet is the best value for most use cases, and Claude Opus is most capable but most expensive. Check anthropic.com/pricing for current rates.
What can you build with the Claude API?
Common use cases include chatbots, content generation, code generation, document analysis, data extraction, summarization, and AI agents with tool use. The API supports text, images (vision), streaming responses, and function calling for building autonomous systems.

Want to keep learning?

Explore our guided learning paths or try building something with AI right now.

Enjoyed this article?

Subscribe for more AI insights delivered to your inbox every week.

No spam. Unsubscribe anytime.