Originally published at claudeguide.io/claude-api-typescript-tutorial
Claude API TypeScript Tutorial: Complete Guide with Node.js Examples
The Anthropic TypeScript SDK (@anthropic-ai/sdk) provides full type coverage for every API surface — MessageParam, Message, ContentBlock, streaming events, and tool use schemas — so you catch malformed requests at compile time rather than at runtime. Install with npm install @anthropic-ai/sdk, set ANTHROPIC_API_KEY in your environment, and you have a strongly-typed client that works in Node.js, Deno, and Next.js edge or server runtimes in 2026.
How do I install the Anthropic TypeScript SDK?
npm install @anthropic-ai/sdk
# peer dependency for env file loading
npm install dotenv
The SDK ships its own type declarations — no @types/ package needed. Your tsconfig.json needs moduleResolution set to node16 or bundler to resolve the package's subpath exports correctly:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "node16",
"strict": true,
"outDir": "dist"
}
}
If you are on an older TypeScript project using "moduleResolution": "node", upgrade to node16 or bundler. The SDK will show type errors under the legacy resolver.
How do I make a basic API call with TypeScript types?
Import the SDK's named types alongside the default client. The key types you will use on every call are MessageParam (for input) and Message (for the response):
typescript
import Anthropic from "@anthropic-ai/sdk";
import type { MessageParam, Message, ContentBlock } from "@anthropic-ai/sdk/resources";
import * as dotenv from "dotenv";
dotenv.config();
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY, // defaults to env var if omitted
});
async function basicCall(): Promise<void
[→ Get the Agent SDK Cookbook — $49](https://shoutfirst.gumroad.com/l/ogxhmy?utm_source=claudeguide&utm_medium=article&utm_campaign=claude-api-typescript-tutorial)
*30-day money-back guarantee. Instant download.*
Top comments (0)