# MentorRateLimiter class

> The MentorRateLimiter class of Novior.MentorAgent.Core: Rate limiter for user messages — in-memory, per session. Algorithm: sliding window counter. Each…

- URL: https://docs.mentoragent.net/api/novior-mentoragent-core/mentorratelimiter
- Verified with: MentorAgent 1.2.0
- Last updated: 2026-10-27
- Packages: Novior.MentorAgent

Rate limiter for user messages — in-memory, per session. Algorithm: sliding window counter. Each userId has a counter and the window start timestamp. When the window expires, the counter resets. Registered as Singleton — shares state across all users. Thread-safe via lock. Disabled if RateLimitPerUser = 0.

## Definition

Namespace: `Novior.MentorAgent.Core`. Package: `Novior.MentorAgent`.

`public sealed class MentorRateLimiter`

```shell
dotnet add package Novior.MentorAgent
```

## Constructors

`public MentorRateLimiter(IOptions<MentorOptions> options)`

## Methods

### `CheckAndIncrement`

`public ValueTuple<bool, int> CheckAndIncrement(string userId)`

Checks whether the user is allowed to send a message. Increments the counter if allowed.

**Returns:** (allowed: true, remaining: N) if allowed, (allowed: false, remaining: 0) if limit reached.

### `GetSecondsUntilReset`

`public int GetSecondsUntilReset(string userId)`

Returns the seconds remaining before the window resets for the given user.

---

- Previous: [MentorMetrics class](https://docs.mentoragent.net/api/novior-mentoragent-core/mentormetrics.md)
- Next: [MentorStructuredService class](https://docs.mentoragent.net/api/novior-mentoragent-core/mentorstructuredservice.md)
