Rate Limiting OpenAI Requests
Getting Started
Prerequisites
In order to run this locally, you will need python installed and an Upstash Redis database. If you don't have a database ready, you can learn how to do it here
Quickstart
- 
Clone the repo $ git clone https://github.com/upstash/examples.git $ cd examples/ratelimiting-python-openai
- 
Install the requirements $ pip install -r requirements.txt
- 
Create the environment variables $ export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY> $ export UPSTASH_REDIS_REST_URL=<YOUR_UPSTASH_REDIS_REST_URL> $ export UPSTASH_REDIS_REST_TOKEN=<YOUR_UPSTASH_REDIS_REST_TOKEN>
- 
Run the Flask server $ cd api $ flask --app server run
- 
Send requests repeatedly and test the rate limit $ curl http://127.0.0.1:5000/openai
Learn More
To learn more about Upstash and its services, check out the following resources: