Your First Steps with Claude: A Complete API Quickstart Guide
Learn how to get started with the Claude API in minutes. This guide covers account setup, authentication, and your first API call using Python, TypeScript, and cURL.
This guide walks you through creating an Anthropic Console account, obtaining your API key, and making your first API call to Claude using cURL, Python, or TypeScript. You'll learn the core Messages API pattern and where to go next.
Introduction
Claude is a powerful AI assistant developed by Anthropic, accessible through a simple yet flexible API. Whether you're building a chatbot, a content generation tool, or an intelligent agent, the Claude API gives you direct access to state-of-the-art language models.
This guide is your starting point. By the end, you'll have made your first successful API call and understand the core patterns you'll use in every integration.
Prerequisites
Before you begin, you'll need:
- An Anthropic Console account – sign up at console.anthropic.com
- An API key – generated from the Console dashboard
- Basic familiarity with the command line and either cURL, Python, or TypeScript
Note: The Claude API is a paid service. After signing up, you'll receive some initial credits to experiment with.
Step 1: Create Your Account and Get an API Key
- Go to console.anthropic.com and click Sign Up.
- Complete the registration process (email verification required).
- Once logged in, navigate to the API Keys section.
- Click Create Key, give it a name (e.g., "My First App"), and copy the key immediately. You won't be able to see it again.
Step 2: Make Your First API Call
You can call the Claude API using any HTTP client. Here are examples in three popular formats.
Using cURL (Command Line)
Open your terminal and run:
curl https://api.anthropic.com/v1/messages \
--header "x-api-key: $ANTHROPIC_API_KEY" \
--header "anthropic-version: 2023-06-01" \
--header "content-type: application/json" \
--data '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello, Claude!"}
]
}'
Replace $ANTHROPIC_API_KEY with your actual key or set it as an environment variable.
Using Python
First, install the Anthropic SDK:
pip install anthropic
Then create a file quickstart.py:
import anthropic
client = anthropic.Anthropic(
api_key="your-api-key-here"
)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
print(message.content[0].text)
Run it:
python quickstart.py
Using TypeScript
First, install the SDK:
npm install @anthropic-ai/sdk
Then create quickstart.ts:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: 'your-api-key-here',
});
async function main() {
const message = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Hello, Claude!' }
],
});
console.log(message.content[0].text);
}
main();
Run with:
npx ts-node quickstart.ts
Understanding the Response
When Claude responds, you'll receive a JSON object like this:
{
"id": "msg_01ABC123...",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! How can I help you today?"
}
],
"model": "claude-sonnet-4-20250514",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 10,
"output_tokens": 10
}
}
Key fields:
- content: An array of content blocks. For text responses, you'll see a
textblock. - stop_reason: Why Claude stopped generating.
"end_turn"means it finished naturally. - usage: Token counts for billing and monitoring.
Next Steps: Core Patterns to Learn
You've made your first API call. Now it's time to explore the patterns you'll use in every integration:
1. Multi-turn Conversations
Send a list of messages to maintain context:
messages = [
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "What is its population?"}
]
2. System Prompts
Set the behavior and persona of Claude:
message = client.messages.create(
model="claude-sonnet-4-20250514",
system="You are a helpful assistant that speaks like a pirate.",
max_tokens=1024,
messages=[
{"role": "user", "content": "Tell me about the weather."}
]
)
3. Handling Stop Reasons
Check stop_reason to handle different scenarios:
"end_turn": Claude finished naturally."max_tokens": The response was cut off – you may need to continue."stop_sequence": Claude hit a custom stop sequence you defined.
4. Streaming Responses
For real-time output, use streaming:
stream = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Count to 10."}],
stream=True
)
for chunk in stream:
if chunk.type == "content_block_delta":
print(chunk.delta.text, end="", flush=True)
Explore Further
Once you're comfortable with the basics, dive into these resources:
- Models Overview: Compare Claude models by capability, speed, and cost.
- Features Overview: Explore tools, context management, structured outputs, and more.
- Client SDKs: Reference documentation for Python, TypeScript, Java, and other libraries.
- Prompt Caching: Reduce latency and cost for repeated system prompts.
- Tool Use: Give Claude the ability to call external functions.
Key Takeaways
- Getting started is fast: Sign up for an Anthropic Console account, generate an API key, and you can make your first call in under 5 minutes.
- The Messages API is your foundation: All interactions use the same
messagesarray pattern – user and assistant messages in sequence. - SDKs simplify development: Use the official Python or TypeScript SDKs for cleaner code, type safety, and built-in error handling.
- Start simple, then layer on features: Begin with a single-turn request, then add system prompts, multi-turn conversations, streaming, and tools as needed.
- Monitor your usage: The
usagefield in every response tells you exactly how many tokens you're consuming – essential for cost management.