Bitzsoft.Integrations.AI.Anthropic
1.0.0-alpha.10
dotnet add package Bitzsoft.Integrations.AI.Anthropic --version 1.0.0-alpha.10
NuGet\Install-Package Bitzsoft.Integrations.AI.Anthropic -Version 1.0.0-alpha.10
<PackageReference Include="Bitzsoft.Integrations.AI.Anthropic" Version="1.0.0-alpha.10" />
<PackageVersion Include="Bitzsoft.Integrations.AI.Anthropic" Version="1.0.0-alpha.10" />
<PackageReference Include="Bitzsoft.Integrations.AI.Anthropic" />
paket add Bitzsoft.Integrations.AI.Anthropic --version 1.0.0-alpha.10
#r "nuget: Bitzsoft.Integrations.AI.Anthropic, 1.0.0-alpha.10"
#:package Bitzsoft.Integrations.AI.Anthropic@1.0.0-alpha.10
#addin nuget:?package=Bitzsoft.Integrations.AI.Anthropic&version=1.0.0-alpha.10&prerelease
#tool nuget:?package=Bitzsoft.Integrations.AI.Anthropic&version=1.0.0-alpha.10&prerelease
Bitzsoft.Integrations.AI.Anthropic
Anthropic Claude 原生 Messages 协议 Adapter。该包把 Anthropic 官方 C# SDK 暴露为
Microsoft.Extensions.AI.IChatClient,避免生产系统依赖功能受限的 OpenAI
兼容层。
安装与兼容性
dotnet add package Bitzsoft.Integrations.AI
dotnet add package Bitzsoft.Integrations.AI.Anthropic
- 目标框架:
net8.0;net10.0; - 使用 Anthropic 官方 C# SDK;
- API Key 由
Bitzsoft.Integrations.Core的凭据解析器按租户解析; - 不在 Options、配置模型、日志或持久化记录中保存 API Key。
注册
// 注册 Claude 原生 Messages 协议 Adapter。
services.AddBitzAnthropicAI();
// 命名客户端便于与其他 Provider 并存。
services.AddBitzChatClient("claude", options =>
{
options.ProviderId = "anthropic";
options.ProfileId = "anthropic";
options.ModelId = "approved-claude-model";
});
运行前为当前租户准备 AI:anthropic 凭据:
// 仅开发和测试:生产环境必须替换为 Vault/KMS 解析器。
services.AddInMemoryIntegrationCredentials(); // 仅开发和测试
// 凭据字段与其他 AI Provider 使用相同契约。
using var credential = new IntegrationCredential(
[
new(AICredentialFieldNames.ApiKey, secretFromSecureSource)
]);
credentialStore.Set(
new IntegrationCredentialKey("tenant-a", "AI:anthropic"),
credential);
生产环境应实现 IIntegrationCredentialResolver 并连接 Vault/KMS,不得使用进程内
Store 保存长期生产密钥。
使用
// 每次业务调用必须设置租户上下文。
using (contextAccessor.Push(new IntegrationContext("tenant-a")))
{
// Key 与 AddBitzChatClient 的注册名完全一致。
var client = serviceProvider.GetRequiredKeyedService<IChatClient>("claude");
var response = await client.GetResponseAsync("你好");
}
模型名称、工具调用、结构化输出、视觉和推理能力取决于所选 Claude 模型及 Anthropic 账户权限。上线前必须用真实账户执行模型契约测试。
该 Adapter 只实现 Claude Messages 聊天协议,不声明 Embeddings 能力。RAG 场景应并行
注册 OpenAI、智谱、通义或自定义 IEmbeddingGenerator;聊天与向量 Provider 可以使用
不同的 ProviderId、凭据和地域。
完整最小示例
using Bitzsoft.Integrations.AI;
using Bitzsoft.Integrations.Core;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
// 开发测试凭据 Store;生产环境不要注册它。
services.AddInMemoryIntegrationCredentials();
services.AddBitzAnthropicAI();
services.AddBitzChatClient("claude", options =>
{
options.ProviderId = "anthropic-dev";
options.ProfileId = "anthropic";
options.ModelId = "<已批准的 Claude 模型>";
options.EnableRequestAudit = true;
});
await using var provider = services.BuildServiceProvider(
new ServiceProviderOptions { ValidateScopes = true });
// 为 tenant-a 写入与 ProviderId 对应的 AI:anthropic-dev 凭据。
var store = provider.GetRequiredService<InMemoryIntegrationCredentialStore>();
using (var credential = new IntegrationCredential(
[
new(AICredentialFieldNames.ApiKey, "<从 User Secrets 读取的 API Key>")
]))
{
store.Set(
new IntegrationCredentialKey(
tenantId: "tenant-a",
providerKey: "AI:anthropic-dev",
environment: IntegrationEnvironments.Development),
credential);
}
using var scope = provider.CreateScope();
var contextAccessor = scope.ServiceProvider.GetRequiredService<
IIntegrationContextAccessor>();
using (contextAccessor.Push(new IntegrationContext(
tenantId: "tenant-a",
environment: IntegrationEnvironments.Development)))
{
// 底层原生客户端在本次调用完成后由上下文化包装器释放。
var client = scope.ServiceProvider
.GetRequiredKeyedService<IChatClient>("claude");
var response = await client.GetResponseAsync(
[
new(ChatRole.System, "只回答已授权范围内的问题。"),
new(ChatRole.User, "总结本周客户反馈。")
]);
Console.WriteLine(response.Text);
}
生产检查:
- 用目标账户验证模型名、流式、工具、视觉、推理和错误映射;
- 对不同地域、数据驻留要求和成本中心使用独立命名客户端与凭据;
- 不把 Anthropic 私有能力误标为所有 Provider 都支持的可移植能力;
- Prompt、工具参数和响应遵循与其他 AI Provider 相同的数据治理策略。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Anthropic (>= 12.39.0)
- Bitzsoft.Integrations.AI (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.AI.Abstractions (>= 1.0.0-alpha.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
-
net8.0
- Anthropic (>= 12.39.0)
- Bitzsoft.Integrations.AI (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.AI.Abstractions (>= 1.0.0-alpha.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.AI.Anthropic:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.All
Bitzsoft 第三方集成聚合包 — net5.0 包含传统连接器,net8.0+ 额外包含受上游 TFM 限制的 AI 模块 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.10 | 36 | 7/26/2026 |