Developer Tutorials & API Setup·6 min read·
Last Updated: October 23, 2026 (Verified for Accuracy)

How to Get a Free Gemini API Key: Step-by-Step Setup & Code (2026)

The 60-Second Setup:

Go to Google AI Studio (aistudio.google.com) → sign in with your standard Google Account → click "Get API key" in the left sidebar → select "Create API key in new project". Copy your 39-character key. No credit card or billing details required. Free tier provides 15 RPM and 1,500 requests/day on Gemini 1.5 Flash.

Why Google AI Studio Offers the Best Free LLM API

While OpenAI and Anthropic require pre-purchased credits or credit card authorization before issuing API keys, Google provides one of the most generous free tiers in the industry via Google AI Studio.

With a free API key, developers can build prototypes, test autonomous agents, analyze PDFs, and write code against models featuring up to a 2-million-token context window without paying a single cent.

Official Free Tier Quota & Rate Limits (2026)

According to published Google AI Developer pricing documentation, free tier keys operate under these strict rate limits:

Model NameRequests Per Minute (RPM)Tokens Per Minute (TPM)Requests Per Day (RPD)
Gemini 1.5 Flash (Workhorse)15 RPM1,000,000 TPM1,500 RPD (Free)
Gemini 1.5 Pro (Deep Reasoning)2 RPM32,000 TPM50 RPD (Free)

Important Privacy Notice on Free Tier

On the Free Tier, Google terms state that conversations and uploaded media may be reviewed by human annotators and used to train Google models. If you are developing proprietary internal enterprise software, attach a Google Cloud Billing account to switch to the commercial tier where zero data logging is enforced.

Step-by-Step Instructions to Generate Your Key

1Navigate to Google AI Studio

Open aistudio.google.com in your web browser. Accept the Terms of Service using your personal or Google Workspace account.

2Create Your Secret Key

In the left-hand navigation panel, click "Get API key". Click the blue button labeled "Create API key". Choose "Create API key in new project" or select an existing Google Cloud project.

3Store Securely in Environment Variables

Never commit raw API keys into public GitHub repositories. Save the key in your local .env.local file or export it in your shell:

# Linux / macOS (Terminal) export GEMINI_API_KEY="AIzaSyYourSecretKeyHere" # Windows PowerShell $env:GEMINI_API_KEY="AIzaSyYourSecretKeyHere"

Working Python SDK Example

Install the official Google GenAI Python library:

pip install google-genai

Execute this complete script to test your free API key:

from google import genai
import os

# Initialize client with your environment key
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))

# Run a test generation on Gemini 1.5 Flash (Free Tier)
response = client.models.generate_content(
    model="gemini-1.5-flash",
    contents="Explain why type safety matters in software engineering in 3 bullet points."
)

print(response.text)

Troubleshooting Common Gemini API Errors

  • 429 Resource Exhausted: You exceeded the 15 RPM burst threshold. Add exponential backoff sleep (e.g. time.sleep(4)) between batch requests.
  • 400 API_KEY_INVALID: Ensure no accidental spaces were copied. Re-verify the key in Google AI Studio dashboard.
  • Region Not Supported: If connecting from a country where AI Studio is geo-restricted, ensure your Google Cloud account region is configured for supported territories (US, Europe, India, Japan, etc.).

Primary Grounding & Official References

Related Technical Guides