How to Get a Gemini API Key — WordsByEkta🌿
How to Get a Gemini API Key Without Losing Your Mind
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."
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.
Sign in with your Google account. No Google Cloud project needed at this stage.
It's next to the settings gear icon. This opens the API Keys section directly.
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.
It won't be shown again in full. Save it somewhere secure — a .env file in your project, a password manager, anywhere private.
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.
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.
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.
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:
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.
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.
Comments
Post a Comment