How to Get a Google Gemini API Key (Beginner's Guide)
Why Gemini?
Google's Gemini models are competitive with GPT-4 on many benchmarks and offer a generous free tier — perfect for learning, prototyping, and side projects.
Step 1: Go to Google AI Studio
Visit aistudio.google.com and sign in with your Google account. No credit card required for the free tier.
Step 2: Create an API Key
- Click "Get API Key" in the left sidebar
- Choose an existing Google Cloud project or create a new one
- Click "Create API Key"
- Copy the key — it starts with
AIza
Step 3: Test Your Key
Option A: Api Key Chain (Easiest)
Paste your key at apikeychain.app. The tool auto-detects it as Gemini and validates it instantly.
Option B: curl
curl "https://generativelanguage.googleapis.com/v1/models?key=YOUR_API_KEY"
If you get a JSON response with model names, your key works.
Understanding Gemini's Free Tier
| Feature | Free Tier Limit |
|---|---|
| Requests/min (Gemini 2.5 Flash) | 15 RPM |
| Requests/min (Gemini 2.5 Pro) | 2 RPM |
| Tokens/min | 1 million |
| Requests/day | 1,500 |
The free tier is rate-limited but not time-limited — it doesn't expire after a trial period.
Making Your First API Call
const API_KEY = 'YOUR_API_KEY';
const url = `https://generativelanguage.googleapis.com/v1/models/gemini-2.5-flash:generateContent?key=${API_KEY}`;
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
contents: [{ parts: [{ text: 'Hello, Gemini!' }] }]
})
});
const data = await response.json();
console.log(data.candidates[0].content.parts[0].text);
Security Tips
- Keep your key server-side — Gemini's query-param auth makes it easy to accidentally expose in URLs
- Set up API key restrictions in Google Cloud Console
- Never commit your key to git — use
.envfiles
When to Upgrade to Paid
The free tier works for:
- Learning and prototyping
- Low-traffic side projects
- Testing prompts before scaling
Switch to paid (pay-as-you-go) when you need higher rate limits or production reliability.
🔑 Gemini key format: Starts with AIza — one of the easiest to recognize. Api Key Chain auto-detects it among dozens of provider key formats.Related Posts
Get an Email When Your API Key Stops Working
API keys get revoked, expire or run out of credit without warning. Here is how to watch a key and get an email when it fails, and again when it works.
Check Your API Keys in CI With a GitHub Action
Fail the build when an API key in your secrets or .env file has stopped working. Use the open-source Api Key Chain CLI or GitHub Action.
How to Check If Your OpenAI API Key Is Still Valid
Learn how to quickly verify if your OpenAI API key is still active, what different error codes mean, and how to avoid common pitfalls.