# Rate Limiting Plugin

**URL:** <https://discuss.konghq.com/t/rate-limiting-plugin/69>\
**Category:** Questions\
**Created:** [November 28, 2017, 6:23pm UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69 "2017-11-28T18:23:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![CaesarKing](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/caesarking/32/36_2.png) [@CaesarKing](https://discuss.konghq.com/u/CaesarKing)\
**Post date:** [November 28, 2017, 6:23pm UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/1 "2017-11-28T18:23:18Z")

</div>

Rate limit how many HTTP requests a developer can make in a given period of seconds, minutes, hours, days, months or years. If the API has no authentication layer, the Client IP address will be used, otherwise the Consumer will be used if an authentication plugin has been configured. Give it a try and discuss it here!

[Rate Limiting plugin documentation](https://getkong.org/plugins/rate-limiting/)

---

<div class="post-metadata">

**Author:** ![Yuval](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuval](https://discuss.konghq.com/u/Yuval)\
**Post date:** [December 22, 2017, 9:56am UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/2 "2017-12-22T09:56:28Z")

</div>

Question: We would like to limit the number of messages per **week**  
Is it possible (simple)? Can you please indicate how it is done?  
Many thanks

---

<div class="post-metadata">

**Author:** ![Henry\_Cen](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@Henry\_Cen](https://discuss.konghq.com/u/Henry_Cen)\
**Post date:** [March 9, 2018, 2:57am UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/3 "2018-03-09T02:57:06Z")

</div>

I just set up rate limiting with “config.limit\_by=ip”, and tried to make API requests from different machines (with different IP address), but the counting includes the requests from different machines, and the X-RateLimit-Remaining-minute value drops for each request from different machines. So it seems to me it’s not really limiting by IP. Is anyone has similar test before, and how’s the outcome? Is my understanding correct?

---

<div class="post-metadata">

**Author:** ![thibaultcha](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/thibaultcha/32/340_2.png) [@thibaultcha](https://discuss.konghq.com/u/thibaultcha)\
**Post date:** [March 9, 2018, 6:46am UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/4 "2018-03-09T06:46:21Z")

</div>

Hi,

Could you maybe describe your setup furthermore so we can help you? There simply isn’t enough information in your message for us to draw any sort of conclusion.

Also, you may want to check this post:

> [@How to Forward Client's request IP](https://discuss.konghq.com/t/how-to-forward-clients-request-ip/384/2):
>
> Hi, This is a typical behavior/drawback of many reverse-proxies and load-balancers. Luckily for you, and as one would expect, there exist ways to circumvent them! Retrieving the client IP in your API First and foremost, Kong will set the [X-Forwarded-For](https://en.wikipedia.org/wiki/X-Forwarded-For) header for you since 0.11.0. You can use its value in your upstream services to retrieve the client IP. This is, I believe, the answer you are looking for. But let’s take a deeper dive here, because there are other important areas around this …

In particular, the following part:

> Beware, for existing plugins already access this value like so, such as the rate-limiting plugin. This means, if Kong/ngx\_http\_realip\_module is badly configured, this plugin will rate-limit based on a previous load-balancer’s IP address, instead of each individual client’s IP address, leading to a drastically different behavior than expected!

Your issue _could_ be related. Or it could be something else entirely but for us to figure it out, we’d need more information.

---

<div class="post-metadata">

**Author:** ![Henry\_Cen](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@Henry\_Cen](https://discuss.konghq.com/u/Henry_Cen)\
**Post date:** [March 15, 2018, 6:35am UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/5 "2018-03-15T06:35:57Z")

</div>

Thanks thibaultcha.  
Yep, it’s because of a proxy (in vagrant) before kong, that set X-Forwarded-For.

---

<div class="post-metadata">

**Author:** ![solosebi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/solosebi/32/444_2.png) [@solosebi](https://discuss.konghq.com/u/solosebi)\
**Post date:** [April 2, 2018, 3:11pm UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/6 "2018-04-02T15:11:10Z")

</div>

Hi,

Is there a way to get the limits for a consumer and the remaining number of requests allowed?  
Thank you.

---

<div class="post-metadata">

**Author:** ![gquad](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@gquad](https://discuss.konghq.com/u/gquad)\
**Post date:** [April 17, 2018, 11:49am UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/7 "2018-04-17T11:49:00Z")

</div>

Hi,

Special headers are sent to the upstream by the plugin with the limits.  
Check **Header Sent to the client** at [https://getkong.org/plugins/rate-limiting/](https://getkong.org/plugins/rate-limiting/)

---

<div class="post-metadata">

**Author:** ![bungle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/bungle/32/13_2.png) [@bungle](https://discuss.konghq.com/u/bungle)\
**Post date:** [April 19, 2018, 9:37pm UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/8 "2018-04-19T21:37:12Z")

</div>

@solosebi17d remaining changes as time goes on with rate limiting. If no requests it grows to max, if requests it goes to zero (if not grown faster). Limits for consumer can be specified by applying rate-limiting plugin to particular consumer.

---

<div class="post-metadata">

**Author:** ![Henry\_Cen](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@Henry\_Cen](https://discuss.konghq.com/u/Henry_Cen)\
**Post date:** [April 24, 2018, 7:46am UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/9 "2018-04-24T07:46:51Z")

</div>

Hi,

Could I know if we can eliminate X-RateLimit-Limit-\* and X-RateLimit-Remaining-\* headers responding to the clients?

And when setting up key-auth for different consumers, is there any way I can get the the key values from our DB (mysql)? With SQL statements? Or I need to write a script to automate it? Thanks!

---

<div class="post-metadata">

**Author:** ![Cooper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/cooper/32/9_2.png) [@Cooper](https://discuss.konghq.com/u/Cooper)\
**Post date:** [April 24, 2018, 6:15pm UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/10 "2018-04-24T18:15:07Z")

</div>

> Could I know if we can eliminate X-RateLimit-Limit-\* and X-RateLimit-Remaining-\* headers responding to the clients?

Yep - you’ll find that option in [the documentation](https://getkong.org/plugins/rate-limiting) - look at `config.hide_client_headers`

> And when setting up key-auth for different consumers, is there any way I can get the the key values from our DB (mysql)? With SQL statements? Or I need to write a script to automate it? Thanks!

Please open [a new discussion](https://discuss.konghq.com/c/questions) for that question, thanks!

---

<div class="post-metadata">

**Author:** ![Rishi\_Anand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/rishi_anand/32/970_2.png) [@Rishi\_Anand](https://discuss.konghq.com/u/Rishi_Anand)\
**Post date:** [February 4, 2019, 8:07pm UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/11 "2019-02-04T20:07:12Z")

</div>

Hi Henry,

As u asked the following query on the form:

**I just set up rate limiting with “config.limit\_by=ip”, and tried to make API requests from different machines (with different IP address), but the counting includes the requests from different machines, and the X-RateLimit-Remaining-minute value drops for each request from different machines. So it seems to me it’s not really limiting by IP.**

Would you be able to restrict the client IP (machine) to make API requests ?

---

<div class="post-metadata">

**Author:** ![Henry\_Cen](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@Henry\_Cen](https://discuss.konghq.com/u/Henry_Cen)\
**Post date:** [April 30, 2019, 8:02am UTC](https://discuss.konghq.com/t/rate-limiting-plugin/69/12 "2019-04-30T08:02:07Z")

</div>

Hi Rishi,

Just notice your message. Sorry for late reply.

Yes, the limit by IP address works for me. But I also got similar problem before which is due to the proxy between client and kong.
