A Gemini API key lets your own code, scripts and apps talk to Google’s Gemini models. You can get one in about a minute from Google AI Studio, and there is a free tier, so you do not need a credit card to start.
Google changed a lot about API keys in 2026. New keys are now “auth keys” tied to a service account, unrestricted old keys are being blocked, and the free tier only covers some models. Many older tutorials are now out of date.
This guide shows how to create a Gemini API key step by step, keep it safe, test it with curl and Python, and understand the free and paid tiers. It also covers the errors you are most likely to hit.
Everything is checked against Google’s official Gemini API docs (API keys, rate limits, pricing and quickstart pages) in November 2026.
- Get a key: go to
aistudio.google.com/apikey, sign in, click Create API key. - New users get a Google Cloud project and key created automatically. Existing Cloud users import a project first.
- Store it as
GEMINI_API_KEY(orGOOGLE_API_KEY, which wins if both are set). Never put it in Git or front-end code. - Free tier: no card needed, limited models (Flash and Flash-Lite families), and your prompts may be used to improve Google products.
- Paid tiers start when you link a billing account (Tier 1), with higher limits and no training on your data.
- Test:
pip install -U google-genai, then run the short Python sample below.
How to Create a Gemini API Key
You need a Google account. A personal Gmail account works fine.
- Open aistudio.google.com/apikey and sign in.
- Accept the Google AI Studio terms if asked.
- If you are new to Google Cloud, a default project and API key are created for you automatically. You will see the key on the API Keys page.
- To make another key, click Create API key and pick the project it belongs to.
- Copy the key and store it somewhere safe, such as a password manager.
That is it. The key works straight away on the free tier.
A few limits to know: the AI Studio Projects page shows up to 10 projects at a time, and the API Keys page displays at most 100 keys. Rate limits are counted per project, not per key, so making extra keys in the same project does not give you more quota.
If You Already Use Google Cloud
Google’s docs say users who already have a Google Cloud account do not get a default project. You need to bring one into AI Studio first.
- In AI Studio, open Dashboard in the left panel and go to Projects.
- Click Import projects, select your Cloud project and click Import.
- Go to the API Keys page and create a key in that project.
If you see “You do not have permission to create a key in this project”, your account lacks the needed IAM permissions. Google suggests using the Project Editor role, or creating a fresh Cloud project that is not tied to an organization. This is common on work or school Google accounts.
Save the Key as an Environment Variable
Google’s client libraries look for GEMINI_API_KEY or GOOGLE_API_KEY automatically. If both are set, GOOGLE_API_KEY takes precedence, which can be confusing if you forget an old value.
| System | How to set it |
|---|---|
| macOS / Linux (zsh) | Add export GEMINI_API_KEY="your_key" to ~/.zshrc, then run source ~/.zshrc |
| Linux (bash) | Add the same line to ~/.bashrc, then run source ~/.bashrc |
| Windows | System Properties > Environment Variables > New, name GEMINI_API_KEY, paste the key, then open a new terminal |
For a quick test in the current terminal only, run export GEMINI_API_KEY="your_key" (macOS/Linux) or $env:GEMINI_API_KEY="your_key" (PowerShell).
Test Your Key With curl and Python
Python
Install Google’s official SDK. The package is called google-genai:
pip install -U google-genai
Then run this script. It reads the key from your environment variable:
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.5-flash",
input="Explain how AI works in a few words"
)
print(interaction.output_text)
If you see a short answer, your key works.
curl
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-H "Api-Revision: 2026-05-20" \
-d '{
"model": "gemini-3.5-flash",
"input": "Explain how AI works in a few words"
}'
These samples follow Google’s current quickstart, which uses the newer Interactions API. Model names change often: Google’s own pages mention gemini-3.5-flash, gemini-3.8-flash and others. Check the Models page in the Gemini docs for the current list, and swap the name in.
JavaScript
For Node.js, install @google/genai with npm install @google/genai. The client reads the same environment variable.
Free Tier vs Paid Tiers
| Free | Paid (Tier 1 and up) | |
|---|---|---|
| Cost | Free input and output tokens | Pay per token |
| Card needed | No | Yes, a linked billing account |
| Models | Limited set (mainly Flash and Flash-Lite models) | All models, including Pro and image models |
| Rate limits | Lowest | Higher, and rise with spend |
| Your data | May be used to improve Google products | Not used to improve Google products |
| Extras | None | Context caching, Batch API at 50% off |
According to Google’s pricing page in November 2026, models such as Gemini 3.8 Flash, 3.6 Flash, 3.5 Flash-Lite and 3.1 Flash-Lite are free of charge on the free tier, while Gemini 4 Argon, Gemini 3.1 Pro Preview and the image generation models are not available on it.
Google Search grounding is also not available on the free tier for those Flash models.
Do not send private or sensitive data on the free tier, because Google may use it to improve its products. For a full price breakdown, see our Gemini API pricing and free tier guide.
Note that the Gemini app subscription (Google AI Pro or Ultra) is separate from the API. Paying for the app does not give you API credits. If you want to drop the app plan, see how to cancel a Gemini subscription.
Rate Limits Explained
Gemini limits are measured in requests per minute (RPM), input tokens per minute (TPM) and requests per day (RPD). Going over any one returns a 429 RESOURCE_EXHAUSTED error. Daily limits reset at midnight Pacific time.
| Tier | How to qualify | Billing cap |
|---|---|---|
| Free | An active project or free trial | N/A |
| Tier 1 | Link an active billing account | $250 |
| Tier 2 | $100 paid and 3 days since first payment | $2,000 |
| Tier 3 | $1,000 paid and 30 days since first payment | $20,000 to $100,000+ |
Upgrades happen automatically. Moving from Free to Tier 1 is usually instant. Exact per-model limits change often, so Google shows your live numbers in AI Studio under the rate limit page rather than in a fixed table. Preview and experimental models have tighter limits.
Keep Your API Key Safe
Anyone with your key can use your quota and, on a paid tier, run up your bill. Google’s docs list these rules:
- Never commit keys to Git. Add your
.envfile to.gitignore. - Never put keys in browser or mobile app code. Call Gemini from your own backend instead.
- Use environment variables, and Google Cloud Secret Manager in production.
- Set billing alerts in Google Cloud so a leak cannot surprise you.
- Restrict the key. In AI Studio, keys marked “Unrestricted” have an Add restrictions option: choose Restrict to Gemini API only, then Restrict key.
If your key leaks
- Create a new key.
- Update your code, environment variables and servers to use it.
- Once the new key works, disable the old one.
- Check usage in the Google Cloud console for anything you did not do.
Auth Keys vs Standard Keys (2026 Changes)
Google is moving the Gemini API from standard API keys to a new type called authorization (auth) keys.
| Standard key | Auth key | |
|---|---|---|
| Linked to | A Cloud project | A Google Cloud service account |
| Restricted by default | No | Yes, to the Gemini (Generative Language) API |
| Leak protection | Basic | Faster leaked-key enforcement |
| Created by AI Studio | Before 28 May 2026 | From 28 May 2026 |
What this means for you:
- Any key you create now is an auth key, so you do not need to do anything.
- The Gemini API rejects requests from unrestricted standard keys. Old standard keys still work if they have explicit restrictions.
- Since 7 May 2026, unrestricted keys that sat unused for a long time are blocked and show a Blocked tag in AI Studio.
If an old project suddenly stops working, create a new key, update your code and delete the old key.
Troubleshooting
| Error or problem | Likely cause | Fix |
|---|---|---|
| API key not valid | Typo, extra space, or the key was deleted | Copy the key again; check which variable your code reads |
| Old key stopped working | Unrestricted standard key blocked | Create a new auth key, or restrict the old one to the Gemini API |
| 429 RESOURCE_EXHAUSTED | Rate limit or spend limit reached | Slow down, add retries with backoff, or move to a paid tier |
| Model not available on free tier | You called a paid-only model | Use a free Flash model or link billing |
| “You do not have permission to create a key” | Missing IAM roles on a work account | Ask for Project Editor, or create a personal Cloud project |
| Wrong key used | Both GOOGLE_API_KEY and GEMINI_API_KEY set | GOOGLE_API_KEY wins; remove the one you do not want |
| Model not found | Old or retired model name | Check the current names on the Models page |
If the Gemini app itself is acting up rather than the API, see our Gemini not working fix.
FAQ
Is the Gemini API key free?
Yes. Creating a key is free, and the free tier gives free tokens on selected models with lower rate limits.
Do I need a credit card?
Not for the free tier. You only add billing to move to Tier 1 for higher limits and paid models.
Can I use one key for several apps?
Yes, but all usage in a project shares the same limits. Separate keys make it easier to revoke one app without breaking the others.
Does Google train on my API data?
On the free tier, Google’s pricing page says content is used to improve its products. On paid tiers it is not.
Is a Gemini API key the same as a Google Cloud API key?
Keys created in AI Studio live in a Google Cloud project, but new ones are auth keys restricted to the Gemini API by default.
How do I get API keys for other AI models?
See our guides on how to get an OpenAI API key and how to get a Claude API key.




