Why start here
Every Gemini app, from a weekend script to a production service, starts the same way: you get a credential, you call a model, and you get text back. This level covers that path, and one habit that will save you a lot of debugging later: keep your key out of your code.
A quick note before we start. This course is independent of Google. Google doesn't write, review or endorse it, and it doesn't copy Google's documentation. When you need the official word on something, go to Google's docs at ai.google.dev.
The two pieces: AI Studio and the developer API
Think of it like a kitchen. Google AI Studio (aistudio.google.com) is the tasting counter. It runs in your browser, you type a prompt, pick a model, tweak settings and see the answer at once. No code needed. The Gemini developer API is the back door your own programs come through to order the same food. Your Python or JavaScript sends an HTTP request, normally through Google's Gen AI SDKs (google-genai for Python, @google/genai for JavaScript).
The two are connected. AI Studio is also where you create the API key your code uses, and it can show you any playground prompt as code you can copy.
Why we check the docs instead of trusting memory
The Gemini API changes about once a month. Models get added, renamed, moved out of preview or shut down. Older models can become hard to get: Google's model list currently says access to the 2.5 models is limited to people who have used them before. Even the recommended way to call the API has changed. Since June 2026 Google's docs recommend the newer Interactions API (client.interactions.create) for new projects. The older generateContent call is now called legacy, though it is still fully supported.
So every model name, limit and price in this course is checked against Google's current docs, and you should do the same. A blog post from six months ago can give you a model ID that no longer exists. When you see a name with -preview in it, expect it to change or go away.
Step 1: Create your API key
- Sign in at
aistudio.google.comwith a Google account. - Open the API keys page (
aistudio.google.com/apikey). New users often find a default key already made for them. If you already use Google Cloud, you may need to import an existing project first. - Create or copy a key.
Every key belongs to a Google Cloud project, and that project is what controls billing and permissions. Since 28 May 2026, new keys made in AI Studio are auth keys: they're tied to a service account and only work with the Gemini API by default. Older "standard" keys are being phased out. If you have an old key from a past project, make a new one instead of reusing it.
Gotcha: A key works like a password that's tied to your billing. If one leaks, make a new key, update your app to use it, then turn off the old one.
Step 2: Put the key in an environment variable
Never paste the key into a source file. One git push and it's public. Store it in an environment variable instead. The SDKs look for GEMINI_API_KEY or GOOGLE_API_KEY on their own. If both are set, GOOGLE_API_KEY wins, which is a common reason for "wrong key" confusion.
# macOS / Linux (current terminal only)
export GEMINI_API_KEY="paste-your-key-here"
# Windows PowerShell (current session only)
$env:GEMINI_API_KEY = "paste-your-key-here"
# To keep it for future sessions (open a new terminal afterwards):
setx GEMINI_API_KEY "paste-your-key-here"
If you'd rather use a .env file, add .env to .gitignore before your first commit.
Step 3: Try a prompt in the playground, then click "Get code"
In AI Studio, open a new prompt, pick a Flash model and type something like:
In two sentences, explain what an API key is to a new developer.
Run it. Then click Get code. AI Studio turns the exact request you just made (model, prompt, settings) into a snippet in Python, JavaScript, REST and other languages. This is the quickest way to see that the playground and the API are the same thing. Notice that the snippet never contains your key. It expects the key to come from the environment, just as we set it up.
Step 4: Run your first script
Install the SDK (pip install -U google-genai or npm install @google/genai), then run one of these.
# hello_gemini.py
import os
import sys
from google import genai
# Fail fast with a clear message instead of a confusing auth error
if not (os.environ.get("GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY")):
sys.exit("No API key found: set GEMINI_API_KEY first.")
client = genai.Client() # reads the key from the environment, never from code
interaction = client.interactions.create(
model="gemini-3.8-flash", # current stable Flash model at the time of writing; check the models page
input="Reply with one short sentence confirming you can hear me.",
)
print(interaction.output_text)
// hello_gemini.mjs (run with: node hello_gemini.mjs)
import { GoogleGenAI } from "@google/genai";
if (!process.env.GEMINI_API_KEY && !process.env.GOOGLE_API_KEY) {
throw new Error("No API key found: set GEMINI_API_KEY first.");
}
const ai = new GoogleGenAI({}); // empty config: the SDK finds the key itself
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Reply with one short sentence confirming you can hear me.",
});
console.log(interaction.output_text);
Step 5: Check that it worked
It worked if you see a line of model text, for example:
Yes, I can hear you loud and clear!
The wording will be different each time, and that's fine. What matters is that text came back and there was no authentication or permission error. If something fails:
- "No API key found": the variable isn't set in this terminal.
setxonly takes effect in new windows. - Auth or permission error: check for a stray
GOOGLE_API_KEYthat's taking priority, a copy-paste mistake, or an old standard key. - Model not found: the model ID has changed. Look it up on the current models page.
Key takeaways
- AI Studio is the browser playground and the place where you make keys. The developer API is how your code reaches the same models.
- This course is independent of Google. Always check model names, limits and prices against Google's current docs.
- New AI Studio keys are auth keys tied to a Google Cloud project. Treat them like passwords.
- Store the key in
GEMINI_API_KEY. The SDK reads it automatically, andGOOGLE_API_KEYtakes priority if both are set. - "Get code" turns any playground prompt into a ready-to-run API call.
- You're done when your script prints model text with no authentication error.