@anthropic-ai/foundry-sdk

中文文档
1.1.1发布于 2026/11/03Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 68.4万

The official TypeScript library for the Anthropic Foundry API

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Basic Usage with API Key
  4. Using Azure AD Token Provider
  5. Using Model Deployments

Claude SDK for Microsoft Foundry

NPM version

This library provides convenient access to the Claude API via Microsoft Azure AI Foundry. See the documentation for more details.

For the direct Claude API at api.anthropic.com, see @anthropic-ai/sdk.

Installation

npm install @anthropic-ai/foundry-sdk

Usage

Basic Usage with API Key

import { AnthropicFoundry } from '@anthropic-ai/foundry-sdk';

const client = new AnthropicFoundry({
  apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY, // defaults to process.env.ANTHROPIC_FOUNDRY_API_KEY
  resource: 'example-resource.azure.anthropic.com', // your Azure resource
});

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

console.log(message.content);

Using Azure AD Token Provider

For enhanced security, you can use Azure AD (Microsoft Entra) authentication instead of an API key:

import { AnthropicFoundry } from '@anthropic-ai/foundry-sdk';
import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';

const credential = new DefaultAzureCredential();
const scope = 'https://ai.azure.com/.default';
const azureADTokenProvider = getBearerTokenProvider(credential, scope);

const client = new AnthropicFoundry({
  azureADTokenProvider,
  resource: 'example-resource.azure.anthropic.com', // your Azure resource
});

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

console.log(message.content);

Using Model Deployments

If you have a model deployment configured, you can specify it to have the SDK automatically construct the correct URL path:

const client = new AnthropicFoundry({
  apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY,
  resource: 'example-resource.azure.anthropic.com',
});

// The SDK will automatically use /deployments/my-claude-deployment/messages
const message = await client.messages.create({
  model: 'claude-sonnet-5-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello!' }],
});

版本与发布记录

@anthropic-ai/foundry-sdk 共发布 25 个版本,首次发布于 2025/11/18;过去 12 个月发布了 25 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.1latest2026/11/033 天前
1.1.02026/10/2313 天前
1.0.02026/10/2115 天前
0.6.02026/10/1522 天前
0.5.42026/10/0829 天前
0.5.32026/10/0829 天前

关于 @anthropic-ai/foundry-sdk 的常见问题

@anthropic-ai/foundry-sdk 是什么?

The official TypeScript library for the Anthropic Foundry API

如何安装 @anthropic-ai/foundry-sdk?

在项目目录运行 npm install @anthropic-ai/foundry-sdk,或使用 pnpm add / yarn add / bun add。

@anthropic-ai/foundry-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anthropic-ai/foundry-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@anthropic-ai/foundry-sdk 可以商用吗?

@anthropic-ai/foundry-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@anthropic-ai/foundry-sdk 的下载量有多少?

根据 npm 官方下载统计,@anthropic-ai/foundry-sdk 在 2026/10/06 – 2026/11/04 这 30 天内被下载 684,397 次,日均约 22,813 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anthropic-ai/foundry-sdk 还在维护吗?

最新版本 1.1.1 发布于 2026/11/03(3 天前);至今共发布 25 个版本,其中过去 12 个月发布了 25 个;首次发布于 2025/11/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。