> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sliding Window Rate Limit Policy • AI Agent SDK

> SlidingWindowRateLimitPolicy: Config-driven sliding-window rate-limit policy.

# SlidingWindowRateLimitPolicy

> Defined in the [**protocols**](https://praison.ai/docs/sdk/reference/praisonaiagents/modules/protocols.md) module.

AI Agent

Config-driven sliding-window rate-limit policy.

The default referenced by `gateway.rate_limit` blocks in
`gateway.yaml` and the `WebSocketGateway(..., rate_limit_policy=...)`
Python surface. It is intentionally minimal and dependency-free so the
decision lives in core and is provable in isolation; heavy wrapper
limiters (`gateway/rate_limiter.py` sliding window,
`bots/_rate_limit.py` token bucket) may adopt this protocol while
keeping their own state and side effects.

The decision, keyed by `(scope, identity)`:

* `allowed` while fewer than `max_requests` have been seen in the
  current `window_seconds` window.
* Once the window count exceeds `max_requests`, the key enters a
  `lockout_seconds` cooldown and every :meth:`check` returns
  `allowed=False` with a `retry_after_seconds` hint until it elapses.

A `max_requests` of `0` disables limiting entirely (every request is
allowed) — the legacy default when no rate limit is configured.

This class is not internally synchronised; the wrapper owns any locking
it needs for concurrent hot paths (the built-in limiters already do).

State ownership: per-`(scope, identity)` window/lockout entries are
reclaimed lazily — a key's entry is dropped or overwritten the next time
that key is checked. It keeps one entry per *active* key and is intended
for a bounded identity space (endpoint classes, authenticated tenants). A
wrapper exposing it to an unbounded/untrusted identity space (e.g. raw
per-IP keys) owns periodic reclamation, exactly as it owns locking.

Example::

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
SlidingWindowRateLimitPolicy(max_requests=5, window_seconds=60,
                             lockout_seconds=300)
```

## Constructor

**max\_requests** `int` (default: 0)

No description available.

**window\_seconds** `float` (default: 60.0)

No description available.

**lockout\_seconds** `float` (default: 0.0)

No description available.

## Methods

> [card] [enabled()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/SlidingWindowRateLimitPolicy-enabled.md)
>
> Whether limiting is active (a positive ceiling is set).

> [card] [check()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/SlidingWindowRateLimitPolicy-check.md)
>
> Instance method.

## Source

> [card] [View on GitHub](https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L5075)
>
> `praisonaiagents/gateway/protocols.py` at line 5075


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.