Anthropic provides first-party SDKs for four languages: Python, TypeScript, Go, and Java. These SDKs wrap the raw REST API with idiomatic helpers, type safety, automatic retries, and streaming utilities — dramatically reducing boilerplate and improving reliability in production.
The Python SDK (anthropic) is the most mature and widely used. It provides synchronous and async clients, streaming helpers, and full type annotations.
# Installation
pip install anthropic
# Basic usage
import anthropic
client = anthropic.Anthropic() # Uses ANTHROPIC_API_KEY env var
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude!"}]
)
print(message.content[0].text)
# Streaming
with client.messages.stream(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a poem."}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
The TypeScript SDK (@anthropic-ai/sdk) provides full type safety, streaming iterators, and works in both Node.js and edge runtimes (Deno, Bun, Cloudflare Workers).
// Installation
// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic(); // Uses ANTHROPIC_API_KEY env var
const message = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello, Claude!" }]
});
console.log(message.content[0].text);
// Streaming
const stream = client.messages.stream({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "Write a haiku." }]
});
for await (const event of stream) {
if (event.type === "content_block_delta") {
process.stdout.write(event.delta.text);
}
}
Anthropic also offers official SDKs for Go (github.com/anthropics/anthropic-sdk-go) and Java (com.anthropic:anthropic-java). Both provide idiomatic interfaces, streaming support, and automatic retries.
| Feature | Description |
|---|---|
| Automatic Retries | All SDKs implement exponential backoff with jitter for 429 and 5xx errors (default: 2 retries). |
| Streaming Helpers | High-level abstractions for SSE streaming — no manual event parsing required. |
| Type Safety | Full type definitions for all request/response objects, enabling IDE autocompletion and compile-time checks. |
| WIF Support | Workload Identity Federation for GCP and AWS — authenticate without static API keys using cloud-native identity. |
| Environment Config | API key auto-loaded from ANTHROPIC_API_KEY environment variable. Base URL configurable for proxies. |