Skip to content

How to Get a Free Gemini API Key (Step by Step)

Get a free Gemini API key in about two minutes, store it safely, test it with five lines of Python and fix the errors that stop new keys working.

Mahnoor 5 min read 4-item prompt pack

Google AI Studio Create API key button, free Gemini API key guide

A free Gemini API key lets your code talk to Google's Gemini models without paying anything. You get it from Google AI Studio in about two minutes with a normal Google account, and you don't need a credit card. This is the exact setup I use for every Morow Global project, plus the fixes for the errors that stop new keys from working.

What you need

  • A personal Google account. A school or work account sometimes can't create keys (more on that below).

  • Two minutes. No credit card and no billing setup.

  • It works in Pakistan and India: both are on Google's list of countries where the Gemini API is available.

Step 1: Open Google AI Studio

Go to aistudio.google.com and sign in with your Google account. Accept the terms when it asks. If you're a new user, AI Studio creates a default Google Cloud project for you, and often a first API key too. You don't have to touch Google Cloud at all.

Step 2: Create your API key

  1. Open the Dashboard in the left panel and go to API Keys.

  2. Click Create API key.

  3. Pick your project (the default one is fine) and create the key.

  4. Copy the key. Treat it like a password.

Since May 2026, every new key made in AI Studio is an auth key. It's tied to one project and only works with the Gemini API, which makes it much safer if it ever leaks.

Step 3: Store the key safely

Never paste your key straight into your code. Put it in a file called .env in your project folder:

GEMINI_API_KEY=paste-your-key-here

Then add .env to your .gitignore, so it never gets pushed to GitHub:

.env

Two more rules. Never put the key in frontend JavaScript, because anyone can open the browser tools and copy it. And never share it in a screenshot. Google scans for leaked keys and blocks them, and then your app stops working with the error "Your API key was reported as leaked".

Step 4: Test your key in Python

Install the official SDK and the package that reads your .env file:

pip install google-genai python-dotenv

Create test_key.py:

from dotenv import load_dotenv
from google import genai

load_dotenv()            # reads GEMINI_API_KEY from .env
client = genai.Client()  # finds the key by itself

response = client.models.generate_content(
    model="gemini-3.5-flash-lite",
    contents="Say hi in five words.",
)
print(response.text)

Run python test_key.py. If you see a short reply like "Hello there, how are you?", your key works. gemini-3.5-flash-lite is fast and works on the free tier, so it's a good model to start with.

Is the Gemini API really free?

Yes, there's a free tier, and it has limits: a number of requests per minute, tokens per minute and requests per day. Two things most guides don't tell you:

  • The limits are per project, not per key. Making five keys in the same project doesn't give you five times the limit.

  • The daily limit resets at midnight Pacific time, which is around noon to 1 PM in Pakistan.

You can see your exact limits on the rate limit page in AI Studio. For learning and side projects, the free tier is enough. If you go over a limit, you'll get a 429 error. Here's how to fix Gemini 429 and 503 errors.

Key not working? Common errors and fixes

  • "Verification needed" or 403 FREE_TIER_VERIFICATION_REQUIRED. Google wants to check that you're a real person before giving free access. Fix: verify with your phone in AI Studio.

  • "You do not have permission to create a key in this project". You're using a school or work account that doesn't allow it. Fix: use a personal Google account, or a new project that isn't part of an organization.

  • "Your API key was reported as leaked". The key was found in public (GitHub, a screenshot, a website). Fix: create a new key and delete the old one.

  • An old key suddenly stops working, or shows a Blocked tag. Since 2026, Google rejects unrestricted old-style keys and blocks keys that haven't been used for a long time. Fix: create a new key in AI Studio. New keys are auth keys, so this won't happen again.

  • "Free tier unavailable" on your project. That project isn't eligible for the free tier. A new key in the same project won't help. Fix: use a different project, or set up billing.

  • 429 RESOURCE_EXHAUSTED. You hit a rate limit. Fix: see the 429 and 503 fix guide.

One trap: listing models can work even when your project can't generate anything. So always test with a real generate_content call, like the script above.

What to build with your key

Now that your key works, build something real with it:

More Gemini projects are in the Build with AI topic.

Prompt pack

Every prompt from this lesson

2 free prompts + a first chatbot with memory and a 10-point key security checklist.

Explain my Gemini error
I'm using the Gemini API with the google-genai Python SDK. Here is my full error message and the code that caused it:

[paste the error]

[paste the code]

Explain in simple words what the error means, whether my key, my code or Google's servers caused it, and give me the exact fix. Don't change any code that isn't related to the error.
Set up my project safely
Create the setup files for a Python project that uses the Gemini API:

1. A .env.example with GEMINI_API_KEY=paste-your-key-here
2. A .gitignore that keeps .env, .venv and __pycache__ out of Git
3. A requirements.txt with google-genai and python-dotenv
4. A short README section that explains how a new developer adds their own key

Never include a real key anywhere.

2 more items in the full pack

Free. Sign in once and every prompt pack on Morow Global unlocks.

Sign in free to unlock

Already a member? Sign in

FAQ

Is the Gemini API key free?

Yes. Creating a key in Google AI Studio is free and doesn't need a card. The free tier has request limits per minute and per day, which are enough for learning and side projects.

Does the Gemini API work in Pakistan and India?

Yes. Both are on Google's list of available regions for the Gemini API.

Do I need a credit card for a Gemini API key?

No. You only need a card if you want the paid tier with higher limits.

Can I use one Gemini API key in many projects?

Yes, but every request counts against the same project's limits. Gemini limits are per project, not per key.

Can I put my Gemini API key in frontend JavaScript?

No. Anyone can copy it from the browser. Call Gemini from a backend or a serverless function that keeps the key secret.

#Gemini #API #Python