Getting Started with Claude: Your First API Call and Beyond
Learn how to set up your Anthropic account, obtain an API key, and make your first API call to Claude. Includes code examples in Python and TypeScript.
This guide walks you through creating an Anthropic Console account, generating an API key, and making your first API call to Claude using cURL, Python, or TypeScript. You'll also learn the next steps for building with Claude.
Introduction
Claude is a powerful AI assistant developed by Anthropic, designed to handle a wide range of tasks from simple Q&A to complex reasoning and tool use. Whether you're building a chatbot, automating workflows, or integrating AI into your application, the Claude API is your gateway to leveraging these capabilities.
This guide will take you from zero to your first successful API call. By the end, you'll have a working integration and a clear path forward for building more advanced features.
Prerequisites
Before you start, you'll need two things:
- An Anthropic Console account – Sign up at console.anthropic.com.
- An API key – Generate one from the Console dashboard under the API Keys section.
Important: Keep your API key secret. Never commit it to version control or expose it in client-side code.
Making Your First API Call
Let's make a simple request to Claude. We'll ask Claude to introduce itself. You can use any of the following methods: cURL, Python, TypeScript, or Java.
Using cURL
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 API key or set it as an environment variable.
Using Python
First, install the Anthropic Python SDK:
pip install anthropic
Then create a file hello_claude.py:
import anthropic
client = anthropic.Anthropic(
api_key="YOUR_API_KEY"
)
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 hello_claude.py
Using TypeScript
Install the Anthropic TypeScript SDK:
npm install @anthropic-ai/sdk
Create a file hello_claude.ts:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: 'YOUR_API_KEY',
});
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 hello_claude.ts
Using Java
Add the dependency to your pom.xml:
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java</artifactId>
<version>0.1.0</version>
</dependency>
Then create a class:
import com.anthropic.Anthropic;
import com.anthropic.models.messages.Message;
import com.anthropic.models.messages.MessageCreateParams;
public class HelloClaude {
public static void main(String[] args) {
Anthropic client = new Anthropic("YOUR_API_KEY");
MessageCreateParams params = MessageCreateParams.builder()
.model("claude-sonnet-4-20250514")
.maxTokens(1024)
.addUserMessage("Hello, Claude!")
.build();
Message message = client.messages().create(params);
System.out.println(message.content().get(0).text());
}
}
Understanding the Response
When you make a successful API call, Claude returns a JSON response with the following structure:
{
"id": "msg_01ABC123...",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! I'm Claude, an AI assistant created by Anthropic. How can I help you today?"
}
],
"model": "claude-sonnet-4-20250514",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 10,
"output_tokens": 25
}
}
Key fields:
- id: Unique identifier for the message.
- content: Array of content blocks (usually text).
- stop_reason: Why the generation stopped (e.g., "end_turn", "max_tokens").
- usage: Token counts for billing and monitoring.
Next Steps
Congratulations! You've made your first API call. Now it's time to explore what Claude can really do.
1. Master the Messages API
Learn the core patterns you'll use in every integration:
- Multi-turn conversations
- System prompts for setting behavior
- Handling stop reasons
- Streaming responses for real-time output
2. Compare Claude Models
Claude comes in different flavors:
- Claude Sonnet: Best balance of speed and capability for most tasks.
- Claude Haiku: Fastest model for simple queries.
- Claude Opus: Most powerful for complex reasoning.
3. Explore Advanced Features
Claude's API supports a rich set of capabilities:
- Tools: Let Claude call external functions.
- Context management: Handle long conversations with prompt caching and compaction.
- Structured outputs: Get JSON responses for programmatic use.
- Vision: Analyze images and PDFs.
- Extended thinking: Enable step-by-step reasoning.
4. Use Client SDKs
For production applications, use the official SDKs:
Key Takeaways
- Start simple: Make your first API call with a basic text prompt to verify your setup.
- Secure your key: Always use environment variables or secret management for your API key.
- Understand the response: Familiarize yourself with the message structure, especially
stop_reasonandusage. - Explore systematically: Move from basic calls to multi-turn conversations, then to advanced features like tools and streaming.
- Use SDKs for production: Official client libraries handle authentication, retries, and error handling automatically.