Features
- Full TypeScript type definitions for all API types
- Streaming with async iterators
- Automatic retries with exponential backoff
- Tool use with typed input schemas
Pros
- Excellent type safety catches errors at compile time
- Idiomatic async/await API
- Auto-imports environment variables for API key
Cons
- Node.js runtime required (not browser-compatible)
- Streaming types can be complex
- Breaking changes between major versions
Overview
The Anthropic TypeScript SDK provides a fully typed interface to the Claude API. It is designed for Node.js server-side applications and offers complete type definitions for all request and response types, making it easy to use the API without consulting documentation for every field.
The SDK supports all Claude features: text generation, streaming with async iterators, tool use with JSON Schema input validation, vision (image understanding), and multi-turn conversations. It handles authentication, retries, and error handling automatically.
For TypeScript developers, the SDK provides discriminated unions for content blocks (text vs. tool use), typed tool input schemas, and proper generic types for streaming events.
When to Use
Use the TypeScript SDK for any Node.js backend that needs to interact with Claude. It is the standard choice for TypeScript/JavaScript server applications, API routes, and serverless functions.
Getting Started
npm install @anthropic-ai/sdk
import Anthropic from '@anthropic-ai/sdk'
const client = new Anthropic() // reads ANTHROPIC_API_KEY from env
const stream = client.messages.stream({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Explain async/await' }]
})
for await (const event of stream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
process.stdout.write(event.delta.text)
}
}