Step-by-step
- 1
Open Google AI Studio
Go to aistudio.google.com/apikey and sign in with your Google account.
- 2
Create API key
Click "Create API key" → choose a Google Cloud project (or create one) → copy the key.
- 3
Save in .env
In your project folder: `GOOGLE_API_KEY=your_key_here` inside a `.env` file.
- 4
Install SDK & test
`pip install google-generativeai python-dotenv` then run a one-line generate call to confirm it works.
Free tier (Google AI Studio)
- •Create a key at no cost — no credit card required for the free tier
- •Gemini 2.0 Flash: fast, cheap, great for learning and prototyping
- •Generous rate limits for personal study and small demos
- •Multimodal: text, images, and more in one API
Paid (when you outgrow free)
- •Enable billing in Google Cloud / AI Studio for higher limits
- •Pay per token — Flash models stay very affordable at scale
- •Vertex AI for enterprise: VPC, compliance, SLAs
Environment variable
GOOGLE_API_KEYQuick test (Python)
1import os2from dotenv import load_dotenv3import google.generativeai as genai4
5load_dotenv()6genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))7model = genai.GenerativeModel("gemini-2.0-flash")8print(model.generate_content("Say hello in one sentence.").text)