Using Flask and OpenAI APIs: correct strategy


I am developing an APP that uses GPT-3 and DALLE, which are called from a Flask API.
For all the business logic of the app and the frontend, I want to use Meteor’s infrastructure.

My question is, how would you manage the flow of the calls to the Flask API? Since plugging Python and Meteor is not the easiest, especially with auth and Mongo, I was thinking of two possible ways to handle this:

  1. React calls Meteor Method, meteor method verifies that user exists and is authorised and calls Flask API, and when the API returns a value, the method stores it.

  2. React calls Flask API directly, the API returns a value, and then the front calls Meteor Method to store that value.

Which approach would you use for a case like this?

Thanks a lot!


if you need authenticated calls to Flask API, safest would be to go server-side unless you have an authentication mecanism to log the user to your Python server (e.g. Python provides the oAuth service). Your user would still be a Meteor user but you authenticate to a 3rd party so you can get 3rd party data.
Server-side though makes UX a bit more complicated since you have to “tell” the user what is going on and is not so cool with a large number of users or data volumes.

If API security/privacy is not so important, definitely number 2 but in this case you can’t control the calling rate to your Flask API. If your limit is let’s say 10 calls per second, you can manage the queue when you do things server-side but on the client … you end up with a fail and eventually a try again.

1 Like

Thanks Paulishca! I think I’m gonna go with option 1), and giving the user a bunch of feedback on the process, since the calls won’t be super short anyways!