Librería para integrar Claude API con inyección de dependencias en .NET compatible con .NET 9.0
License
—
Deps
6
Install Size
—
Vulns
✓ 0
Published
Oct 9, 2025
$ dotnet add package ClaudeIntegratorLibraryJCdiazLibrary for easily integrating the Claude API into .NET applications using Dependency Injection.
AddClaudeApiClient)appsettings.jsonAzure.IdentityTargetFramework)Install the package from NuGet:
dotnet add package ClaudeIntegratorLibraryJCdiaz
{
"ClaudeApi": {
"ApiKey": "sk-ant-api03-YOUR_API_KEY_HERE",
"BaseUrl": "https://api.anthropic.com/v1",
"Model": "claude-sonnet-4-20250514",
"MaxTokens": 2048,
"Temperature": 0.7,
"ApiVersion": "2023-06-01"
}
}
💡 Note: If using Azure Key Vault, leave
"ApiKey"empty.
POST https://api.anthropic.com/v1/messages
Headers
x-api-key: sk-ant-api03-xxxxx
anthropic-version: 2023-06-01
content-type: application/json
Body
{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"temperature": 1.0,
"messages": [
{
"role": "user",
"content": "Explain what LINQ is in C# in 2 sentences"
}
]
}
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-20250514",
"content": [
{
"type": "text",
"text": "LINQ (Language Integrated Query) is a C# feature that allows querying data collections using SQL-like syntax directly in code. It provides methods like Where, Select, OrderBy to filter, transform and sort data declaratively."
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 18,
"output_tokens": 62
}
}
appsettings.json){
"ClaudeApi": {
"ApiKey": "sk-ant-api03-YOUR_API_KEY_HERE",
"BaseUrl": "https://api.anthropic.com/v1",
"Model": "claude-sonnet-4-20250514",
"MaxTokens": 2048,
"Temperature": 0.7,
"ApiVersion": "2023-06-01"
}
}
📝 Use
"ApiKey": ""if you’re using Azure Key Vault. In that case, the secret must be named: ClaudeApi--ApiKey
using ClaudeIntegratorLibraryJCdiaz.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Register Claude API client dependency injection
builder.Services.AddClaudeApiClient(builder.Configuration);
var app = builder.Build();
app.MapGet("/", async (ClaudeApiClient claude) =>
{
var response = await claude.SendMessageAsync("Explain what LINQ is in C# in 2 sentences");
return response;
});
app.Run();
using Azure.Identity;
using ClaudeIntegratorLibraryJCdiaz.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using System;
var builder = WebApplication.CreateBuilder(args);
// Add Key Vault to configuration
// The secret must be named ClaudeApi--ApiKey
builder.Configuration.AddAzureKeyVault(
new Uri("https://YOUR_VAULT.vault.azure.net/"),
new DefaultAzureCredential()
);
// Configuration now includes secrets from Key Vault
builder.Services.AddClaudeApiClient(builder.Configuration);
var app = builder.Build();
app.MapGet("/", async (ClaudeIntegratorLibraryJCdiaz.Services.ClaudeApiClient claude) =>
{
var response = await claude.SendMessageAsync("Explain what LINQ is in C# in 2 sentences");
return response;
});
app.Run();
🔑 When using Azure Key Vault, the secret must be named:
ClaudeApi--ApiKey
(double hyphen to represent section nesting)
🗝️ The library automatically maps Key Vault secrets using:
Section--Key → Section:Key
🧑💻 Ensure your Azure user or app has at least the role: Key Vault Secrets User