← Blog

How to Get an AI API Key for Gemini: Step by Step

2026-09-06 · 5 min read · SubToAPI Team

Getting a Gemini API key is one of the fastest ways to start building with Google's AI models, and it takes less than five minutes if you go through the right path. The short answer: go to Google AI Studio, sign in with a Google account, click "Get API key," and copy the key it generates. There's no separate approval process for the free tier, and you can start making requests immediately.

The longer answer depends on whether you want the quick developer path (Google AI Studio) or the enterprise path (Vertex AI on Google Cloud), because they use different consoles, different billing models, and different key formats. This guide covers both, plus what to do with the key once you have it.

Google AI Studio vs Vertex AI

Google actually offers two ways to get a Gemini API key, and picking the wrong one wastes time.

Google AI Studio is the fast path. It's meant for prototyping and small-to-medium production use. You sign in with a personal or Workspace Google account, generate a key, and you're calling the Gemini API within minutes. It includes a genuinely usable free tier with rate limits per model.

Vertex AI is Google Cloud's enterprise ML platform. Gemini is available there too, but you authenticate with Google Cloud service accounts and IAM roles instead of a simple API key, billing runs through your GCP project, and you get more control over quotas, VPC networking, and data residency.

If you're an individual developer, a startup, or just testing an idea, use AI Studio. If you're already deep in Google Cloud infrastructure with compliance requirements, use Vertex AI. Most people searching for "how to get a Gemini API key" want the AI Studio path, so that's what we'll walk through.

Step 1: Create or sign in to a Google account

You need a standard Google account. A personal Gmail account works fine for the free tier. If your organization restricts API access at the Workspace admin level, you may need a personal account instead, or have an admin enable API access.

Step 2: Open Google AI Studio

Go to Google AI Studio (aistudio.google.com) and sign in. The interface shows a chat playground where you can test prompts against Gemini models before writing any code — useful for checking model behavior and pricing tiers before committing to an integration.

Step 3: Generate the API key

In the left sidebar, click "Get API key," then "Create API key." You'll be asked to either:

For most use cases, letting Google create a new project is simpler. The key appears as a string starting with AIza.... Copy it immediately and store it somewhere safe — a password manager or a secrets vault, not a text file on your desktop.

Step 4: Store the key as an environment variable

Never hardcode the key into your source files. Set it as an environment variable instead:

export GEMINI_API_KEY="AIzaSy..."

Or in a .env file (make sure .env is in .gitignore):

GEMINI_API_KEY=AIzaSy...

Step 5: Make your first request

Test the key with a simple curl request to the Gemini API:

curl -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [{"text": "Explain what an API key does in one sentence."}]
    }]
  }'

If everything is set up correctly, you'll get back a JSON response with the model's generated text inside a candidates array. If you get a 400 or 403 error, double-check that the key wasn't truncated when copied and that you're using the correct model name for your account tier.

Understanding the free tier and limits

Google's free tier for Gemini via AI Studio includes a set number of requests per minute and per day, varying by model (Flash models generally have higher free-tier limits than Pro models). There's no credit card required to get started at this tier. Once you exceed free quotas or need higher throughput, you link a billing account to your Google Cloud project and move to pay-as-you-go pricing based on input/output tokens.

Keep in mind that free-tier usage may be used by Google to improve their models, depending on current terms — read the AI Studio terms of service if data privacy is a concern for your use case, and consider the paid tier if you need stricter data handling guarantees.

Rotating and restricting your key

Once your key is live, don't leave it unrestricted. In Google Cloud Console, under APIs & Services > Credentials, you can:

Rotate keys periodically, especially if a key was ever pasted into a shared Slack channel, a public repo, or a support ticket.

If you're also working with Claude

A lot of teams building on Gemini also use Claude for specific tasks — long-context reasoning, tool use, or Anthropic-specific model behavior. If you already have Claude access and want it exposed as a clean HTTPS API with its own application keys, streaming, usage metadata, and team seats — similar to how you'd manage a Gemini key in a dashboard — SubToAPI does exactly that. You get sub_live_... keys scoped per application, without building your own auth and billing layer on top of Claude. Plans start at €9/month with a free trial at /signup, and the quickstart docs cover the same kind of first-request flow shown above.

Questions

Do I need a credit card to get a Gemini API key? No. Google AI Studio's free tier lets you generate a key and make requests without adding billing information. You only need a billing account once you exceed free-tier rate limits.

What's the difference between an AI Studio key and a Vertex AI key? AI Studio keys are simple API keys for quick access, billed per-project once you exceed free limits. Vertex AI uses Google Cloud IAM and service accounts instead of a flat API key, aimed at enterprise deployments with more granular access control.

Can I use the same Gemini key across multiple apps? Technically yes, but it's better practice to generate separate keys per application or environment (dev, staging, production) so you can monitor usage and revoke access independently if one key is compromised.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →