Claude API Guide for Developers
Claude API Guide
A practical guide to the Claude API — authentication, model selection, pricing, and code examples to get your first integration running quickly.
ClaudeAIHub. All facts below are sourced from official Anthropic documentation.
What Is the Claude API?
The Claude API is a RESTful interface that gives developers programmatic access to Claude models. Instead of using Claude through the chat interface at claude.ai, the API lets you call Claude directly from your own application, script, or service.
The API base URL is https://api.anthropic.com. All requests go through Anthropic’s infrastructure and are billed based on the tokens you send and receive.
Claude App vs Claude API: What’s the Difference?
These are two separate products with separate billing:
| Feature | Claude App (claude.ai) | Claude API |
|---|---|---|
| Who it’s for | Individuals, teams | Developers, businesses |
| How you access it | Browser, mobile, desktop app | HTTP requests, SDKs |
| Billing | Monthly subscription (Free/Pro/Max/Team) | Pay per token used |
| Setup | Sign up, use in browser | Create API key, write code |
| Customization | Limited to UI settings | Full system prompts, parameters |
A Claude Pro subscription does not give you API access. API billing is separate and managed through the Anthropic Console (external link).
The Anthropic Console
The Anthropic Console (external link) is where you manage everything API-related:
- Create and manage API keys
- Test prompts in the Workbench before coding
- View usage and billing
- Set spend limits and rate limits
- Manage workspaces (for teams)
You’ll need a Console account (free to create) before you can make any API calls.
API Keys and Authentication
Every API request requires an API key. You generate keys in the Console under Account Settings → API Keys. Every API request must include these headers:
x-api-key: YOUR_API_KEY
anthropic-version: 2023-06-01
content-type: application/json
If you use an official SDK, these headers are handled automatically. See the Claude API Key guide for full setup and security instructions.
The Messages API
The core endpoint is the Messages API: POST /v1/messages. You send a list of messages, and Claude returns a response. A basic request looks like this:
# Python SDK example
import anthropic
client = anthropic.Anthropic(api_key="YOUR_API_KEY")
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain what a REST API is in one paragraph."}
]
)
print(message.content[0].text)
Other available API endpoints include the Message Batches API (async, 50% cheaper), Token Counting API, Files API (beta), and Models API.
Current Claude Models for API Use
As of the time of this guide (source: official Anthropic model docs), the current models available via API are:
| Model | API ID | Context Window | Input Price | Output Price | Best For |
|---|---|---|---|---|---|
| Claude Fable 5 | claude-fable-5 | 1M tokens | $10/MTok | $50/MTok | Most demanding reasoning, long-horizon agentic work |
| Claude Opus 4.8 | claude-opus-4-8 | 1M tokens | $5/MTok | $25/MTok | Complex reasoning, agentic coding |
| Claude Sonnet 4.6 | claude-sonnet-4-6 | 1M tokens | $3/MTok | $15/MTok | Speed + intelligence balance |
| Claude Haiku 4.5 | claude-haiku-4-5-20251001 | 200k tokens | $1/MTok | $5/MTok | Fastest, high-volume tasks |
Prices are per million tokens (MTok). Always verify current pricing at the official Anthropic pricing page (external link) as rates can change.
Claude Fable 5 API notes: launched June 9, 2026, claude-fable-5 uses adaptive thinking (always on) and does not support manual extended thinking. Like Opus 4.7 and later, it does not accept temperature, top_p, or top_k. Some requests can be routed to Opus 4.8 by safety classifiers. Claude Mythos 5 (claude-mythos-5) appears in Anthropic’s docs but is restricted to approved Project Glasswing customers — it is not available for normal API sign-ups. See the Claude Fable 5 guide and Claude Mythos 5 overview.
See our Claude models guide for a full breakdown of capabilities, context windows, and use-case recommendations.
API Pricing: What You Need to Know
API billing is token-based, not subscription-based. Key points:
- Input tokens: tokens in your prompt (system + user messages)
- Output tokens: tokens Claude generates in its response
- Batch API: 50% discount on async batch requests
- Prompt caching: reduces input costs for repeated context
- Free tier: new accounts may include a small credit, but verify this at signup — it changes
There is no flat monthly fee for the API. You pay for what you use. Monitor usage in the Console to avoid unexpected bills.
Getting Started: Step-by-Step Workflow
- Create a Console account at platform.claude.com
- Add a payment method (required before API access)
- Create an API key in Console → Settings → API Keys
- Install the Python or TypeScript SDK (
pip install anthropicornpm install @anthropic-ai/sdk) - Store your key safely in an environment variable (never in code)
- Test a small prompt using the code example above
- Monitor your usage in the Console dashboard
For a detailed walkthrough of API key security, see our Claude API Key guide. For coding workflows that use Claude via API, see our Claude for coding guide.
Official SDKs
Anthropic provides official SDKs for:
- Python (
pip install anthropic) - TypeScript / Node.js (
npm install @anthropic-ai/sdk) - Java, Go, C#, Ruby, PHP (see official SDK docs)
SDKs handle authentication headers, retries, and streaming automatically.
Security and Safe API Use
API keys grant access to your account and your billing. Treat them like passwords:
- Never put your API key in your source code. Use environment variables (
ANTHROPIC_API_KEY). - Never commit a .env file containing your key to GitHub or any public repo.
- Use separate keys per project so you can rotate one without affecting others.
- Monitor your Console usage regularly — a leaked key can generate unexpected charges.
- Rotate leaked keys immediately. In Console → API Keys, delete the old key and create a new one.
- Set spend limits in the Console to cap monthly API costs.
- Review model outputs before showing them to end users — don’t auto-publish AI responses.
Claude API vs Cloud Platforms
Claude is also available through AWS Bedrock, Google Vertex AI, Microsoft Foundry, and Claude Platform on AWS. If you already use one of these cloud platforms, those options may simplify billing and compliance. Direct API access gives you the latest models and features first.
Related Guides
- Claude API Key: Setup and Safety
- Claude Models: Opus, Sonnet, and Haiku Explained
- Claude for Coding: Developer Workflows
- Claude Prompt Templates and Guide
- Is Claude AI Free? Plans and Pricing
Building tool-calling workflows with Claude? The Claude Tool Use Guide covers the full function-calling API with Python examples, JSON schema definitions, and tool_choice options.
Frequently Asked Questions
Related tools: use the Claude API Cost Estimator to estimate token costs before you build, the Claude Model Selector to find the right model for your task, and the Claude Prompt Caching Guide to reduce costs on repeated context.