Getting Started with Claude: Your Complete Guide to the API and Managed Agents
Learn how to build with Claude AI using the Messages API or Managed Agents. Step-by-step guide covering setup, core features, and best practices for developers.
This guide walks you through building with Claude—from making your first API call to choosing between the Messages API and Managed Agents. You'll learn the core request/response structure, model selection, and key capabilities like vision, extended thinking, and tool use.
Getting Started with Claude: Your Complete Guide to the API and Managed Agents
Claude by Anthropic represents a new generation of AI assistants designed for complex reasoning, coding, and enterprise workflows. Whether you're building a chatbot, automating tasks, or integrating AI into your product, this guide will help you go from zero to a working Claude integration.
Understanding Your Options: Messages API vs. Managed Agents
Anthropic offers two primary ways to build with Claude, each suited to different use cases:
| Feature | Messages API | Claude Managed Agents |
|---|---|---|
| What it is | Direct model prompting access | Pre-built, configurable agent harness |
| Best for | Custom agent loops and fine-grained control | Long-running tasks and asynchronous work |
| Control level | Full control over prompts and logic | Managed infrastructure with configuration |
| Learning curve | Steeper (build from scratch) | Gentler (configure, don't code loops) |
Step 1: Make Your First API Call
Let's start by setting up your environment and sending your first message to Claude.
Prerequisites
- An Anthropic account and API key (get one from console.anthropic.com)
- Python 3.7+ or Node.js 14+
Python Quickstart
import anthropic
client = anthropic.Anthropic(api_key="your-api-key-here")
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1000,
temperature=0,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "Hello, Claude! What can you help me with?"}
]
)
print(message.content[0].text)
TypeScript/JavaScript Quickstart
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: 1000,
temperature: 0,
system: 'You are a helpful assistant.',
messages: [
{ role: 'user', content: 'Hello, Claude! What can you help me with?' }
]
});
console.log(message.content[0].text);
}
main();
Pro tip: Always set temperature to 0 for deterministic tasks like coding or data extraction. Use higher values (0.3–0.7) for creative tasks.
Step 2: Understand the Messages API Structure
The Messages API is the core way to interact with Claude. Here's what you need to know:
Request Components
model: Which Claude model to use (e.g.,claude-sonnet-4-20250514)messages: An array of conversation turns, each with arole("user" or "assistant") andcontentsystem: An optional system prompt that sets Claude's behaviormax_tokens: Maximum tokens in the responsetemperature: Controls randomness (0–1)
Multi-Turn Conversations
conversation = [
{"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?"}
]
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=500,
messages=conversation
)
Handling Stop Reasons
When Claude finishes generating, the response includes a stop_reason field. Common values:
"end_turn": Claude naturally finished"max_tokens": Hit the token limit—you may need to continue"tool_use": Claude wants to use a tool (more on this later)
response = client.messages.create(...)
if response.stop_reason == "max_tokens":
# Continue the conversation to get more output
print("Response was truncated. Consider increasing max_tokens.")
Step 3: Choose the Right Model
Claude comes in several flavors, each optimized for different needs:
| Model | Best For | Speed | Cost |
|---|---|---|---|
| Claude Opus 4.7 | Complex reasoning, agentic coding | Moderate | Highest |
| Claude Sonnet 4.6 | Coding, agents, enterprise workflows | Fast | Medium |
| Claude Haiku 4.5 | High-throughput, simple tasks | Fastest | Lowest |
Step 4: Explore Key Features
Claude offers a rich set of capabilities beyond simple text generation:
Extended Thinking
For complex reasoning tasks, enable Claude's extended thinking mode:
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=2000,
thinking={"type": "enabled", "budget_tokens": 1000},
messages=[{"role": "user", "content": "Solve this complex math problem step by step..."}]
)
Structured Outputs
Get JSON-formatted responses for easier parsing:
response = client.messages.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "List 3 countries and their capitals as JSON."}],
response_format={"type": "json_object"}
)
Vision (Image Processing)
Claude can analyze images and screenshots:
import base64
with open("screenshot.png", "rb") as f:
image_data = base64.b64encode(f.read()).decode("utf-8")
response = client.messages.create(
model="claude-sonnet-4-20250514",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image_data}}
]
}]
)
Tool Use
Claude can call external tools and APIs. Here's a minimal example:
tools = [
{
"name": "get_weather",
"description": "Get current weather for a city",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
]
response = client.messages.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
tools=tools
)
Best Practices for Production
- Use prompt caching for frequently used system prompts to reduce latency and cost
- Implement streaming for better user experience with long responses
- Set appropriate max_tokens to avoid unexpected truncation
- Handle errors gracefully—API calls can fail due to rate limits or network issues
- Monitor token usage to control costs
Developer Tools
Anthropic provides several tools to accelerate development:
- Developer Console: Prototype and test prompts in your browser with the Workbench
- API Reference: Full documentation for the Claude API and client SDKs
- Claude Cookbook: Interactive Jupyter notebooks covering PDFs, embeddings, and more
Key Takeaways
- Choose the right integration path: Use the Messages API for full control, or Managed Agents for hands-off deployment
- Start with Sonnet: Claude Sonnet 4.6 offers the best balance of intelligence, speed, and cost for most applications
- Master the Messages API: Understand request structure, stop reasons, and multi-turn conversations to build robust applications
- Leverage advanced features: Extended thinking, structured outputs, vision, and tool use unlock powerful use cases
- Follow best practices: Use prompt caching, streaming, and proper error handling for production-ready applications