Call the chat API using the Stream method

How should I use the Stream method for interaction? Should I directly call the OpenAI chat API from the frontend, or should I create a backend service (using JAVA) to interact with OpenAI and then have the frontend call the backend service?

If frontend = client-side code: no, you don’t directly call the API from there.

Don’t expose your API key.