Skip to main content

How to Get a Gemini API Key — WordsByEkta🌿

Developer Tools · API Setup

How to Get a Gemini API Key Without Losing Your Mind

Gemini Flash Google AI Studio Free Tier No Billing Required API Integration
⚡ Quick Answer

Go to aistudio.google.com → click Get API Key → click Create API key → done. Do not use Google Cloud Console — it will send you through OAuth and service account flows that have nothing to do with Gemini.

I was building a category recommender tool for KDP (Kindle Direct Publishing) and needed Gemini to re-rank results. Simple enough, right? Just grab an API key.

Forty minutes later I was staring at a service account creation screen wondering what I'd done wrong. I hadn't done anything wrong — Google's own interface just sends you down the wrong path if you start from the wrong place. Here's everything I figured out so you don't have to waste the same forty minutes.

Why This Is Confusing (It's Not Just You)

Google has two separate systems for AI credentials and they look related but behave completely differently. Most tutorials — including some from Google itself — are written for the older Cloud Console flow. As of 2025-26, the Cloud Console UI has changed. The "Create Credentials" wizard no longer shows an "API key" option upfront — it now routes you through a type-selection screen asking whether your app uses "User data" or "Application data."

⚠️ What's changed
Clicking "Create Credentials" in Cloud Console now opens a wizard asking you to choose between User data (→ OAuth client) and Application data (→ Service account). There is no direct "just give me a key" option in this flow anymore. This is why you end up at a service account screen even when you just wanted a simple API key.

The solution is to skip Cloud Console entirely for Gemini and use Google AI Studio instead. These are two separate products with separate credential systems.

The Right Way — Google AI Studio

Google AI Studio is Google's dedicated playground and API access portal for Gemini models. It's free, it doesn't require billing, and it gives you an API key in under a minute.

01
Go to aistudio.google.com

Sign in with your Google account. No Google Cloud project needed at this stage.

02
Click the key icon (🔑) in the bottom-left sidebar

It's next to the settings gear icon. This opens the API Keys section directly.

03
Click "Create API key"

It will ask you to associate a Google Cloud project. You can create a new one or pick an existing project. Name it something recognisable like kdp-recommender or my-app-gemini.

04
Copy the key immediately

It won't be shown again in full. Save it somewhere secure — a .env file in your project, a password manager, anywhere private.

05
Name your key (optional but useful)

Give it a descriptive label like kdp-recommender. This name is just for your reference — it has no technical impact on how the key works.

✅ That's it
No OAuth setup. No service account. No billing account required. No roles, no IAM, no permission configuration. The key is ready to use immediately.

What Happens If You Use Cloud Console

If you go to console.cloud.google.com and try to create a Gemini API key from there, here's the exact path you end up on — and why it doesn't work the way you'd expect.

APIs & Services → Credentials → Create Credentials → [wizard appears]

The wizard asks: "What data will you be accessing?" with two options — User data and Application data. Neither of these is the right answer for Gemini API.

  • User data — creates an OAuth client. Used when your app accesses data belonging to a Google user (Gmail, Drive, Calendar). Requires user consent screens, OAuth flows, and redirect URIs. Not what you want for Gemini.
  • Application data — creates a service account. Used for server-to-server communication with Google Cloud services like Cloud Storage, BigQuery, Cloud Functions. Also not what you want for Gemini.

The reason there's no simple API key option in this wizard is that it was added for OAuth and service account flows specifically. The plain API key option exists in Cloud Console — but you have to exit this wizard and look under "Create Credentials → API key" from the dropdown directly, not via the wizard. Except Google's UI now takes you into the wizard by default, which is why most people get stuck.

💡 For the record
You can technically generate a Gemini-compatible API key from Cloud Console — but you'd need to enable the "Generative Language API" in the API library first, then go to Credentials and create an API key (not via the wizard). It's 6–8 extra steps. AI Studio does all of this for you automatically.

AI Studio vs Cloud Console — Side by Side

Factor Google AI Studio Cloud Console
Steps to get a key 3 clicks 6–8 steps minimum
Billing required No Depends on usage
OAuth or service account needed No Wizard forces this path
Free tier access Yes, immediate Possible but more setup
Key validity Works with Gemini API Works if API is enabled
Best for Indie devs, apps, tools Enterprise GCP integrations

Using the Key in Your Project

Once you have the key, the right way to use it depends on your project setup. Here are the two most common scenarios.

React / Vite project (with .env file)

Create a .env file at the root of your project and add:

VITE_GEMINI_API_KEY=your_actual_key_here

Then access it in your code as import.meta.env.VITE_GEMINI_API_KEY. Never hardcode the key directly in your source files — if you push that to GitHub, the key is exposed publicly.

Deploying to Vercel

Go to your project on vercel.com → Settings → Environment Variables → Add a new variable with the name VITE_GEMINI_API_KEY and paste your key as the value. Vercel injects this at build time. No need to commit your .env file to the repo.

🚫 Never do this
Don't paste your API key directly into your JSX or TypeScript files and push to GitHub. Even in a private repo, it's bad practice. The key will appear in your git history and could be scraped. Always use environment variables.

One important note: the key name you gave in AI Studio (kdp-recommender or whatever you chose) is just a human-readable label for managing keys in the dashboard. It has absolutely no bearing on the variable name you use in your code — those are completely independent.

What the Free Tier Actually Gives You

As of 2026, Gemini 1.5 Flash on AI Studio's free tier gives you 15 requests per minute and 1,500 requests per day. For most indie tools, side projects, and internal utilities, this is more than enough.

  • 15 RPM — 15 requests per minute. For a tool where users click a button and wait for results, you'd need 15 simultaneous users for this to be a constraint.
  • 1,500 RPD — 1,500 requests per day. If your tool gets 100 users making 10 requests each, you're still within limits.
  • 1M token context window — This is large enough to include hundreds of category paths in a single prompt without chunking.
  • No credit card required — The free tier on AI Studio is genuinely free, not a trial that expires.

When you do hit limits, the API returns a 429 error. The right approach is to show a "please try again in a moment" message rather than crashing — build that handling in from the start.

Frequently Asked Questions

No. The name (like kdp-recommender) is purely a label for your own reference in the AI Studio dashboard. Your code uses the actual key string value, not the name. You can name it anything you like.
Yes, if you manage to generate one correctly — you'd need to enable the Generative Language API in Cloud Console first, then create an API key (bypassing the wizard). The key itself works the same way. But for most use cases, AI Studio is the simpler route.
The free tier on Google AI Studio (Gemini 1.5 Flash) is not a trial — it's an ongoing free tier with rate limits. You don't need a credit card. Paid plans exist for higher limits and more powerful models, but the free tier doesn't expire.
No. When AI Studio asks you to link a project, you can select your existing Cloud project from the dropdown. The API key will be associated with that project. You don't need to create a new one.
Flash is faster and cheaper — it's optimised for tasks that need quick responses rather than complex reasoning. Pro is more capable for nuanced tasks but has tighter free tier limits. For re-ranking, classification, or structured output tasks, Flash is the better choice — it's fast enough and the quality is more than sufficient.
Because most tutorials were written before AI Studio became the standard path for Gemini. Google also updated the Cloud Console wizard UI sometime in 2024-25, removing the direct API key option from the first screen. Existing tutorials haven't caught up yet.

Comments

Popular Posts

Stop Uploading PDFs Online — Unlock Them Yourself — WordsByEkta🌿

Publish Your Android App on Google Play Store — WordsByEkta🌿

How to Set Up Your Blogger About Me Page: Part 02 — WordsByEkta🌿