For example, how to implement a token bucket limiter that is increased limit if user pays for it?
The doc shows something very similar to what you have requested - you can return different partition keys and limiters for paid and unpaid users:
builder.Services.AddRateLimiter(opts => opts
.AddPolicy(policyName: "somePolicyName", partitioner: httpContext =>
{
var userName = httpContext.User.Identity?.Name ?? string.Empty;
// determine somehow if user is paid, for example set corresponding claim for token
// or any other method:
var isPaid = httpContext.User.HasClaim("paid", "true");
if (isPaid)
{
return RateLimitPartition.GetTokenBucketLimiter("Paid!:" + userName, _ =>
new TokenBucketRateLimiterOptions
{
// values for paid users
});
}
return RateLimitPartition.GetTokenBucketLimiter("Unpaid!:" + userName, _ =>
new TokenBucketRateLimiterOptions
{
// values for free users
});
}));