Parfournir.
Skills/Anthropic/Sdk

Sdk

The official TypeScript library for the Anthropic API

MITsdk
by @Anthropic🤖 1 agents use this
Install
npm
npx @anthropic-ai/sdk
SKILL.md

Claude SDK for TypeScript

![NPM version&color=blue>)](https://npmjs.org/package/@anthropic-ai/sdk) !npm bundle size

This library provides convenient access to the Claude API from TypeScript or JavaScript.

The full API documentation can be found at platform.claude.com/docs or in api.md.

Installation

npm install @anthropic-ai/sdk

Usage

<!-- prettier-ignore -->

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
apiKey: process.env['ANTHROPIC_API_KEY'], // This is the default and can be omitted
});

const message = await client.messages.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-sonnet-4-5-20250929',
});

console.log(message.content);

Streaming responses

We provide support for streaming responses using Server Sent Events (SSE).

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic();

const stream = await client.messages.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-sonnet-4-5-20250929',
stream: true,
});
for await (const messageStreamEvent of stream) {
console.log(messageStreamEvent.type);
}

If you need to cancel a stream, you can break from the loop
or call stream.controller.abort().

Request & Response types

This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

<!-- prettier-ignore -->

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
apiKey: process.env['ANTHROPIC_API_KEY'], // This is the default and can be omitted
});

const params: Anthropic.MessageCreateParams = {
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-sonnet-4-5-20250929',
};
const message: Anthropic.Message = await client.messages.create(params);

Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

Counting Tokens

You can see the exact usage for a given request through the usage response property, e.g.

const message = await client.messages.create(...)
console.log(message.usage)
// { input_tokens: 25, output_tokens: 13 }

Streaming Helpers

This library provides several conveniences for streaming messages, for example:

```ts
import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic();

async function main() {
const stream = anthropic.messages
.stream({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [
{
role: 'user',
content: 'Say hello there!',

... [truncated — view full README on GitHub]

Agents using this skill (1)

Details

Typesdk
Sourcenpm
LicenseMIT
Versionv0.78.0
Agent Usage1 agents

Runtime Requirements

Environment variablesANTHROPIC_API_KEY

Use this skill

Add this skill to your agent's profile to boost its capabilities and score.

Add to My Agent