Anthropic Client Reference

Purpose and Scope

This page documents the public client entrypoint for the main package, @anthropic-ai/sdk. The client is the object application code instantiates before calling Claude API resources such as messages, models, files, batches, beta resources, and helper layers. In normal usage, you import the default Anthropic export, construct it once with authentication and optional configuration, and then call resource methods from that instance. This page focuses on the package boundary: what is exported, how the constructor is shown to users, and how the package metadata maps runtime imports to built artifacts.

Sources: src/index.ts, src/client.ts, package.json, README.md, api.md

The README frames this package as the Claude SDK for TypeScript and says it provides access to the Claude API from server-side TypeScript or JavaScript applications. That wording matters because the primary client is not an agent runtime by itself; it is the transport and resource wrapper for Claude Platform APIs. Official Claude documentation groups API capabilities into model behavior, tools, tool infrastructure, context management, and files/assets, and this SDK exposes those areas through typed resources and generated modules rather than asking callers to hand-build raw HTTP requests.

Sources: README.md, src/index.ts

Relevant Source Files

  • src/index.ts - Package source entrypoint. It re-exports Anthropic as the default export, exposes named client types such as BaseAnthropic, Anthropic, ClientOptions, and APIRequest, and surfaces core helpers, errors, pagination, uploads, middleware, and parser types.
  • src/client.ts - Client implementation module behind the exported Anthropic, BaseAnthropic, ClientOptions, HUMAN_PROMPT, and AI_PROMPT symbols re-exported by src/index.ts. Use this path when tracing constructor behavior and resource initialization.
  • package.json - Published package metadata for @anthropic-ai/sdk, including types, CommonJS main, package exports, optional zod peer dependency, browser replacements, the CLI binary name, and build/test scripts.
  • README.md - First-party usage documentation for installation, the canonical default import pattern, apiKey behavior, Messages quickstart code, TypeScript version support, supported runtimes, and browser credential safety.
  • api.md - Repository API reference companion for the generated public surface. Use it alongside the TypeScript declarations when auditing exported classes, resource methods, and types.

Public Entrypoint and Exports

The package source entrypoint is intentionally thin. src/index.ts exports Anthropic from ./client as the default export, and then re-exports the same Anthropic class as a named export with BaseAnthropic, ClientOptions, and APIRequest. That means both default-import and named-import styles can be supported by the generated distribution, while the implementation remains centralized in src/client.ts. The entrypoint also exports low-level primitives that advanced users need when composing integrations: upload conversion, API promises, pagination promises, middleware types, parser types, and typed error classes.

Sources: src/index.ts, src/client.ts

