Getting Started with Claude API: Your First Integration in 10 Minutes
A practical, step-by-step guide to making your first Claude API call. Learn prerequisites, authentication, and core API patterns with code examples in Python and TypeScript.
This guide walks you through setting up an Anthropic Console account, generating an API key, and making your first call to the Claude API using cURL, Python, or TypeScript. You'll learn the essential Messages API patterns needed for every integration.
Getting Started with Claude API: Your First Integration in 10 Minutes
Claude is one of the most capable and versatile AI models available today. Whether you're building a chatbot, a content generator, a code assistant, or an agentic workflow, the Claude API gives you programmatic access to Claude's intelligence. This guide will get you from zero to your first API call in under 10 minutes.
Prerequisites
Before you can start making API calls, you need two things:
1. An Anthropic Console Account
Head over to console.anthropic.com and sign up for a free account. The console is your control center for managing API keys, viewing usage, and exploring the model playground.
2. An API Key
Once logged in:
- Navigate to API Keys in the left sidebar
- Click Create Key
- Give your key a descriptive name (e.g., "Development" or "My App")
- Copy the key immediately — you won't be able to see it again
⚠️ Security tip: Treat your API key like a password. Never commit it to version control. Use environment variables or a secrets manager.
Making Your First API Call
Let's make a simple request to Claude. You can use cURL, Python, or TypeScript — pick your preferred method below.
Option 1: cURL (Quick Test)
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-sonnet-4-20250514",
"max_tokens": 150,
"messages": [
{"role": "user", "content": "Hello, Claude!"}
]
}'
Option 2: Python (Recommended)
First, install the Anthropic SDK:
pip install anthropic
Then create a file hello_claude.py:
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.environ.get("ANTHROPIC_API_KEY")
)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=150,
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
print(message.content[0].text)
Run it:
python hello_claude.py
Option 3: TypeScript / JavaScript
Install the SDK:
npm install @anthropic-ai/sdk
Then create hello_claude.ts:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
async function main() {
const message = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 150,
messages: [
{ role: 'user', content: 'Hello, Claude!' }
],
});
console.log(message.content[0].text);
}
main();
Run it:
npx ts-node hello_claude.ts
Understanding the Response
When Claude responds, you'll get a structured JSON object. Here's what the key fields mean:
id: Unique identifier for this messagetype: Always"message"role: Always"assistant"content: An array of content blocks (usually text)model: The model usedstop_reason: Why the response ended ("end_turn","max_tokens","stop_sequence", or"tool_use")usage: Token counts for input and output
{
"id": "msg_01ABC123xyz",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! How can I help you today?"
}
],
"model": "claude-sonnet-4-20250514",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 10,
"output_tokens": 9
}
}
Core API Patterns You'll Use Every Time
Once you've made your first call, you'll want to understand the fundamental patterns that power every Claude integration.
Multi-Turn Conversations
Claude is stateless — each API call is independent. To maintain conversation context, you send the entire message history:
messages = [
{"role": "user", "content": "What's the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "What's its most famous landmark?"}
]
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=200,
messages=messages
)
System Prompts
System prompts set Claude's behavior and persona. They're passed separately from the conversation:
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=500,
system="You are a helpful coding assistant. Always provide code examples.",
messages=[
{"role": "user", "content": "How do I read a file in Python?"}
]
)
Handling Stop Reasons
The stop_reason field tells you why Claude stopped generating. You'll handle it differently based on the value:
end_turn: Claude finished naturally — the response is completemax_tokens: Claude hit the token limit — you may need to continue the conversationstop_sequence: Claude encountered a custom stop sequence you definedtool_use: Claude wants to call a tool — you need to execute it and return the result
if response.stop_reason == "max_tokens":
# Continue the conversation to get more output
messages.append({"role": "assistant", "content": response.content[0].text})
messages.append({"role": "user", "content": "Please continue."})
# Make another API call
Next Steps: Explore Claude's Full Capabilities
You've made your first API call and understand the core patterns. Now it's time to explore what makes Claude truly powerful:
Models Overview
Claude comes in different variants optimized for different use cases:
| Model | Best For |
|---|---|
claude-sonnet-4-20250514 | Balanced performance and speed |
claude-opus-4-20250514 | Complex reasoning and analysis |
claude-haiku-3-5-20241022 | Fast, lightweight tasks |
Features to Explore
- Tools (Function Calling): Let Claude use external tools, APIs, and databases
- Structured Outputs: Get JSON, XML, or other formatted responses
- Streaming: Receive responses token-by-token for real-time UX
- Vision: Analyze images alongside text
- Prompt Caching: Reduce latency and costs for repeated system prompts
- Batch Processing: Send multiple requests asynchronously
Client SDKs
Beyond Python and TypeScript, Anthropic provides official SDKs for:
- Java
- Go
- Ruby
- .NET
Key Takeaways
- Get started in minutes: Sign up at console.anthropic.com, generate an API key, and make your first call with cURL, Python, or TypeScript
- Master the Messages API: Understand multi-turn conversations, system prompts, and stop reasons — these are the building blocks of every Claude integration
- Handle stop reasons properly: Check
stop_reasonin every response to determine if you need to continue the conversation or handle a tool call - Explore Claude's ecosystem: From tools and streaming to vision and batch processing, Claude offers a rich set of capabilities beyond simple text generation
- Use environment variables: Always store your API key in environment variables, never in code