Anthropic SDK TypeScript

Active
GitHub TypeScript MIT

Description

Anthropic's official TypeScript SDK offering type-safe, Promise-based access to the Claude API with streaming responses and tool-use support.

Key Features

  • Type-safe API client — Full TypeScript types aligned with the Claude API for end-to-end type inference on requests and responses
  • Streaming response support — Built-in SSE streaming parser for real-time chat and incremental token rendering in agents
  • Tool-use primitives — Wraps the tool_use / tool_result protocol to simplify agent function calling
  • Prompt caching — Honors Anthropic's prompt cache headers to reduce repeated prompt cost
  • Cross-runtime compatibility — Works across Node.js, browser, Deno, edge runtime, and Bun
  • Automatic retries and timeouts — Built-in exponential backoff and timeout controls for production-grade agent calls

Use Cases

💡 Integrate Claude models as the inference engine of an agent in TypeScript / Node.js backends
💡 Build type-safe Claude clients and streaming UIs for front-end chat products
💡 Implement reusable tool-use wrappers to compose custom agent frameworks
💡 Deploy Claude-powered AI applications on Deno, Cloudflare Workers, Vercel Edge, and other serverless runtimes
💡 Leverage prompt caching to reduce cost and latency for long system prompts

Quick Start

npm install @anthropic-ai/sdk
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const msg = await client.messages.create({
  model: 'claude-sonnet-4-6',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello, Claude' }],
});
console.log(msg.content[0].text);

Related Projects