The published package metadata reinforces that src/index.ts is the source-level boundary and dist/index.* is the runtime boundary. The package is named @anthropic-ai/sdk, has types pointing to dist/index.d.ts, and has CommonJS main pointing to dist/index.js. Its exports field maps the package root to ./dist/index.mjs for import consumers and ./dist/index.js for require consumers. Subpath export patterns also map ./*, ./*.js, and ./*.mjs to built distribution files, which is important for users who import helper modules directly.

Sources: package.json, src/index.ts

Compact export reference

Public nameExported fromRole
Anthropic default exportsrc/index.ts from ./clientPrimary client constructor for the direct Claude API package.
Anthropic named exportsrc/index.ts from ./clientNamed import form of the same client.
BaseAnthropicsrc/index.ts from ./clientBase client class exported for generated or advanced SDK composition.
ClientOptionssrc/index.ts from ./clientConstructor options type for the client.
APIRequestsrc/index.ts from ./clientRequest type exported from the client module.
HUMAN_PROMPT, AI_PROMPTsrc/index.ts from ./clientLegacy prompt constants kept on the public package surface.
APIPromisesrc/index.ts from ./core/api-promisePromise wrapper used by SDK API calls.
PagePromisesrc/index.ts from ./core/paginationPromise wrapper for paginated list operations.
Error classessrc/index.ts from ./core/errorTyped failures such as authentication, rate limit, timeout, and server errors.

Constructor and Authentication Pattern

The README shows the canonical construction pattern: import Anthropic from @anthropic-ai/sdk, create new Anthropic({ apiKey: process.env['ANTHROPIC_API_KEY'] }), and then call client.messages.create. The inline README comment states that apiKey defaults to process.env['ANTHROPIC_API_KEY'] and can be omitted. In practice, this makes the environment variable the standard server-side credential path, while still allowing explicit injection when an application loads secrets from another configuration system, test harness, or deployment platform.

Sources: README.md, src/client.ts

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-4-6',
});
 
console.log(message.content);

The constructor options should be treated as process-wide client configuration, not as per-message prompt settings. Model choice, max_tokens, and conversation messages belong on client.messages.create, as shown in the README example. Authentication belongs on the client. Request-specific behavior, headers, middleware, retries, or streaming behavior may be configured through other exported SDK facilities, but this reference page only claims the symbols visible at the package boundary. When you need exact option names beyond apiKey and the documented browser flag, inspect ClientOptions in the generated declarations and src/client.ts.

Sources: README.md, src/index.ts, src/client.ts

Runtime, Browser, and Package Behavior

The README states that TypeScript 4.9 or later is supported for the main SDK. It lists Node.js 20 LTS or later, Deno 1.28.0 or higher, Bun 1.0 or later, Cloudflare Workers, Vercel Edge Runtime, Jest 28 or greater with the node environment, and Nitro 2.6 or greater as supported runtimes. It also explicitly says React Native is not supported at this time. These constraints belong in client-reference documentation because they affect whether importing and constructing Anthropic is expected to work in a target environment.

Sources: README.md, package.json

Browser support is deliberately guarded. The README says web browsers are disabled by default to avoid exposing secret API credentials, and that browser support must be enabled by setting dangerouslyAllowBrowser to true. That option name communicates the security tradeoff: a browser bundle can expose API keys to end users, so most production browser applications should call the SDK from a server, edge function, or trusted backend instead. The package.json browser mappings also show that some Node-oriented tool modules are replaced with browser-specific builds in packaged output.

Sources: README.md, package.json

Error, Upload, Middleware, and Helper Surface

Although the Anthropic constructor is the center of the public API, the package entrypoint exports several related primitives that client users commonly encounter. Upload support is exposed through Uploadable and toFile, which helps callers pass files into API methods that accept multipart-style inputs. Middleware types and fallback middleware exports support request/response interception and beta fallback behavior. Parser types support structured-output workflows. Typed errors such as AuthenticationError, RateLimitError, APIConnectionTimeoutError, and InternalServerError let applications distinguish credential failures, throttling, network problems, and service-side failures without string-matching messages.

Sources: src/index.ts, package.json

The package also declares an optional zod peer dependency accepting version 3.25 or 4.0 ranges. That does not make Zod required for basic client construction or ordinary Messages calls, but it signals that typed schema helpers are part of the broader SDK ecosystem. If your application only imports the default Anthropic client and calls generated resources, the core package dependencies remain small. If you use Zod-based helpers for structured outputs or tools, ensure your application supplies a compatible Zod version.

Sources: package.json, src/index.ts

Usage Guidance and Next Steps

For most applications, start with the README pattern: install @anthropic-ai/sdk, create one Anthropic client using the ANTHROPIC_API_KEY environment variable, and call client.messages.create from server-side code. Keep credentials out of browser bundles unless you have deliberately accepted the dangerouslyAllowBrowser risk. Prefer the default package import for ordinary usage, and use named exports when you need typed errors, pagination wrappers, upload helpers, middleware types, parser types, or the ClientOptions type in application code.

Sources: README.md, src/index.ts, package.json

Next, read the Messages resource reference when you need request and response details for client.messages.create, the authentication and client configuration guide when you need deployment-specific configuration, and the request options/errors/retries page when you need operational behavior. If you are targeting AWS Bedrock, Google Vertex AI, or Microsoft Foundry instead of the direct Claude API at api.anthropic.com, use the provider-specific SDK packages rather than substituting provider credentials into the main Anthropic client.

Sources: README.md, package.json