src
The official Anthropic TypeScript/JavaScript SDK that provides programmatic access to Claude AI models. It includes the core SDK client plus specialized integrations for AWS Bedrock, Google Cloud Vertex AI, and Palantir Foundry, enabling developers to build AI-powered applications across multiple cloud platforms.
Tech Stack
Key Features
- Messages API Client
- Streaming Support
- Tool Runner Framework
- Zod Schema Integration
- AWS Bedrock Integration
- Vertex AI Integration
- Foundry Integration
- Message Batching
- MCP Protocol Support
- Beta Files API
Entry Points
Start here when working with this codebase
src/client.tsMain API client that orchestrates HTTP communication and provides unified interface for all API resources
Start here when adding new API methods, modifying request/response handling, or understanding how resources are wired together
src/index.tsCentralized public API aggregation - controls what gets exported from the SDK
Start here when adding new public types, classes, or functions that consumers should access
src/resources.tsModule aggregation for API resources - re-exports all resource modules
Start here when adding a new API resource category or understanding resource organization
src/helpers/index.tsUnified export interface for helper functions like Zod integration and JSON schema conversion
Start here when adding new helper utilities or schema validation features
packages/bedrock-sdk/jest.config.tsAWS Bedrock integration package configuration
Start here when modifying Bedrock-specific functionality or AWS authentication
packages/vertex-sdk/jest.config.tsGoogle Cloud Vertex AI integration package configuration
Start here when modifying Vertex AI-specific functionality
packages/foundry-sdk/jest.config.tsPalantir Foundry integration with Azure AD auth
Start here when modifying Foundry-specific functionality or Azure authentication
How to Make Changes
Common modification patterns for this codebase
Add a new API endpoint/resource
src/resources/completions.tsCreate new resource file following this pattern - define types, create class extending APIResource, implement methods
Pattern: See how Completions class defines CompletionCreateParams interface and create() method with _client.post()
src/resources/models.tsFor resources with multiple operations (list, get, etc), follow this pattern with pagination
Pattern: See how Models class implements retrieve() and list() with PagePromise for paginated results
src/resources.tsExport your new resource module - add export statement
Pattern: Add line like: export * from './resources/your-resource';
src/client.tsRegister resource on client - add property and instantiate in constructor
Pattern: See how 'messages: API.Messages' is declared and 'this.messages = new API.Messages(this)' in constructor
tests/api-resources/completions.test.tsCreate test file for new resource
Pattern: Follow test structure: mock client, test each method with expected params and response handling
Conventions to follow:
Add a new beta feature/resource
src/resources/beta/files.tsCreate beta resource file in beta directory
Pattern: See how Files class implements upload(), list(), delete(), download(), retrieveMetadata() methods
src/resources/beta/messages/messages.tsFor complex beta resources with sub-resources, follow nested structure
Pattern: See how Messages has 'batches: Batches' property for sub-resource access
tests/api-resources/beta/files.test.tsCreate test file in beta test directory
Pattern: Follow existing beta test patterns with proper mocking
Conventions to follow:
Add a new helper/utility function
src/helpers/zod.tsFor schema-related helpers, add to or follow pattern in zod.ts
Pattern: See zodToJsonSchema() function that converts Zod schemas to JSON schema format
src/helpers/json-schema.tsFor JSON schema manipulation, add to json-schema.ts
Pattern: See how schemas are converted for Anthropic's structured output system
src/helpers/index.tsExport new helper from index
Pattern: Add export statement to expose helper publicly
tests/resources/messages/parse.test.tsAdd tests for helper functionality
Pattern: See how structured output parsing is tested with mocked responses
Conventions to follow:
Add streaming functionality
src/lib/MessageStream.tsExtend or follow MessageStream pattern for new streaming features
Pattern: See how MessageStream handles SSE parsing and event emission
examples/mcp.tsCreate example demonstrating streaming usage
Pattern: See how anthropic.beta.messages.stream() is used with async iteration
Conventions to follow:
Add tool/function calling support
src/lib/tools/index.tsAdd tool definition or runner in tools module
Pattern: See existing tool execution framework structure
examples/tools-helpers-memory.tsCreate example showing tool integration
Pattern: See how beta memory tool integrates with filesystem backend and manages context
Conventions to follow:
Add a new example
examples/count-tokens.tsCreate example file following existing patterns
Pattern: See how count-tokens.ts demonstrates token counting with clear comments and error handling
examples/batch-results.tsFor batch/async operations, follow this pattern
Pattern: See how batch results are fetched and processed
Conventions to follow:
Add tests for existing functionality
tests/api-resources/messages/messages.test.tsFor API resource tests, follow this structure
Pattern: See how client is mocked, requests are tested with expected params, and responses are validated
tests/api-resources/messages/batches.test.tsFor resources with CRUD operations, test each method
Pattern: See tests for create, retrieve, list, delete, cancel operations
packages/bedrock-sdk/tests/client.test.tsFor SDK package tests, follow package-specific patterns
Pattern: See how Bedrock client tests mock fetch and validate request encoding
Conventions to follow:
Modify build/publish process
scripts/publish-packages.tsModify publishing logic for monorepo packages
Pattern: See how packages are published after releases
scripts/utils/postprocess-files.cjsModify build post-processing
Pattern: See how compiled output is cleaned and package exports are configured
Conventions to follow:
Coding Conventions
Standards and patterns used in this codebase
Monorepo structure: apps/ contains deployable applications, packages/ contains shared libraries
Packages: packages/bedrock-sdk, packages/foundry-sdk, packages/vertex-sdkFile naming uses: kebab-case, PascalCase (for components/classes)
eslint.config.mjs, jest.config.ts, count-tokens.ts, tools-helpers-memory.ts, publish-packages.tsTypeScript is the primary language
All new files should be .ts or .tsxTests use .test. pattern
Test files are named like component.test.ts or placed in __tests__/Configuration is centralized in config files
Config files: eslint.config.mjs, jest.config.tsDatabase operations are in data layer
Data files: src/helpers/json-schema.ts, src/lib/transform-json-schema.tsTypes are defined in dedicated type files
Type files: src/internal/builtin-types.ts, src/internal/types.tsShared utilities are in utils/ directory
Utility files: scripts/utils/postprocess-files.cjs, src/helpers/index.ts