Anthropic Claude Models
Complete guide to Anthropic's Claude family of models. Learn about Claude 3.5 Sonnet, Claude 3 Opus, their capabilities, API usage, pricing, and best practices for safe and effective integration.
Also available on AWS Bedrock! Access Claude models through AWS with enterprise security, IAM integration, and managed guardrails. Learn more →
Current Claude Models
Claude 3.5 Sonnet
RecommendedThe flagship model with industry-leading performance. Outperforms GPT-4o and Gemini 1.5 Pro on most benchmarks while being faster and more cost-effective. Best for complex reasoning, coding, and analysis.
Claude 3.5 Haiku
Fast & AffordableThe fastest and most affordable Claude model. Matches Claude 3 Opus performance at a fraction of the cost. Ideal for high-volume tasks, chat, and real-time applications.
Claude 3 Opus
Maximum IntelligencePrevious flagship, still excellent for tasks requiring maximum reasoning depth. Being superseded by Claude 3.5 Sonnet for most use cases due to better performance/cost.
Claude 3 Sonnet
LegacyPrevious-generation balanced model. Recommend upgrading to Claude 3.5 Sonnet for significantly better performance at similar cost.
What Makes Claude Unique
200K Context Window
Process entire books, codebases, or lengthy documents in a single conversation. Near-perfect recall across the full context.
Constitutional AI
Trained with Anthropic's Constitutional AI approach for safety, making it more resistant to jailbreaks and harmful outputs.
Vision Capabilities
Analyze images, charts, diagrams, and documents. Excellent at extracting data from visual content.
Exceptional at Code
Top-tier code generation, debugging, and explanation. Strong performance on SWE-bench and HumanEval benchmarks.
Tool Use & Agents
Excellent function calling and agentic capabilities. Can use computer tools to interact with web browsers and desktop apps.
Artifacts
Creates interactive artifacts (code, documents, diagrams) that users can view, edit, and iterate on in real-time.
Which Model to Use?
| Use Case | Recommended | Why |
|---|---|---|
| Complex coding tasks | 3.5 Sonnet | Best code generation and debugging |
| High-volume chat | 3.5 Haiku | Fast, cheap, good enough quality |
| Document analysis | 3.5 Sonnet | 200K context + vision for PDFs |
| Classification/extraction | 3.5 Haiku | Cost-effective for simple tasks |
| Agentic workflows | 3.5 Sonnet | Best tool use and reasoning |
| Research & complex reasoning | 3 Opus | Maximum depth when cost isn't priority |
API Usage
Basic Message
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
system="You are a helpful AI assistant.",
messages=[
{"role": "user", "content": "Explain quantum computing in simple terms."}
]
)
print(message.content[0].text)
Vision (Image Analysis)
import anthropic
import base64
client = anthropic.Anthropic()
# From file
with open("chart.png", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data,
},
},
{
"type": "text",
"text": "Analyze this chart and summarize the key trends."
}
],
}
],
)
Tool Use (Function Calling)
import anthropic
client = anthropic.Anthropic()
tools = [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["location"]
}
}
]
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}]
)
# Check for tool use
for block in message.content:
if block.type == "tool_use":
print(f"Tool: {block.name}")
print(f"Input: {block.input}")
Streaming
import anthropic
client = anthropic.Anthropic()
with client.messages.stream(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a haiku about coding."}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
Extended Thinking (Beta)
import anthropic
client = anthropic.Anthropic()
# Enable extended thinking for complex reasoning
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=16000,
thinking={
"type": "enabled",
"budget_tokens": 10000 # Tokens for internal reasoning
},
messages=[{
"role": "user",
"content": "Solve this complex math problem step by step..."
}]
)
# Access thinking blocks
for block in response.content:
if block.type == "thinking":
print("Reasoning:", block.thinking)
elif block.type == "text":
print("Answer:", block.text)
Key Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| max_tokens | int | required | Maximum tokens in response. Required parameter. |
| temperature | float | 1.0 | Randomness (0-1). Lower = more focused. |
| system | string | null | System prompt (passed separately, not in messages). |
| top_p | float | null | Nucleus sampling (0-1). Use instead of temperature. |
| top_k | int | null | Sample from top K tokens only. |
| stop_sequences | list | null | Custom stop sequences to end generation. |
| metadata | object | null | User ID for abuse detection and billing. |
Best Practices
Use XML Tags in Prompts
Claude responds well to structured prompts with XML tags like <context>,
<instructions>,
<example>.
Separate System Prompt
Always use the system
parameter instead of putting
system instructions in the first user message.
Prefill Responses
Use assistant prefills to guide output format. Start the assistant message with "{" for JSON output.
Prompt Caching
Use prompt caching for repeated system prompts or large contexts to reduce costs up to 90%.