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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Universal.Operative.Sdk.Discrete.Anthropic" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Universal.Operative.Sdk.Discrete.Anthropic" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Universal.Operative.Sdk.Discrete.Anthropic" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Universal.Operative.Sdk.Discrete.Anthropic --version 4.0.0
                    
#r "nuget: Universal.Operative.Sdk.Discrete.Anthropic, 4.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Universal.Operative.Sdk.Discrete.Anthropic@4.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Universal.Operative.Sdk.Discrete.Anthropic&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Universal.Operative.Sdk.Discrete.Anthropic&version=4.0.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.