Anthropic TypeScript SDK
The official TypeScript and JavaScript SDK for building on Anthropic's Claude API.
Repository Health
Technical Analysis
The Anthropic TypeScript SDK is the official client library for the Claude API, giving server-side TypeScript and JavaScript applications a fully typed interface to Anthropic’s language models. It wraps the REST API with ergonomic resource methods for messages, streaming, token counting, batches, and model metadata, so you can go from an API key to a working request in a handful of lines.
Beyond the raw endpoints, the SDK ships higher-level helpers for streaming events, tool use, and structured outputs backed by Zod or JSON Schema, plus automatic retries, configurable timeouts, and pluggable middleware. It runs across Node.js, Deno, Bun, Cloudflare Workers, and Vercel Edge, and serves as the foundation for the Bedrock, Vertex, AWS, Google Cloud, and Foundry adapter packages in the same repository.
What You Get
- A fully typed client covering the Messages, Models, Completions, and Batches endpoints of the Claude API.
- Streaming helpers that surface incremental message, text, and thinking events with typed accessors.
- Tool-use and structured-output helpers backed by Zod or JSON Schema for validated, typed responses.
- Built-in resilience: automatic retries with backoff, configurable timeouts, and request middleware hooks.
- Broad runtime support across Node.js, Deno, Bun, Cloudflare Workers, and Vercel Edge.
Common Use Cases
- Calling Claude for chat, summarization, extraction, or classification from a Node.js backend.
- Streaming model responses token-by-token into a web app or terminal UI.
- Building tool-using agents that validate model output against Zod or JSON Schema.
- Running high-volume asynchronous jobs through the Message Batches API.
Under The Hood
Architecture
The library is generated from Anthropic’s OpenAPI specification by Stainless and then extended with hand-written helpers. The entry point src/client.ts defines the Anthropic client, which composes a request pipeline (src/internal/request-options.ts, src/core/api-promise.ts), a credentials chain (src/lib/credentials/), platform detection (src/internal/detect-platform.ts), retry/backoff logic, and pluggable middleware (src/core/middleware.ts). Endpoints are modeled as resource classes under src/resources/ (for example messages/, models.ts, completions.ts, and the beta/ namespace), while streaming, pagination, and uploads live in dedicated modules (src/lib/MessageStream.ts, src/core/pagination.ts, src/core/uploads.ts). Higher-level ergonomics — tool toolsets, memory, and structured outputs — sit in src/helpers/ and src/tools/.
Tech Stack
Written almost entirely in TypeScript (~99% of the codebase), the runtime footprint is deliberately small: only standardwebhooks and json-schema-to-ts are hard dependencies, with zod as an optional peer dependency for schema-validated helpers. The build uses tsc-multi to emit CommonJS and ESM outputs plus Deno-compatible builds, and the project targets TypeScript 4.9+ and Node.js 20+. Tooling includes Jest with SWC for tests, ESLint 9, and Prettier.
Code Quality
The repository carries a substantial test suite — roughly 83 test files under tests/ covering client behavior, streaming, pagination, and helpers, exercised with nock for HTTP mocking. Generated code keeps naming and typing consistent across every endpoint, and hand-written helper modules follow the same conventions. Error handling is centralized through a typed error hierarchy (src/core/error.ts) that maps HTTP failures to specific exception classes, and releases are automated via release-please with a detailed changelog.
API Design
The public API is intentionally minimal and discoverable: instantiate new Anthropic({ apiKey }) and call resource methods like client.messages.create(...). Streaming is a first-class .stream() variant with typed event handlers, and tool use plus structured outputs are wrapped in Zod/JSON-Schema helpers that eliminate manual parsing boilerplate. Documentation is thorough — a README quickstart, a large api.md reference, a helpers.md guide, a MIGRATION.md, and 30-plus runnable examples — making the getting-started path short despite the breadth of capabilities.
Used by 63 apps in this directory
Helicone
AI Development · Analytics · Monitoring
An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.
Helicone
AI Development · Analytics · Monitoring
An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.
HyperDX
Analytics · Developer Tools · Monitoring
Open source observability platform that unifies logs, traces, metrics, and session replays on ClickHouse — now the core of ClickStack.
Kimi Code CLI
AI Agents · AI Code Assistants · Developer Tools
A single-binary, terminal-native coding agent that reads, edits, and runs code end to end, built by Moonshot AI for Kimi models but pluggable with Anthropic, OpenAI, and Google providers too.
Latitude
AI Agents · Monitoring
Open-source AI agent monitoring that catches what will break next before your users do.
LibreChat
AI Assistants · Developer Tools
Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.
Lightdash
Analytics · Data Engineering
The open-source Looker alternative that turns your dbt project's metrics and dimensions into governed, self-serve charts and dashboards — no license key required.
LiteLLM
AI Development · Developer Tools
Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.
LobeHub
AI Assistants · Automation · Productivity
Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.