← Blog

How to Get a Google AI Studio API Key

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

Getting a Google AI Studio API key takes about two minutes: go to aistudio.google.com, sign in with a Google account, click Get API key, create a new key in a Google Cloud project, and copy it. That key gives you programmatic access to Google's Gemini models — text generation, vision, function calling, and streaming — over a REST or SDK interface.

The rest of this guide walks through the exact steps, what to do if you hit common errors (quota limits, billing prompts, region restrictions), and how to use the key safely once you have it. If you're building something that needs to run reliably in production rather than just testing prompts in a browser, there's also a note at the end about wrapping any Claude-based access you have into a proper API instead of relying on browser sessions.

Step 1: Go to Google AI Studio

Navigate to aistudio.google.com. This is Google's free, no-install web console for experimenting with Gemini models before you write any code. You'll need a Google account — a personal Gmail account works, but if you're doing this for a company project, use a Google Workspace account tied to that organization so billing and permissions stay separate from personal usage.

Step 2: Accept the terms and open the API key panel

On first visit you'll be asked to accept Google's Generative AI terms of service. After that, look for Get API key in the left sidebar (or under the settings menu, depending on the current UI layout — Google updates this occasionally).

Clicking it opens a panel with two options:

For most individual developers and small teams, "new project" is fine. You can always move quota and billing settings later.

Step 3: Generate and copy the key

Click Create API key. Google generates a string that looks like:

AIzaSy...

Copy it immediately and store it somewhere safe — a password manager or a .env file that's excluded from version control. Google won't show you the full key again after you navigate away, though you can always view it later inside AI Studio or regenerate it.

Never commit this key to a public repository. Google actively scans public GitHub repos for leaked API keys and will disable them, but by then someone may already have run up usage on your account.

Step 4: Test the key

Before wiring the key into an application, confirm it works with a simple request:

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

If you get a JSON response with generated text back, the key is active. If you get a 400 or 403 error, check the next section.

Step 5: Understand the free tier and rate limits

Google AI Studio keys come with a generous free tier for most Gemini models, with requests-per-minute and tokens-per-minute caps that vary by model. If you exceed them you'll get a 429 error. For anything beyond prototyping — real user traffic, agents running many calls per minute — you'll eventually need to link a billing account in Google Cloud Console to raise those limits. This doesn't happen automatically; you have to go into Cloud Console, enable billing for the project tied to your key, and Google will then apply paid-tier rate limits.

Common issues and fixes

"API key not valid" error Double-check you copied the entire string with no trailing space, and that you're calling the correct endpoint version (v1beta is standard for most current Gemini models).

Key works in AI Studio but not in your app Some regions and some Google Workspace organizational policies restrict the Generative Language API by default. Check your Cloud Console project's API restrictions under APIs & Services.

Quota exceeded immediately This usually means you're on a shared free-tier project or you generated the key inside an organization project that already has other services consuming quota. Try creating the key in a fresh project.

Key restrictions Under Credentials in Google Cloud Console, you can restrict a key to specific APIs or specific IP addresses/HTTP referrers. Do this for any key used in a client-side app, since AI Studio keys embedded in frontend JavaScript are visible to anyone who opens dev tools.

What to do with the key once you have it

Once you have a working key, you'd typically call it from server-side code, not directly from a browser. A minimal Node example:

const res = await fetch(
  `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${process.env.GOOGLE_API_KEY}`,
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      contents: [{ parts: [{ text: "Summarize this in two lines: ..." }] }],
    }),
  }
);
const data = await res.json();

Keep the key server-side, rotate it periodically, and set up a budget alert in Google Cloud if you enable billing.

If you're building on Claude instead

This guide is specifically about Google's Gemini models through AI Studio. If your stack is actually built around Claude and you're looking to turn existing Claude access into a proper API with its own keys, streaming, and usage tracking rather than scripting a browser session, that's a different problem — one SubToAPI is built for. It issues sub_live_... application keys, supports streaming and tool use, and gives you per-key usage metadata across a team, starting with a free trial at /signup. Setup details are in the quickstart docs.

questions

Do I need a credit card to get a Google AI Studio API key? No. You can generate and use a key on the free tier without adding billing. A credit card is only required if you want to raise rate limits beyond the free tier.

Is a Google AI Studio API key the same as a Vertex AI key? No. AI Studio keys hit the Generative Language API directly and are simpler to set up. Vertex AI is Google Cloud's enterprise ML platform with different authentication (service accounts, IAM) and is meant for larger production deployments.

Can I use one API key for multiple projects? Yes, technically the same key works anywhere until you revoke it, but it's better practice to generate separate keys per project or environment (dev, staging, production) so you can track usage and revoke access independently if one 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 →