It’s a best practice that API keys must never be stored inside code or with the software that is distributed.
So it makes sense to have a middleware that would safely store the API key and somehow allow the validated requests to be sent to the OpenAI API with the valid (and securely stored) API key.
Have you deployed your OpenAI based application to production? What was your approach?
How would one allow an end user to use one’s software without having access to the API key? From what I understand, an environment variable is local and not a very secure thing.