How to Access and Use Google Gemini API Key (original) (raw)

Last Updated : 15 Apr, 2026

In today's world artificial intelligence (AI) is changing the way technology is used. The Google Gemini API is a widely used tool that can help create smart applications like chatbots, content generators and many more.

How to Get Your Google Gemini API Key

Step 1: Open Google AI Studio

google_ai_studio

Visit the home page

Step 2: Click on "Get API Key"

On the top-right corner, click on “Get API Key”.

google_ai_studio

Step 3: Click on "Create API Key"

create_api_key

Create API Key

Step 4: Select Google Cloud Project

Select an existing Google Cloud project or create a new one when prompted.

p

Choose a Project

Step 5: Generate and Copy API Key

f

Copy the API

Chatbot using Gemini API key

Let's build a simple chatbot using the Gemini API key integration,

Step 1: Install the Gemini Python SDK

We need to install the official Google Generative AI SDK which is needed to interact with Gemini Models.

Python `

!pip install google-generativeai

`

Step 2: Set up the API Key and Initialize Gemini

Here we need to mention our API Key.

import google.generativeai as genai

API_KEY = 'your_api_key_here' genai.configure(api_key=API_KEY)

`

Step 3: Create the Model Instance

model = genai.GenerativeModel('gemini-1.5-flash')

`

Step 4: Build the Chatbot

We build a basic chatbot using the gemini API,

def chat_with_bot(prompt): response = model.generate_content(prompt) return response.text.strip()

print("Welcome to Gemini Chatbot! Type 'exit' to quit.\n") while True: user = input("You: ") if user.strip().lower() == 'exit': print("Chatbot: Goodbye!") break bot = chat_with_bot(user) print("Chatbot:", bot)

`

**Output:

output

Output Generated by ChatBot