Getting Started with the Claude API: Your First Integration in Minutes
A practical, step-by-step guide to making your first Claude API call, understanding the Messages API, and exploring key features like tools, streaming, and context management.
Learn how to set up your Anthropic account, obtain an API key, and make your first API call using cURL, Python, or TypeScript. Then explore the Messages API patterns, tools, streaming, and context management.
Introduction
Welcome to the Claude API! Whether you're building a chatbot, an AI-powered assistant, or a complex agent, this guide will get you from zero to your first successful API call in minutes. We'll cover everything from account setup to making your first request, and then point you to the next steps for building more advanced integrations.
By the end of this guide, you'll have a working Claude integration and understand the core patterns you'll use in every project.
Prerequisites
Before you start, make sure you have:
- An Anthropic Console account – sign up at console.anthropic.com
- An API key – generate one in the Console under the API Keys section
- A tool to make HTTP requests: cURL, Python (with
requestsoranthropicSDK), or TypeScript (withaxiosor@anthropic-ai/sdk)
Security tip: Never hard-code your API key in client-side code or public repositories. Use environment variables or a secrets manager.
Step 1: Make Your First API Call
The fastest way to test your setup is with a simple "Hello, Claude" request using the Messages API. Here's how to do it in three popular formats.
Using cURL
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": 1024,
"messages": [
{"role": "user", "content": "Hello, Claude!"}
]
}'
Using Python
First install the SDK:
pip install anthropic
Then run:
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
print(message.content[0].text)
Using TypeScript
First install the SDK:
npm install @anthropic-ai/sdk
Then run:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
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();
Expected response: Claude will greet you back with a friendly message. If you see an error, double-check your API key and endpoint URL.
Step 2: Understand the Messages API
The Messages API is the primary way to interact with Claude. Here are the key parameters you'll use in every request:
| Parameter | Description |
|---|---|
model | The Claude model ID (e.g., claude-sonnet-4-20250514, claude-3-5-haiku-latest) |
max_tokens | Maximum number of tokens in the response |
messages | Array of message objects with role and content |
system | (Optional) System prompt to set Claude's behavior |
temperature | (Optional) Controls randomness (0.0 to 1.0) |
Multi-turn Conversations
To continue a conversation, simply append the assistant's response and your new message to the messages array:
messages = [
{"role": "user", "content": "What's the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "Tell me more about its history."}
]
System Prompts
Use the system parameter to set the tone or constraints:
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a helpful assistant that speaks like a pirate.",
messages=[
{"role": "user", "content": "What's the weather like today?"}
]
)
Handling Stop Reasons
Every response includes a stop_reason field. Common values:
"end_turn": Claude finished naturally"max_tokens": Response was cut off – increasemax_tokensor continue the conversation"tool_use": Claude wants to call a tool (more on this below)
Step 3: Explore Key Features
Once you're comfortable with basic requests, explore these powerful features:
Streaming Responses
For real-time output (like chatbots), use streaming:
stream = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for event in stream:
if event.type == "content_block_delta":
print(event.delta.text, end="")
Tool Use (Function Calling)
Claude can use external tools. Define a tool and let Claude decide when to call it:
tools = [
{
"name": "get_weather",
"description": "Get the current weather for a city",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"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?"}]
)
Structured Outputs
Request JSON responses by setting the response_format parameter:
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
response_format={"type": "json_object"},
messages=[
{"role": "user", "content": "List three fruits as a JSON array"}
]
)
Prompt Caching
Reduce costs and latency for repeated system prompts or large contexts:
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system=[
{
"type": "text",
"text": "You are an expert historian...",
"cache_control": {"type": "ephemeral"}
}
],
messages=[...]
)
Step 4: Next Steps
You've made your first API call and learned the core patterns. Here's where to go next:
- Models overview – Compare Claude models by capability and cost
- Features overview – Browse all capabilities: tools, context management, structured outputs, and more
- Client SDKs – Reference documentation for Python, TypeScript, Java, and other client libraries
- Building with Claude – Learn about extended thinking, batch processing, and advanced agent patterns
Key Takeaways
- Get started in minutes – Sign up for an Anthropic account, generate an API key, and make your first call with cURL, Python, or TypeScript.
- Master the Messages API – Understand the core parameters:
model,max_tokens,messages,system, andtemperature. - Leverage advanced features – Streaming, tool use, structured outputs, and prompt caching unlock powerful applications.
- Handle stop reasons – Always check
stop_reasonto know if Claude finished naturally or needs more input. - Explore the ecosystem – Dive into client SDKs, model comparisons, and the full feature set to build production-ready integrations.