How to Get a Google AI API Key

Across the open issues on the google-gemini/gemini-cli repository and community threads on Stack Overflow, one setup question dominates all others: where to obtain a valid API key and which authentication path to choose. The answer splits cleanly into two tracks. Developers who want a zero-cost starting point use Google AI Studio to generate a key in under two minutes, no billing required. Teams operating inside Google Cloud infrastructure—or those with data-residency requirements—route through Vertex AI instead, a distinction documented in the official Gemini CLI authentication guide. The two paths share no quota pool: a key created in AI Studio draws from the Gemini Developer API free tier, while Vertex AI credentials draw from Google Cloud project quotas entirely separately. Getting the wrong key for the wrong track is the single most common activation failure pattern observed in community reports.

This guide follows the AI Studio path — the correct starting point for the vast majority of Gemini CLI users — and covers every decision point from project selection through key security and quota planning.

Prerequisites

Step-by-Step Guide

1

Visit Google AI Studio

Go to Google AI Studio (makersuite.google.com). The domain redirects to aistudio.google.com — both addresses reach the same interface. According to Google's official API key documentation, AI Studio is the canonical entry point for creating and managing Gemini Developer API keys.

Note: Google AI Studio is currently available in specific regions. If you cannot access it, check the available regions list or consider using a VPN. Teams in unsupported regions may need to evaluate the Vertex AI path instead.

2

Sign in with Google

Click "Sign in" and authenticate with your Google account. Accept the terms of service if prompted. Both personal Gmail accounts and Google Workspace accounts are supported for the free tier.

3

Navigate to API Keys

Once signed in, look for the "Get API key" button or navigate to the API keys section:

  • Click on your profile icon in the top right
  • Select "API keys" from the dropdown menu
  • Or look for a "Get API key" button on the main page
4

Create a New API Key

Click "Create API key" and choose your preferences:

  • Select "Create API key in new project" for a fresh start
  • Or choose an existing project if you have one
  • Give your API key a descriptive name (e.g., "Gemini CLI Key")

Project vs. key distinction: As noted in Google's key management docs, quota is attached to the project, not the individual key. Creating multiple keys inside the same project does not multiply your free-tier allocation — all keys share a single quota bucket. Separate projects are required to obtain independent quota pools.

5

Copy and Save Your API Key

Your API key will be displayed. Make sure to:

  • Copy the entire API key string
  • Save it in a secure location (password manager recommended)
  • Never share your API key publicly or commit it to version control

Important: This may be the only time you can view the full API key. If you lose it, you'll need to create a new one.

Once copied, export the key as an environment variable before running Gemini CLI:

# Set for the current shell session
export GEMINI_API_KEY="AIza..."

# Verify the CLI picks it up
gemini --version

API Key Limits and Quotas

The official rate limits documentation defines the free tier thresholds for the currently available stable models. As of early 2026, the Gemini Developer API free tier includes:

  • 10–15 requests per minute (varies by model; Gemini 2.5 Flash-Lite offers the highest RPM at 15)
  • 500–1,000 requests per day (daily counter resets at midnight Pacific Time)
  • 250,000 tokens per minute across all models in the project
  • 1 million token context window on supported models
  • Free to use for personal and commercial projects — no credit card required on the free tier

Quota upgrade path: When free-tier limits constrain production workloads, the Gemini API billing documentation describes a tiered upgrade process. Tier 1 (up to $250/month) activates by linking a billing account; Tier 2 ($2,000/month cap) requires a cumulative spend of $100 and an account age of at least 3 days. A tracked community issue (#1149 in the cookbook repo) documents a specific failure mode where linking a GCP billing account does not automatically upgrade Developer API quotas — the billing account must be linked through the AI Studio interface, not through the Google Cloud Console, to trigger the tier transition. Consulting the official pricing page before upgrading is recommended for current per-token costs.

AI Studio Key vs. Vertex AI: Choosing the Right Track

Of the two supported authentication paths for Gemini CLI — AI Studio API key and Vertex AI Application Default Credentials — the choice has significant downstream implications beyond initial setup complexity. The official authentication documentation identifies three Vertex AI-specific requirements that do not apply to AI Studio keys: an active Google Cloud project with the Vertex AI API enabled, the GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables set correctly, and either gcloud auth application-default login completed or a service account JSON key configured. A community-reported authentication bug documented in gemini-cli issue #15823 illustrates how a valid service account credential can still produce CREDENTIALS_MISSING errors when environment variables are set in the wrong order or scope.

FactorAI Studio KeyVertex AI (ADC)
Setup time~2 minutes10–30 minutes
Billing requiredNo (free tier)Yes (GCP project)
Data residency controlLimitedFull (region selection)
Recommended forIndividual / prototypingTeams / enterprise / CI-CD

For individual developers and prototype workloads, the AI Studio key path eliminates all Google Cloud IAM complexity while still providing access to the same underlying models. The Vertex AI path is warranted primarily when organizational policy mandates data-residency guarantees, when the workload is already inside a GCP project, or when Service Account access controls are required for audit compliance.

Security Best Practices

DO ✓

  • • Store API keys in environment variables
  • • Use a password manager
  • • Rotate keys regularly
  • • Use different keys for different projects
  • • Set up API key restrictions

DON'T ✗

  • • Commit keys to Git repositories
  • • Share keys in public forums
  • • Hardcode keys in your applications
  • • Use the same key everywhere
  • • Ignore suspicious activity

Common Issues

Google AI Studio not available in my region

Currently, Google AI Studio has limited availability. Check the available regions list or use a VPN to access from a supported region. Developers in consistently unsupported regions may find the Vertex AI authentication path — which operates through Google Cloud infrastructure — a more reliable alternative.

API key not working

Ensure the entire key string was copied, including any trailing characters. Check that the key has not been revoked in the AI Studio interface and that the project's daily request quota has not been exhausted — the per-day limit resets at midnight Pacific Time per the rate limits documentation. If errors persist after the reset window, regenerating the key in AI Studio resolves the majority of activation failures.

Billing linked but quota unchanged

A well-documented pattern — captured in cookbook issue #1149 — is that linking a GCP billing account through the Cloud Console does not always trigger a Developer API tier upgrade. The billing account must be associated through the AI Studio project settings to update the Gemini Developer API quota tier correctly.

Next Steps

Now that you have your API key, configure it with Gemini CLI:

Configure Your API Key →