Setting up
To use the API, we have to first get an API key that you can can from here: https://ai.google.dev/tutorials/setup

After that click on “Get an API key” button and then click on “Create API key in new project”.

Copy the API key and set it as an environment variable. We are using Deepnote and it is quite easy for us to set the key with the name “GEMINI_API_KEY”. Just go to the integration, scroll down and select environment variables.

In the next step, we will instal the Python API using PIP:
pip install -q -U google-generativeai
After that, we will set the API key to Google’s GenAI and initiate the instance.
import google.generativeai as genai import os gemini_api_key = os.environ[“GEMINI_API_KEY”] genai.configure(api_key = gemini_api_key)
How to Access and Use Gemini API for Free
— Was this helpful? · 👍 · 👎 —