How do I set API KEY environment for the repo

I am participating in the Hackathon. I clone the repo GitHub - google-gemini/generative-ai-js: The official Node.js / Typescript library for the Google Gemini API

I got my API Key and save it in a .env file in the samples directory. But when I run the command to test I got the error [400 Bad Request] API key not valid. Please pass a valid API key.. Do I need to perform any other action to use the API Key I generated from the AI studio?

You may wish to verify that the correct environment variable is exposed in the file and that it is available inside the node environment when you run it. Not all versions of node support .env directly and require additional libraries to be installed.

1 Like