XBag.AI.Quota.ClientModel 0.1.0-preview.1

This is a prerelease version of XBag.AI.Quota.ClientModel.
dotnet add package XBag.AI.Quota.ClientModel --version 0.1.0-preview.1
                    
NuGet\Install-Package XBag.AI.Quota.ClientModel -Version 0.1.0-preview.1
                    
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="XBag.AI.Quota.ClientModel" Version="0.1.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XBag.AI.Quota.ClientModel" Version="0.1.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="XBag.AI.Quota.ClientModel" />
                    
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 XBag.AI.Quota.ClientModel --version 0.1.0-preview.1
                    
#r "nuget: XBag.AI.Quota.ClientModel, 0.1.0-preview.1"
                    
#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 XBag.AI.Quota.ClientModel@0.1.0-preview.1
                    
#: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=XBag.AI.Quota.ClientModel&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=XBag.AI.Quota.ClientModel&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Tool

XBag.AI.Quota.ClientModel

CI NuGet .NET 8 | 10 License: MIT

Retry-After for XBag.AI.Quota with the OpenAI and Azure OpenAI SDKs. Those SDKs (and every Microsoft.Extensions.AI adapter on top of them) fail with System.ClientModel's ClientResultException, which carries the HTTP status and the raw response. The core package is provider-free and does not know that type, so without this classifier a 429 from the OpenAI SDK is not retried at all. ClientModelFailures.Classify reads the status and the provider's wait.

Part of the XBag family of .NET packages by Murat Ay, the author of XBag, a .NET process-orchestration and decisioning platform. Community package, not affiliated with Microsoft or OpenAI.

Pipeline slot: none of its own; it is the ClassifyError of UseQuotaLimiter (BELOW FunctionInvokingChatClient).

Install

It brings XBag.AI.Quota and System.ClientModel 1.15.0:

dotnet add package XBag.AI.Quota.ClientModel --prerelease

Example

From RetryTests.cs, run in CI: the provider answers 429 with Retry-After: 20, the call is repeated exactly 20 seconds later (fake time), buffered and streaming:

var model = new ScriptedChatClient()
    .Fail(Provider.RateLimited(retryAfterSeconds: 20))                  // new ClientResultException(message, rawResponse)
    .ReplyAt(clock, calledAt, "Kargonuz Ankara aktarma merkezinde.");

IChatClient client = model.AsBuilder()
    .UseFunctionInvocation()
    .UseQuotaLimiter(o => o.ClassifyError = ClientModelFailures.Classify, new QuotaLedger(clock))
    .Build();

Task<string> call = client.AskAsync("TR123 nerede?", Ask, streaming);
await clock.AdvanceWhenWaitingAsync(TimeSpan.FromSeconds(20));

Assert.Equal("Kargonuz Ankara aktarma merkezinde.", await call);
Assert.Equal([TimeSpan.FromSeconds(20)], calledAt);

API

Member What it is
ClientModelFailures.Classify(exception) For a ClientResultException: 429 → RateLimited; 408, 500, 502, 503, 504 and status 0 (no response: network) → Transient; any other status → NotRetryable; RetryAfter from retry-after-ms, x-ms-retry-after-ms or Retry-After of the raw response. Any other exception → null (the built-in classifier decides).

Set the SDK's own retries to zero (new OpenAIClientOptions { RetryPolicy = new ClientRetryPolicy(maxRetries: 0) }), otherwise the SDK has already waited and retried (honouring Retry-After itself) before this classifier ever sees the 429.

What this is not

  • Not Azure.Core. Azure SDKs built on Azure.Core fail with RequestFailedException; that classifier is on the roadmap.
  • Not a reader of OpenAI's x-ratelimit-* headers. Only the wait a 429 / 503 asks for is read.

If Microsoft ships a resilience middleware

See the core package's README. MEAI deliberately does not wrap provider exceptions (dotnet/extensions#6774), so a classifier per SDK error type stays useful even if a first-party retry layer appears.

Versions

Depends on XBag.AI.Quota and System.ClientModel 1.15.0 (the version the OpenAI 2.14.0 SDK depends on). Tested on .NET 8 and .NET 10. Status: 0.1.0-preview.1, the API may change before 1.0.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 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.0-preview.1 98 10/11/2026