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
GitHub - JonathanAlphonso/ai-fight-pits
Contribute to JonathanAlphonso/ai-fight-pits development by creating an account on GitHub.
1 Reply
whatplan
whatplan11mo ago
Theo - t3․gg
YouTube
Ratelimiting Your APIs With Redis (The Theo-Proof Way)
The trolls almost ruined roundest.t3.gg - we stopped them 🙏 THANK YOU TO MY FIRST SPONSOR - UPSTASH https://upstash.com/?ref=theo Check out their Redis rate limiter package: https://github.com/upstash/ratelimit Original video for when I built Roundest https://www.youtube.com/watch?v=PKy2lYEnhgs Twitch link: https://twitch.tv/theo Twitter lin...