Python
PIP# Install $ pip install anthropic # Authenticate $ export ANTHROPIC_API_KEY="sk-ant-..." # First call import anthropic client = anthropic.Anthropic() msg = client.messages.create( model="claude-sonnet-4-6", max_tokens=512, messages=[...])
Every Claude model - Opus, Sonnet, Haiku - through one stable interface. Tool use, vision, batch, streaming, and prompt caching, in three official SDKs. $5 free credit when you sign up.
import anthropic client = anthropic.Anthropic() response = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, messages=[{ "role": "user", "content": "Hello, Claude!" }] ) print(response.content[0].text) # → "Hello! How can I help today?"
import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); const response = await client.messages.create({ model: "claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Hello, Claude!" }] }); console.log(response.content[0].text);
$ curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello, Claude!"} ] }'
No setup wizard. No CLI install. Generate a key, set an env var, paste five lines of code. Most people are streaming tokens in under five minutes.
Sign in at console.anthropic.com with email or Google. New accounts get $5 in credit, no payment method required.
# Free $5 credit on signup
console.anthropic.com
Pick Python, TypeScript, or use cURL directly. Community libraries exist for Go, Java, Ruby, Rust, and more.
# Pick your language
$ pip install anthropic
Set the env var, instantiate the client, send a message. The shape stays identical across every Claude model and every SDK.
# It's really this short
$ python first_call.py
Modern AI workloads need more than text-in, text-out. The Claude API ships the primitives engineers actually reach for - and they all work together.
Server-sent events stream tokens as they're generated. Time-to-first-token in the low hundreds of milliseconds.
stream: trueFunction calling with structured args. Define tools as JSON schemas; Claude picks, fills, and chains them.
tools: [...]Image inputs natively — PDFs, screenshots, charts, diagrams. Same models, same endpoint, more context.
type: "image"Async processing for large workloads at half the cost. Ideal for backfills and overnight pipelines.
— 50% costCache static prompt prefixes (system messages, tool defs, RAG context) for up to 90% cost savings.
— 90% costReliable JSON via tool use, plus prefill techniques and response_format hints. No more regex hacks.
strict JSONNative support for the Model Context Protocol. Plug Claude into your existing tool ecosystem in one config.
mcp_servers: [...]200,000-token context window across all current models. Drop in entire codebases, books, or RAG corpora.
200,000 tokensSwap models by changing one string. Same SDK, same endpoints, same response format - pick the intelligence you need at the price you want.
| Model | API string | Input ($ / M) | Output ($ / M) | Best for |
|---|---|---|---|---|
| Opus 4.7 Newest | claude-opus-4-7 | $15.00 | $75.00 | Hardest reasoning, agents |
| Sonnet 4.6 Default | claude-sonnet-4-6 | $3.00 | $15.00 | Most everyday tasks |
| Haiku 4.5 Fastest | claude-haiku-4-5 | $0.25 | $1.25 | High volume, low latency |
Cut input + output cost in half on async workloads — ideal for backfills, evals, and overnight jobs.
Cache long system prompts, tool defs, or RAG context. Repeated calls cost a fraction of full-price input.
Enough for thousands of Haiku calls or hundreds of Sonnet calls. Spend it however you want.
Sign in, click "Create Key," paste it into your env. Whatever you ship next is one Anthropic SDK call away from being smarter.
First-party libraries for Python, TypeScript, and direct HTTP via cURL. Streaming, tool use, vision, and batch — all supported identically across each.
# Install $ pip install anthropic # Authenticate $ export ANTHROPIC_API_KEY="sk-ant-..." # First call import anthropic client = anthropic.Anthropic() msg = client.messages.create( model="claude-sonnet-4-6", max_tokens=512, messages=[...])
// Install $ npm i @anthropic-ai/sdk // Authenticate $ export ANTHROPIC_API_KEY="sk-ant-..." // First call import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); const msg = await client.messages.create({ model: "claude-sonnet-4-6", max_tokens: 512, messages: [...] });
# Direct HTTP — any language $ curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{ "model": "claude-sonnet-4-6", "max_tokens": 512, "messages": [...] }'
A snapshot of the workloads developers send through the Claude API every day. Each one is a real production pattern, not a "hello world."
Multi-file code edits, refactors, test generation, debugging across a repo. Pair Sonnet for routine ops with Opus for hard reasoning.
Build it → RAGVector search → Claude as the answer step. 200K context lets you skip clever chunking and just feed the docs.
Build it → ChatTriage, draft responses, escalate to humans. Tool use + brand-voice system prompts produce ticket replies you can ship.
Build it → PipelineModeration, classification, sentiment, summarization. Run on Haiku via the Batch API and pay cents per thousand items.
Build it → ExtractPull structured data from invoices, contracts, screenshots, PDFs. Use vision + tool use for reliable JSON output.
Build it → InternalSlack bots, dashboards, ops automation. Wrap Claude with your company's data via prompt caching for fast, cheap answers.
Build it →No drama, no FUD. Here's a clear-eyed look at how the Claude API stacks up against the other major LLM providers — focused on what API users actually care about.
| Claude API | OpenAI API | Gemini API | |
|---|---|---|---|
| Free credit on signup | $5 | Limited / promo | Free tier |
| Context window (top tier) | 200K | ~200K (1M-context) | 1M+ |
| Tool use / function calling | ✓ | ✓ | ✓ |
| Vision (image input) | ✓ | ✓ | ✓ |
| Batch API discount | 50% off | 50% off | Limited |
| Prompt caching | Up to 90% off | Auto, ~50% | Yes |
| MCP support | Native | No | No |
| Image generation | No | DALL·E | Imagen |
| Strongest for | Agents, code, long-context | Breadth + plugins | Multimodal + 1M context |
Pricing and feature parity move fast. Verify current rates at anthropic.com/pricing before committing.
The questions teams ask most often before they cut over a workload.
Roughly five minutes. Sign in at console.anthropic.com, generate a key, run pip install anthropic, paste five lines of code, hit run. The hardest step is usually deciding which model to pass.
$5 on signup, no payment method required to start. On Haiku 4.5 that's roughly 20 million input tokens — enough for thousands of small calls. On Sonnet it's about 1.6M input tokens. On Opus it's smaller but plenty to evaluate.
The Messages API is stable on v1. Models are pinned by API string (claude-sonnet-4-6, claude-opus-4-7, etc.) so you control upgrades. Anthropic publishes a deprecation timeline for older models with long sunset windows.
Yes — that's the design. Change the model string in your call. Same request shape, same response shape, same SDK. Most teams ship A/B comparisons across Haiku / Sonnet / Opus without touching anything else.
Yes — pass stream: true (TS) or use messages.stream() (Python) and you get a server-sent event stream of incremental text. Time-to-first-token is typically a few hundred milliseconds, depending on prompt length.
Full tool-use (function calling) is supported with JSON-schema input definitions. For strict JSON output, define a tool with the schema you want and let Claude call it. Tool use docs →
Prompt caching saves up to 90% on repeated context (system prompts, tool defs, large RAG context). The Batch API gives 50% off all input/output. They stack — async workloads with stable system prompts can run at a fraction of nominal cost.
By default, Anthropic does not use API customer data to train its generative models. Enterprise plans support zero data retention. Full details at anthropic.com/privacy.
Limits are tier-based and scale automatically as you spend more. New accounts start with reasonable defaults sufficient for development and small production workloads. For higher limits or guaranteed throughput, see Scale Plan / Enterprise.
Python and TypeScript are first-party. Anthropic also publishes SDKs for Java and Go, with active community libraries for Ruby, Rust, .NET, PHP, and others. Direct HTTP via cURL works from anywhere.
Yes — status.anthropic.com tracks API uptime, incidents, and degraded regions. Subscribe via RSS or email for production monitoring.
Generate a key. Paste the snippet. Watch tokens stream back. The whole loop takes less time than reading this page — and the next thing you ship gets noticeably smarter.
$ pip install anthropic · $ npm i @anthropic-ai/sdk · $5 free credit · no card