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

  1. Go to console.anthropic.com
  2. Sign up and verify your email
  3. Add a payment method

Step 2: Get Your API Key

  1. Navigate to API Keys in the console
  2. Click Create Key
  3. 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

ModelIDBest ForContext
Claude 3.7 Sonnetclaude-sonnet-4-20250514Best all-around200K
Claude Opusclaude-opus-4-20250514Maximum intelligence200K
Claude Haikuclaude-haiku-3-5-20241022Fast, cheap tasks200K

API Pricing

Claude API uses pay-per-token pricing:

ModelInput (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

TierRequests/minTokens/min
Free520,000
Build5080,000
Scale1,000400,000

Upgrade tiers by maintaining consistent usage.

Best Practices

  1. Use system prompts to set behavior consistently
  2. Stream responses for better user experience
  3. Handle rate limits with exponential backoff
  4. Cache responses for repeated queries
  5. Use Haiku for simple tasks to save costs
  6. Set max_tokens appropriately to control costs

Claude Code vs Claude API

Claude CodeClaude API
UseAI coding agentBuild custom apps
InterfaceTerminal / IDEHTTP / SDK
BillingSubscriptionPay-per-token
Best forCoding tasksCustom integration

Install Claude Code → for coding. Use the API for building applications.

Not working?

Check common errors and instant fixes in the Error Fix Center.

Fix Errors →