How API rate limiting works, and 2 implementation examples in FastAPI

Опубликовано: 30 Сентябрь 2024
на канале: Pybites
2,272
51

"GPT-4 currently has a cap of 25 messages every 3 hours." - you must have seen this message, right?

In this video we talk about API rate limits, what is it and how to implement it in FastAPI.

First, we look at a plugin called fastapi-limiter which is a nice implementation using FastAPI's dependency injection system. We also look at how they've tested it as it.

Then we look at an example how we implemented in our CodeImag.es API which is more based on user consumption.

We hope these examples help you when you need to implement this. It might not be necessary from the start, but when you expect a lot of usage and calls to your API incur a cost, then this becomes pretty important!

Links:
- fastapi-limiter: https://github.com/long2ice/fastapi-l...
- its testing: https://github.com/long2ice/fastapi-l...
- our codeimag.es API: https://github.com/bbelderbos/codeima...
- and website: http://pybites-codeimages.herokuapp.com
- rate limiting by user consumption: https://github.com/bbelderbos/codeima...
- testing of it if interested: https://github.com/bbelderbos/codeima...
- pending fix, HTTP code fix: https://github.com/bbelderbos/codeima...

---
Learn more about Pybites / what we do: https://pybit.es

Get our weekly developer / mindset emails: https://pybit.es/friends/

Join our Slack community: https://pybit.es/community/

And last but not least, we appreciate any feedback to make our YouTube content better 💡
https://form.jotform.com/230941798741062 🙏