API developer guide
Claude API Complete Guide: Authentication, Pricing & Examples (2026)
Complete guide to the Claude API by Anthropic. Learn authentication, pricing, Python/JavaScript examples, models, and best practices.
↻ Updated: February 6, 2026 11 min read
Claude API: Build AI-Powered Applications
The Claude API lets you integrate Claude’s intelligence into your own applications. Whether you’re building chatbots, code generators, content tools, or data analysis pipelines, the API gives you direct access to Claude’s models.
Getting Started
Step 1: Create an Account
- Go to console.anthropic.com
- Sign up and verify your email
- Add a payment method
Step 2: Get Your API Key
- Navigate to API Keys in the console
- Click Create Key
- Copy and save your key securely
Never expose your API key in client-side code or public repositories.
Step 3: Install the SDK
Python:
pip install anthropic
JavaScript/TypeScript:
npm install @anthropic-ai/sdk
Quick Examples
Python
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": "Explain quantum computing in simple terms"}
]
)
print(message.content[0].text)
JavaScript/TypeScript
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({ apiKey: 'your-api-key' });
const message = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Explain quantum computing in simple terms' }
],
});
console.log(message.content[0].text);
cURL
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello, Claude!"}]
}'
Available Models
| Model | ID | Best For | Context |
|---|---|---|---|
| Claude 3.7 Sonnet | claude-sonnet-4-20250514 | Best all-around | 200K |
| Claude Opus | claude-opus-4-20250514 | Maximum intelligence | 200K |
| Claude Haiku | claude-haiku-3-5-20241022 | Fast, cheap tasks | 200K |
API Pricing
Claude API uses pay-per-token pricing:
| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| Sonnet | ~$3 | ~$15 |
| Opus | ~$15 | ~$75 |
| Haiku | ~$0.25 | ~$1.25 |
Check anthropic.com/pricing for current rates.
Key Features
Streaming
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a poem"}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
Vision (Image Analysis)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{"type": "image", "source": {"type": "url", "url": "https://example.com/image.jpg"}},
{"type": "text", "text": "Describe this image"}
]
}]
)
Tool Use (Function Calling)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=[{
"name": "get_weather",
"description": "Get current weather for a location",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}],
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}]
)
System Prompts
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a helpful coding assistant. Always include code examples.",
messages=[{"role": "user", "content": "How do I read a file in Python?"}]
)
Cloud Provider Access
Use Claude API through your existing cloud provider:
- Amazon Bedrock:
anthropic.AnthropicBedrock() - Google Vertex AI:
anthropic.AnthropicVertex() - Microsoft Foundry: Available through Azure
Rate Limits
| Tier | Requests/min | Tokens/min |
|---|---|---|
| Free | 5 | 20,000 |
| Build | 50 | 80,000 |
| Scale | 1,000 | 400,000 |
Upgrade tiers by maintaining consistent usage.
Best Practices
- Use system prompts to set behavior consistently
- Stream responses for better user experience
- Handle rate limits with exponential backoff
- Cache responses for repeated queries
- Use Haiku for simple tasks to save costs
- Set max_tokens appropriately to control costs
Claude Code vs Claude API
| Claude Code | Claude API | |
|---|---|---|
| Use | AI coding agent | Build custom apps |
| Interface | Terminal / IDE | HTTP / SDK |
| Billing | Subscription | Pay-per-token |
| Best for | Coding tasks | Custom integration |
Install Claude Code → for coding. Use the API for building applications.
Related Articles
- What is Claude AI? — Overview
- Claude Agents Guide — Build AI agents
- Claude Code Pricing — Subscription plans
- Claude Code for Beginners — Get started