Universal.Operative.Sdk.Discrete.Anthropic
4.0.0
dotnet add package Universal.Operative.Sdk.Discrete.Anthropic --version 4.0.0
NuGet\Install-Package Universal.Operative.Sdk.Discrete.Anthropic -Version 4.0.0
<PackageReference Include="Universal.Operative.Sdk.Discrete.Anthropic" Version="4.0.0" />
<PackageVersion Include="Universal.Operative.Sdk.Discrete.Anthropic" Version="4.0.0" />
<PackageReference Include="Universal.Operative.Sdk.Discrete.Anthropic" />
paket add Universal.Operative.Sdk.Discrete.Anthropic --version 4.0.0
#r "nuget: Universal.Operative.Sdk.Discrete.Anthropic, 4.0.0"
#:package Universal.Operative.Sdk.Discrete.Anthropic@4.0.0
#addin nuget:?package=Universal.Operative.Sdk.Discrete.Anthropic&version=4.0.0
#tool nuget:?package=Universal.Operative.Sdk.Discrete.Anthropic&version=4.0.0
Universal.Operative.Sdk.Discrete.Anthropic
About
Universal.Operative.Sdk.Discrete.Anthropic plugs Anthropic's Messages API into Universal.Operative.Sdk via an IModel adapter (Model) backed by the Universal.Anthropic.Client transport, plus a small set of Anthropic-specific extensions (prompt caching, extended thinking, per-block cache_control) that don't belong in the provider-neutral core.
How to Use
Installation
Requires .NET 10 or .NET 11.
dotnet add package Universal.Operative.Sdk.Discrete.Anthropic
Configuration
using Universal.Operative.Sdk;
using Universal.Operative.Sdk.Discrete;
using Universal.Operative.Sdk.Discrete.Anthropic;
using Model model = new Model(apiKey, new Model.Options { ModelId = "claude-sonnet-4-6", MaxTokens = 4096, // required by Anthropic; defaults to 1024
Temperature = 1.0f, UsePromptCaching = true, // default: stamps ephemeral cache_control on system/tools automatically
});
Supply apiKey from your application's secret configuration. A model constructed with an API key owns its transport and must be disposed. The constructor also accepts an existing Universal.Anthropic.Client.V1.AnthropicClient so you can reuse a customized client across models; that client remains caller-owned, and disposing the model leaves it alive. StopSequences and Thinking are shared mutable configuration objects; changes to their contents affect subsequent requests.
Usage
Drop the model into EngineBuilder like any other IModel:
IEngine engine = EngineBuilder.FromDefaults(model).AddBaselineToolSet().Build();
ConversationManager manager = await ConversationManager.CreateAsync(conversation, cancellationToken: CancellationToken.None);
await foreach (EngineEvent e in engine.ExecuteAsync(new Universal.Operative.Sdk.Discrete.ExecutionContext(new TurnContext()), manager, CancellationToken.None))
{
// handle events as usual — see Universal.Operative.Sdk's Package.md
}
Extended thinking
Set Model.Options.Thinking to enable Claude's extended-thinking mode; thinking blocks round-trip through the same provider-neutral Block model as everything else.
Prompt caching
With UsePromptCaching (default true), the adapter adds ephemeral cache_control breakpoints to the final system block, tool definition and message block. Explicit block cache controls, including their TTLs, are preserved. Set UsePromptCaching = false for entirely manual breakpoint placement.
To control caching on individual content blocks yourself, use the Anthropic extension property added onto Block:
using Universal.Operative.Sdk.Discrete.Anthropic;
block.Anthropic.CacheControl = new CacheControl
{
Ttl = "1h"
};
Use AnthropicUsageExtensions.ProjectCompactionTokens as your compaction transformer's projected-token calculator to include cache creation and cache read tokens in context estimates.
Content and failures
Unsupported block or source kinds throw NotSupportedException. Images support JPEG, PNG, GIF and WebP. Unsupported inline media, oversized images and file IDs explicitly attributed to another provider become explanatory text placeholders. Inline documents are normalized against the shared document payload limits. If the serialized request exceeds the adapter's 30,000,000-byte safety limit, older inline images and documents are replaced with placeholders; oversized remaining text or tool payloads throw InvalidOperationException requiring compaction. This normalization leaves conversation history unchanged.
Cancellation stops streaming with OperationCanceledException. HTTP failures retain the native client's exception; streamed errors produce ErrorEvent and cause CompleteAsync to throw ModelStreamException with the partial message and provider error payload.
Refusals
When Anthropic ends a streamed turn with stop_reason: refusal, the provider category and explanation are retained on the settled message:
if (message.StopReason == StopReasons.Refusal)
{
string? category = message.Anthropic.RefusalCategory;
string? explanation = message.Anthropic.RefusalExplanation;
}
License
Free for noncommercial use under the Universal.Operative Noncommercial License. Source is closed; commercial use requires a separate license from Andrew Ong.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net11.0 is compatible. |
-
net10.0
- Universal.Anthropic.Client (>= 3.2.0)
- Universal.Common.Formats.Gif (>= 2.1.0)
- Universal.Common.Formats.Jpeg (>= 2.1.3)
- Universal.Common.Formats.Png (>= 2.2.0)
- Universal.Common.Formats.WebP (>= 2.0.0)
- Universal.Operative.Sdk.Discrete (>= 4.0.0)
-
net11.0
- Universal.Anthropic.Client (>= 3.2.0)
- Universal.Common.Formats.Gif (>= 2.1.0)
- Universal.Common.Formats.Jpeg (>= 2.1.3)
- Universal.Common.Formats.Png (>= 2.2.0)
- Universal.Common.Formats.WebP (>= 2.0.0)
- Universal.Operative.Sdk.Discrete (>= 4.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0 | 0 | 11/18/2026 |
| 3.2.1 | 65 | 11/16/2026 |
| 3.2.0 | 126 | 11/11/2026 |
| 3.1.0 | 96 | 11/11/2026 |
| 3.0.5 | 102 | 11/10/2026 |
| 3.0.4 | 104 | 11/10/2026 |
| 3.0.3 | 212 | 10/1/2026 |
| 3.0.2 | 112 | 10/1/2026 |
| 3.0.1 | 115 | 9/28/2026 |
| 3.0.0 | 168 | 9/7/2026 |
| 2.0.3 | 136 | 9/3/2026 |
| 2.0.2 | 134 | 9/3/2026 |
| 2.0.1 | 127 | 9/2/2026 |
| 2.0.0 | 135 | 9/1/2026 |
| 1.1.0 | 153 | 8/26/2026 |
| 1.0.1 | 149 | 8/24/2026 |
| 1.0.0 | 158 | 8/12/2026 |
Targets .NET 10 and .NET 11; removes .NET 8 support. Streaming honors cancellation during reads and preserves structured error details. Explicit cache TTLs are retained. Dispose models constructed with an API key to release their owned transport; supplied clients remain caller-owned.