If you encounter an error like "API key not valid. Please pass a valid API key." while chatting with the Gemini, please follow these steps:
- Go to Google AI Studio.
- Navigate to the API key section and create a new API key.
Your API key will look something like this: AIzaSyAtpnKGX13bTgmx0l_gQeatYvdWvY_wOTQ
Note: The API is free but has a limited number of usage requests.
- Open your project folder in VS Code.
- Locate to the
script.js
file in your project. - Find the
API_KEY
variable and replacePASTE-YOUR-API-KEY
with your actual API key.
- Save the
script.js
file after adding your API key. - Open
index.html
in your browser to verify that Gemini is working correctly.