All Guides

Google Gemini API Setup

Set up Google Gemini (formerly Bard) API and use it in your projects.

Intermediate20 min

Setup Steps

1. Go to https://aistudio.google.com

2. Sign in with your Google account and create an API key

3. Install the Python SDK:

pip install google-generativeai

4. Set the API key as an environment variable:

export GOOGLE_API_KEY="AIza..."

5. Send your first request with Python:

python
import google.generativeai as genai
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
model = genai.GenerativeModel('gemini-2.0-flash')
response = model.generate_content("Hello!")
print(response.text)

6. For Node.js:

npm install @google/generative-ai

7. JavaScript example:

javascript
import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });
const result = await model.generateContent("Hello!");
console.log(result.response.text());