best way to do rate limiting for API Calls?

I have a web app that calls gpt's API to create a fun little fight story between 2 characters.

Code and demo site are detailed at:

https://github.com/JonathanAlphonso/ai-fight-pits

Api call in question is at
Ai-fight-pits/src/server/api/routerd/gpt.ts

My fear is that people will spam requests are rack up my gpt api bill.

I like the idea of not needing to log in to generate a fight, so maybe limiting people by IP would be good?

Theo's t3 tut limits people by used ID in upstash but I don't think that's a good fit if I don't want to require logins.

Any tips???
GitHub
Contribute to JonathanAlphonso/ai-fight-pits development by creating an account on GitHub.
GitHub - JonathanAlphonso/ai-fight-pits
Was this page helpful?