SyntaxCircus.AI.Providers 0.1.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package SyntaxCircus.AI.Providers --version 0.1.4
                    
NuGet\Install-Package SyntaxCircus.AI.Providers -Version 0.1.4
                    
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="SyntaxCircus.AI.Providers" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyntaxCircus.AI.Providers" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="SyntaxCircus.AI.Providers" />
                    
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 SyntaxCircus.AI.Providers --version 0.1.4
                    
#r "nuget: SyntaxCircus.AI.Providers, 0.1.4"
                    
#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 SyntaxCircus.AI.Providers@0.1.4
                    
#: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=SyntaxCircus.AI.Providers&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=SyntaxCircus.AI.Providers&version=0.1.4
                    
Install as a Cake Tool

SyntaxCircus.AI.Providers

Build NuGet License: MIT

Low-level typed HTTP clients for the Anthropic Messages API and the Gemini generateContent API: request/response DTOs, rate-limit handling, and Retry-After parsing. Not a unified provider abstraction — a broad IAiProvider-style interface covering many vendors and modes (API, CLI, etc.) and a narrow structured-classification interface solve genuinely different problems, and forcing them into one shared abstraction serves neither well. This package is just the HTTP plumbing both kinds of consumer otherwise reimplement identically.

No support guaranteed. Published as-is and maintained on a best-effort basis. Issues and PRs are welcome, but there's no SLA — fork it or vendor what you need if that's not enough.

📖 Documentation

Start here:

By topic:

Setup

builder.Services.AddAiProviders(builder.Configuration); // binds "Anthropic" and "Gemini", registers both typed clients
{
  "Anthropic": { "ApiKey": "sk-ant-...", "Model": "claude-sonnet-5", "MaxTokens": 4096 },
  "Gemini": { "ApiKey": "...", "Model": "gemini-2.5-flash", "MaxOutputTokens": 4096 }
}

See Getting Started for detailed setup instructions.

Usage

AiCompletionResult result = await anthropicClient.SendAsync(
    prompt: "Summarize this in one sentence.",
    systemPrompt: "You are a terse assistant.",
    conversationHistory: previousTurns);

if (!result.Success)
{
    if (result.IsRateLimited)
    {
        // back off until result.RetryAfter (see Performance guide)
    }
    // result.Error contains error message
}

// result.Content contains the response text

Both AnthropicClient and GeminiClient accept the same responseJsonSchema pattern for structured output. See API Reference for complete method documentation, or Examples for real-world usage patterns.

Runtime API keys

The standard overload obtains its key from the configured Anthropic:ApiKey or Gemini:ApiKey option. Applications that securely retrieve a user-specific key at runtime (for example, from an OS credential store) can use the overload that takes apiKeyOverride instead. The override is used only for that request; it is never written to configuration or logged by this package.

string? apiKey = await credentialStore.GetAsync("MyApp", "Gemini", cancellationToken);
if (string.IsNullOrWhiteSpace(apiKey))
{
    return;
}

AiCompletionResult result = await geminiClient.SendAsync(
    prompt: "Summarize this crawl report.",
    apiKeyOverride: apiKey,
    ct: cancellationToken);

Use the normal configured-key overload for service-owned credentials. Use the runtime-key overload for per-user credentials; do not copy those secrets into appsettings.json merely to call a client.

Structured Output / Schema-Constrained Responses

Both clients support schema-constrained responses for structured classification and extraction:

var schema = """
{
  "type": "object",
  "properties": {
    "sentiment": { "type": "string", "enum": ["positive", "negative", "neutral"] },
    "confidence": { "type": "number" }
  },
  "required": ["sentiment", "confidence"]
}
""";

AiCompletionResult result = await anthropicClient.SendAsync(
    prompt: "Analyze this review: 'Amazing product, highly recommend!'",
    responseJsonSchema: schema);

if (!result.Success)
{
    // result.Error contains provider error, timeout, or schema/tool-use issues
}

// result.Content is guaranteed to be valid JSON conforming to the schema
var response = JsonSerializer.Deserialize<SentimentAnalysis>(result.Content);

Anthropic uses tool use under the hood to force a structured JSON response. Gemini uses its native JSON schema response mode.

A note on the API key

GeminiClient sends both configured and runtime override keys via the x-goog-api-key header, not the ?key= query-string parameter some sample code uses. A key in the URL ends up in server logs, proxy logs, and the Referer header of any request the response triggers — a real leak vector for something meant to stay secret. AnthropicClient sends its configured or runtime override key through x-api-key, which was never at risk of this since Anthropic's API never supported a query-string key.

Contributing

Issues and pull requests are welcome. See Contributing Guide for detailed guidelines on:

  • Code style and conventions
  • Adding new providers
  • Testing requirements
  • Documentation standards
  • Pull request process

Quick summary:

  • Keep changes focused, with a clear description of the behavior change.
  • Match the existing code style (see .editorconfig).
  • Add tests for new features.
  • Call out any breaking changes to the public API in your PR description.

License

MIT — see LICENSE.txt.

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. 
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
0.1.7 111 9/6/2026
0.1.6 96 9/3/2026
0.1.5 87 9/3/2026
0.1.4 110 8/18/2026
0.1.3 107 8/18/2026
0.1.2 110 8/16/2026
0.1.1 105 8/16/2026
0.1.0 100 8/16/2026