Skip to content

Save APIKey #209

Answered by ztjhz
ai-samira asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, you can do that by creating a .env file in the root directory. Then, you set the VITE_OPENAI_API_KEY (see .env.example for more details). Then rebuild the app and your local server will be preloaded with the API key. However, do note that by doing so, your API key will be exposed to anyone who uses your website. This would not be an issue if it is hosted on your private server.

An alternate solution would be to host a proxy server where the API key is set in that server. Then, you can set the VITE_CUSTOM_API_ENDPOINT and VITE_DEFAULT_API_ENDPOINT to that proxy server. In this way, your API is not exposed to the users using your website. You can learn how to set up your own proxy server

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ai-samira
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants