If you encounter an error like "API key not valid. Please pass a valid API key." while chatting with the chatbot, 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.jsfile in your project. - Find the
API_KEYvariable and replacePASTE-YOUR-API-KEYwith your actual API key.
- Save the
script.jsfile after adding your API key. - Open
index.htmlin your browser to verify that Chatbot is working correctly.
If you still get an error or get stuck, feel free to message me on Buy Me a Coffee. https://buymeacoffee.com/codingnepal
Happy coding!