# Rate limiting

Rate limiting is useful for protecting your API from abuse, preventing excessive traffic, and ensuring fair usage.

## Basic Usage

Apply rate limiting using the `rate_limit` middleware:

```python
from slush.core.throttle import rate_limit

@app.route("/hello", methods=["GET"], middlewares=[rate_limit(5, 60)])
def hello(request):
    return {"message": "Hello from Slush"}
```

## How It Works

* The first argument (`5`) is the maximum number of requests allowed
* The second argument (`60`) is the time window in seconds

In the example above, each client can make up to **5 requests per 60 seconds**.

## Limit Exceeded

If the limit is exceeded, Slush returns:

* Status code: `429 Too Many Requests`
* A JSON error response

## Summary

Rate limiting in Slush allows you to:

* Restrict request frequency per client
* Protect endpoints from abuse
* Apply limits easily using middleware


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://slush.gitbook.io/docs/documentation/basics/rate-limiting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
