Getting Started with Claude API: Your First Integration in Minutes
Learn how to set up your Anthropic account, generate an API key, and make your first call to the Claude API using cURL, Python, or TypeScript. A practical guide for developers.
This guide walks you through creating an Anthropic Console account, obtaining an API key, and making your first API call to Claude using cURL, Python, or TypeScript. You'll learn the essential patterns 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 gives you direct access to Claude's capabilities.
This guide will get you from zero to your first successful API call in just a few minutes. No prior experience with Claude is required—just a basic understanding of APIs and your preferred programming language.
Prerequisites
Before you start, you'll need two things:
- An Anthropic Console account – Sign up at console.anthropic.com. The process is free and straightforward.
- An API key – Once logged in, navigate to the API Keys section and generate a new key. Treat this key like a password—never share it or commit it to version control.
Tip: Store your API key as an environment variable (e.g., ANTHROPIC_API_KEY) to keep it secure and accessible across projects.
Making Your First API Call
The Claude API uses a simple HTTP interface. You can call it with any tool that sends HTTP requests, but we'll cover the three most common approaches: cURL, Python, and TypeScript.
1. Using cURL (Quick Test)
cURL is perfect for testing your setup from the 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!"}
]
}'
If everything works, you'll receive a JSON response containing Claude's reply. The response will include the message content, stop reason, and usage metadata.
2. Using Python
For Python developers, install the official Anthropic SDK:
pip install anthropic
Then create a simple script:
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)
Run the script with python your_script.py. The SDK handles authentication, serialization, and error handling automatically.
3. Using TypeScript
For Node.js/TypeScript projects, install the SDK:
npm install @anthropic-ai/sdk
Then use it in your code:
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic();
async function main() {
const message = await anthropic.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 ts-node your_script.ts or compile and run with Node.js.
Understanding the Response
When Claude responds, the API returns a structured JSON object. Here's what you'll see:
content– An array of content blocks. For text responses, it's usually a single block with atextfield.stop_reason– Indicates why the response ended (e.g.,"end_turn","max_tokens", or"stop_sequence").usage– Token counts for input and output, useful for cost tracking.
{
"content": [
{
"type": "text",
"text": "Hello! How can I assist you today?"
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 12,
"output_tokens": 10
}
}
Next Steps: Core API Patterns
Once you've made your first call, you're ready to explore the patterns that power every Claude integration.
Multi-turn Conversations
Claude supports conversational memory by passing the full message history. Each turn adds a new message to the messages array:
messages = [
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "Tell me more about its history."}
]
System Prompts
Set the context or behavior of Claude using a system prompt:
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": "What is the capital of France?"}
]
)
Handling Stop Reasons
Always check the stop_reason in the response. If it's "max_tokens", the response was cut short—you may need to continue the conversation or increase max_tokens.
Exploring Claude's Capabilities
After mastering the basics, dive into Claude's advanced features:
- Tools (Function Calling) – Give Claude the ability to call external APIs or perform actions.
- Extended Thinking – Enable Claude to reason step-by-step before responding.
- Structured Outputs – Request JSON, XML, or other structured formats.
- Streaming – Receive responses token-by-token for real-time user experiences.
- Vision – Analyze images by passing them as part of the message.
- Prompt Caching – Reduce latency and cost for repeated system prompts or large contexts.
Choosing the Right Model
Claude comes in several variants, each optimized for different use cases:
| Model | Best For |
|---|---|
| Claude Sonnet 4 | General-purpose tasks, speed, and cost balance |
| Claude Haiku 3.5 | Fast, lightweight tasks (e.g., classification, moderation) |
| Claude Opus 4 | Complex reasoning, long-form content, deep analysis |
Troubleshooting Common Issues
- 401 Unauthorized – Your API key is missing or invalid. Check your environment variable.
- 429 Too Many Requests – You've hit a rate limit. Implement exponential backoff.
- 400 Bad Request – Malformed JSON or missing required fields. Validate your request body.
- Model not found – You may be using a deprecated model name. Always reference the latest model ID from the docs.
Conclusion
You've now made your first API call to Claude and understand the foundational patterns. From here, you can build anything from a simple chatbot to a complex agent that uses tools, processes files, and thinks step-by-step.
The Claude API is designed to be intuitive and developer-friendly. As you explore further, remember that the Anthropic Console provides logs, usage metrics, and a playground for testing prompts without writing code.
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 – Use the
messagesarray for multi-turn conversations and system prompts for behavior control. - Always check stop reasons – The
stop_reasonfield tells you if a response was truncated or complete. - Explore advanced features – Tools, streaming, vision, and structured outputs unlock Claude's full potential.
- Choose the right model – Match Claude's variant (Sonnet, Haiku, Opus) to your task's complexity and latency requirements.