
Security News
PHP Foundation Says Chainguard Broke Security Embargo Ahead of Emergency Patches
The PHP Foundation says Chainguard broke a security embargo ahead of critical RCE patches, as leaks disrupted the coordinated release.
@anthropic-ai/sdk
Advanced tools
The Claude SDK for TypeScript provides access to the Claude API from server-side TypeScript or JavaScript applications.
SDK helpers (streaming, structured outputs, tool helpers and the tool runner) are documented in helpers.md. The browser and computer toolset classes have their own guides, browser-toolset.md and computer-toolset.md.
Full documentation is available at platform.claude.com/docs/en/api/sdks/typescript.
npm install @anthropic-ai/sdk
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-opus-5-5',
});
console.log(message.content);
TypeScript >= 5.0 is supported.
The following runtimes are supported:
"node" environment ("jsdom" is not supported at this time).dangerouslyAllowBrowser to true.Note that React Native is not supported at this time.
If you are interested in other runtime environments, please open or upvote an issue.
The SDK reports each API call as an OpenTelemetry span once your application has registered a tracer provider with @opentelemetry/api, which the SDK depends on.
Spans are on by default, so there is nothing to enable on the client.
The openTelemetry client option selects another tracer provider, turns the spans or the trace headers off, or, with traces.contentMode: 'content', adds the content of requests and responses to them.
const client = new Anthropic({ openTelemetry: { tracerProvider } }); // a provider other than the registered one
const quiet = new Anthropic({ openTelemetry: false }); // no spans
const detailed = new Anthropic({
openTelemetry: { traces: { contentMode: 'content', maxContentBytes: 65_536 } }, // content, up to about 64 KiB a span
});
const unpropagated = new Anthropic({ openTelemetry: { propagation: false } }); // spans, and no trace headers on the requests
await client.messages.create(params, { openTelemetry: { conversationId } }); // sets gen_ai.conversation.id
traces is a boolean, or an object with enabled, contentMode and maxContentBytes.
With each request the client sends the trace context of its span, as the headers that your registered propagator writes: traceparent, and tracestate and baggage when it writes them.
propagation: false sends none of them and leaves the spans as they are, for an application whose HTTP client instrumentation already propagates the trace context, so that a request does not carry it twice.
A field that the option leaves unset has its default.
A client without the option reads these environment variables once, when it is constructed: ANTHROPIC_OPEN_TELEMETRY=false turns its spans off, ANTHROPIC_OPEN_TELEMETRY_PROPAGATION=false turns propagation off, and ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE and ANTHROPIC_OPEN_TELEMETRY_TRACES_MAX_CONTENT_BYTES give contentMode and maxContentBytes.
A client with the option does not read them.
client.openTelemetry is the option as the client settled it.
A withOptions() copy that passes openTelemetry uses that in place of the client's whole option, so spread the settled one to change a single setting:
const { openTelemetry } = client;
const withContent = client.withOptions({
openTelemetry: { ...openTelemetry, traces: { ...openTelemetry.traces, contentMode: 'content' } },
});
See CONTRIBUTING.md.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
The official TypeScript library for the Anthropic API
The npm package @anthropic-ai/sdk receives a total of 19,903,579 weekly downloads. As such, @anthropic-ai/sdk popularity was classified as popular.
We found that @anthropic-ai/sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 15 open source maintainers collaborating on the project.

Security News
The PHP Foundation says Chainguard broke a security embargo ahead of critical RCE patches, as leaks disrupted the coordinated release.

Security News
PHP releases emergency patches for two critical RCE vulnerabilities as agencies urge organizations to take unpatched sites offline.

Threat Research
/Security News
A supply chain attack compromised LiteLLM 1.107.0 on PyPI and Docker, spreading malware that steals cloud credentials, developer secrets, and AI provider keys.