- Spec files
npm-anthropic-ai--sdk
Describes: pkg:npm/@anthropic-ai/sdk@0.61.x
- Description
- The official TypeScript library for the Anthropic API providing comprehensive client functionality for Claude AI models.
- Author
- tessl
- Last updated
beta-features.md docs/
1# Beta Features23The Beta API provides access to experimental features, new capabilities, and preview functionality that may not be available in the main API. Beta features may change or be removed in future versions.45## Capabilities67### Beta API Access89Access beta features through the dedicated beta resource with feature-specific headers.1011```typescript { .api }12/**13* Beta features API providing access to experimental functionality14*/15class Beta extends APIResource {16/** File management operations */17files: Files;18/** Beta model information */19models: Models;20/** Beta message features */21messages: Messages;22}2324type AnthropicBeta =25| "computer-use-2024-10-22"26| "pdfs-2024-09-25"27| "token-counting-2024-11-01"28| "message-batches-2024-09-24"29| string[];30```3132**Usage Examples:**3334```typescript35import Anthropic from "@anthropic-ai/sdk";3637const client = new Anthropic();3839// Access beta files40const files = await client.beta.files.list();4142// Access beta models43const betaModels = await client.beta.models.list({44betas: ["computer-use-2024-10-22"],45});4647// Use beta message features48const message = await client.beta.messages.create({49model: "claude-3-5-sonnet-20241022",50max_tokens: 1024,51messages: [{ role: "user", content: "Hello with beta features!" }],52betas: ["pdfs-2024-09-25"],53});54```5556### File Management5758Upload, manage, and reference files in conversations through the beta files API.5960```typescript { .api }61/**62* File management for beta features63*/64class Files extends APIResource {65upload(params: FileUploadParams): APIPromise<FileMetadata>;66list(params?: FileListParams): PagePromise<FileMetadataPage, FileMetadata>;67retrieveMetadata(fileId: string, params?: FileRetrieveMetadataParams): APIPromise<FileMetadata>;68download(fileId: string, params?: FileDownloadParams): APIPromise<Response>;69delete(fileId: string, params?: FileDeleteParams): APIPromise<DeletedFile>;70}7172interface FileUploadParams {73/** File content to upload */74file: File | Blob;75/** Purpose of the file upload */76purpose: "vision";77/** Beta features to enable */78betas?: AnthropicBeta;79}8081interface FileMetadata {82/** Unique file identifier */83id: string;84/** Original filename */85filename: string;86/** File size in bytes */87size: number;88/** MIME type of the file */89type: string;90/** Upload timestamp */91created_at: string;92/** File purpose */93purpose: "vision";94}95```9697**Usage Examples:**9899```typescript100// Upload a file101const fileUpload = await client.beta.files.upload({102file: new File([imageData], "image.jpg", { type: "image/jpeg" }),103purpose: "vision",104betas: ["pdfs-2024-09-25"],105});106107console.log(`Uploaded file: ${fileUpload.id}`);108109// List uploaded files110const files = await client.beta.files.list();111for (const file of files.data) {112console.log(`${file.filename}: ${file.size} bytes`);113}114115// Use file in message116const message = await client.beta.messages.create({117model: "claude-3-5-sonnet-20241022",118max_tokens: 1024,119messages: [120{121role: "user",122content: [123{ type: "text", text: "What's in this image?" },124{ type: "image", source: { type: "file", file_id: fileUpload.id } }125]126}127],128betas: ["pdfs-2024-09-25"],129});130131// Download a file132const downloadResponse = await client.beta.files.download(fileUpload.id);133const fileContent = await downloadResponse.arrayBuffer();134135// Delete a file136await client.beta.files.delete(fileUpload.id);137```138139### Computer Use140141Interact with computer interfaces through Claude's computer use capabilities.142143```typescript { .api }144/**145* Computer use tool for screen interaction146*/147interface BetaComputerUseTool20241022 {148type: "computer_20241022";149name: "computer";150/** Screen dimensions */151display_width_px: number;152display_height_px: number;153/** Screen scaling factor */154display_number?: number;155}156157interface BetaComputerUseAction {158/** Action type */159action: "screenshot" | "click" | "type" | "key" | "scroll";160/** Click coordinates (for click action) */161coordinate?: [number, number];162/** Text to type (for type action) */163text?: string;164/** Key to press (for key action) */165key?: string;166/** Scroll direction and amount */167scrolling?: {168direction: "up" | "down" | "left" | "right";169pixels: number;170};171}172```173174**Usage Examples:**175176```typescript177// Enable computer use for a message178const computerMessage = await client.beta.messages.create({179model: "claude-3-5-sonnet-20241022",180max_tokens: 1024,181tools: [182{183type: "computer_20241022",184name: "computer",185display_width_px: 1920,186display_height_px: 1080,187}188],189messages: [190{191role: "user",192content: "Take a screenshot and describe what you see"193}194],195betas: ["computer-use-2024-10-22"],196});197```198199### PDF Support200201Enhanced PDF document processing and analysis capabilities.202203```typescript { .api }204/**205* PDF document source for beta features206*/207interface BetaBase64PDFSource {208type: "base64";209media_type: "application/pdf";210data: string;211}212213interface BetaURLPDFSource {214type: "url";215url: string;216}217218interface BetaDocumentBlockParam {219type: "document";220source: BetaBase64PDFSource | BetaURLPDFSource;221cache_control?: BetaCacheControlEphemeral;222}223```224225**Usage Examples:**226227```typescript228// Analyze a PDF document229const pdfMessage = await client.beta.messages.create({230model: "claude-3-5-sonnet-20241022",231max_tokens: 1024,232messages: [233{234role: "user",235content: [236{ type: "text", text: "Summarize this PDF document" },237{238type: "document",239source: {240type: "base64",241media_type: "application/pdf",242data: base64PdfData,243},244},245],246},247],248betas: ["pdfs-2024-09-25"],249});250```251252### Code Execution253254Execute code in a sandboxed environment with full input/output handling.255256```typescript { .api }257/**258* Code execution tools for beta features259*/260interface BetaCodeExecutionTool20250522 {261type: "code_execution_20250522";262name: "code_execution";263}264265interface BetaCodeExecutionResultBlock {266type: "code_execution_result";267code_execution_result: {268/** Exit code of the execution */269exit_code: number;270/** Standard output */271stdout?: string;272/** Standard error */273stderr?: string;274/** Generated files or artifacts */275artifacts?: BetaCodeExecutionArtifact[];276};277}278279interface BetaCodeExecutionArtifact {280/** Artifact type */281type: "image" | "text" | "data";282/** Artifact content */283content: string;284/** Content encoding */285encoding?: "base64" | "utf8";286}287```288289**Usage Examples:**290291```typescript292// Execute Python code293const codeMessage = await client.beta.messages.create({294model: "claude-3-5-sonnet-20241022",295max_tokens: 1024,296tools: [297{298type: "code_execution_20250522",299name: "code_execution",300}301],302messages: [303{304role: "user",305content: "Create a simple bar chart showing sales data"306}307],308betas: ["code-execution-2025-05-22"],309});310```311312### Advanced Message Features313314Beta message capabilities including enhanced streaming and batch processing.315316```typescript { .api }317/**318* Beta message features and enhancements319*/320class BetaMessages extends APIResource {321create(params: BetaMessageCreateParams): APIPromise<BetaMessage>;322stream(params: BetaMessageStreamParams): BetaMessageStream;323countTokens(params: BetaMessageCountTokensParams): APIPromise<BetaMessageTokensCount>;324}325326interface BetaMessageCreateParams extends MessageCreateParams {327/** Beta features to enable */328betas?: AnthropicBeta;329/** Enhanced caching options */330cache_control?: BetaCacheControlEphemeral;331/** Citation configuration */332citations?: BetaCitationsConfigParam;333}334```335336## Beta Error Types337338```typescript { .api }339/**340* Beta-specific error types341*/342class BetaError extends AnthropicError {}343class BetaAPIError extends BetaError {344status: number;345error: BetaErrorResponse;346}347class BetaAuthenticationError extends BetaAPIError {}348class BetaBillingError extends BetaAPIError {}349class BetaInvalidRequestError extends BetaAPIError {}350class BetaNotFoundError extends BetaAPIError {}351class BetaOverloadedError extends BetaAPIError {}352class BetaPermissionError extends BetaAPIError {}353class BetaRateLimitError extends BetaAPIError {}354class BetaGatewayTimeoutError extends BetaAPIError {}355356interface BetaErrorResponse {357type: string;358message: string;359}360```361362## Beta Feature Guidelines363364**Important Considerations:**3653661. **Stability**: Beta features may change or be removed without notice3672. **Compatibility**: Not all beta features work with all models3683. **Access**: Some beta features require special access or approval3694. **Rate Limits**: Beta features may have different rate limits3705. **Pricing**: Beta features may have different pricing structures371372**Best Practices:**373374```typescript375// Always handle beta-specific errors376try {377const result = await client.beta.messages.create({378model: "claude-3-5-sonnet-20241022",379max_tokens: 1024,380messages: [{ role: "user", content: "Beta test" }],381betas: ["new-feature-2024-12-01"],382});383} catch (error) {384if (error instanceof BetaError) {385console.log("Beta feature error:", error.message);386// Fallback to stable API387const fallback = await client.messages.create({388model: "claude-3-sonnet-20240229",389max_tokens: 1024,390messages: [{ role: "user", content: "Beta test" }],391});392}393}394395// Feature detection396const isFeatureAvailable = async (feature: string) => {397try {398await client.beta.models.list({ betas: [feature] });399return true;400} catch {401return false;402}403};404```405406## Available Beta Features407408Current beta features (availability may change):409410- **computer-use-2024-10-22**: Computer interface interaction411- **pdfs-2024-09-25**: Enhanced PDF document processing412- **token-counting-2024-11-01**: Advanced token counting413- **message-batches-2024-09-24**: Batch message processing414- **code-execution-2025-05-22**: Sandboxed code execution415- **citations-2024-11-15**: Citation tracking and references416417Check the official documentation for the most current list of available beta features and their capabilities.