Universal.GenerativeAI.Anthropic
1.2.0
dotnet add package Universal.GenerativeAI.Anthropic --version 1.2.0
NuGet\Install-Package Universal.GenerativeAI.Anthropic -Version 1.2.0
<PackageReference Include="Universal.GenerativeAI.Anthropic" Version="1.2.0" />
<PackageVersion Include="Universal.GenerativeAI.Anthropic" Version="1.2.0" />
<PackageReference Include="Universal.GenerativeAI.Anthropic" />
paket add Universal.GenerativeAI.Anthropic --version 1.2.0
#r "nuget: Universal.GenerativeAI.Anthropic, 1.2.0"
#:package Universal.GenerativeAI.Anthropic@1.2.0
#addin nuget:?package=Universal.GenerativeAI.Anthropic&version=1.2.0
#tool nuget:?package=Universal.GenerativeAI.Anthropic&version=1.2.0
Universal.GenerativeAI.Anthropic
Implementation of generative AI interfaces using Anthropic's Claude models for text generation and transformation.
Classes
AnthropicTextGenerator
Implements the IAsyncTextGenerator interface to generate text using Anthropic's Claude models. Automatically selects the best continuation strategy based on the model: prefilling on models that support it, prompt-based continuation on newer models (Claude 4.6+).
var anthropicClient = new AnthropicClient("api-key");
var generator = new AnthropicTextGenerator(anthropicClient);
string generatedText = await generator.GenerateAsync("Write a summary of the key features of quantum computing:");
// With custom options
var options = new AnthropicTextGenerator.Options
{
Model = Models.ClaudeOpus46,
BatchMaxTokens = 131072
};
var generator = new AnthropicTextGenerator(anthropicClient, options);
string generatedText = await generator.GenerateAsync("Write a detailed report:", cancellationToken);
AnthropicStructuredTextTransformer
Implements the IAsyncTextTransformer interface using Anthropic's structured output API to transform text into typed objects. The target type is automatically converted to a JSON schema and enforced server-side via OutputConfig. Requires Claude 4.5+ models.
var anthropicClient = new AnthropicClient("api-key");
var transformer = new AnthropicStructuredTextTransformer(anthropicClient);
// Define a class — use [Description] and [Required] attributes for richer schema hints
[Description("A product listing")]
public class Product
{
[Required, Description("The product name")]
public string Name { get; set; }
[Required, Description("A brief description of the product")]
public string Description { get; set; }
[Required, Description("The price in USD")]
public decimal Price { get; set; }
}
// No need for JSON formatting instructions — the schema handles it
Product product = await transformer.TransformAsync<Product>(
"Extract product details: Gaming laptop XPS-9000, high-performance gaming with RGB keyboard, priced at $1299.99",
cancellationToken
);
// For lists, wrap in a container type
[Description("A list of products")]
public class ProductList
{
[Required, Description("The extracted products")]
public List<Product> Products { get; set; }
}
ProductList products = await transformer.TransformAsync<ProductList>(
"Extract all products: XPS-9000 gaming laptop ($1299.99) with RGB keyboard, and UltraSlim X1 ultrabook ($899.50) with 4K touchscreen.",
cancellationToken
);
The AnthropicJsonSchemaConverter is used by default to convert .NET types to Anthropic-compatible schemas, automatically setting additionalProperties: false on all object schemas as required by the API. A custom IJsonSchemaConverter can be injected via options.
Features
- Structured Output: Schema-enforced JSON responses via
OutputConfigon Claude 4.5+ models - Automatic Strategy Selection: The generator uses prefilling on supported models and prompt-based continuation on Claude 4.6+
- Token Streaming: Automatically handles responses that exceed token limits by continuing in batches
- Model Selection: Configure different Claude models based on your needs
- Intelligent Type Detection: Automatically converts .NET types to JSON schemas with support for
[Description],[Required], and validation attributes - Configurable Token Limits: Adjust token limits to optimize for performance or cost (defaults tuned per model generation)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Universal.Anthropic.Client (>= 3.0.0.1)
- Universal.GenerativeAI (>= 1.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.
Added support for custom schema specification. Deprecated the AnthropicTextTransformer due to Anthropic dropping support for prefill.