Gemini API keys
How to get a Gemini API key
To get a Gemini API key, sign in to Google AI Studio, open the API Keys page at aistudio.google.com/api-keys and click Create API key. Since May 28, 2026, every new key made in AI Studio is an auth key, bound to a service account and restricted to the Gemini API by default.
The Free tier covers certain models up to their free rate limits. Paid use starts with a prepay of at least $5, and the billing account then has a monthly spend cap, $250 on Tier 1, shared by every project linked to it.
Create a Gemini API key in Google AI Studio
- Sign in to Google AI Studio and accept the Terms of Service. As a new user you get a default Google Cloud project and an API key right away.
- Already on Google Cloud? AI Studio doesn't create a default project for you. Open Dashboard, then Projects, click Import projects and pick the project.
- Go to the API Keys page and click Create API key in the project that should pay for the calls.
- Copy the key into an environment variable or a secret manager.
The Gemini client libraries pick up GEMINI_API_KEY or GOOGLE_API_KEY from the environment. If both are set, GOOGLE_API_KEY wins.
export GEMINI_API_KEY="your-key-here"If Create API key is unavailable with "You do not have permission to create a key in this project", you lack IAM permissions such as apikeys.keys.create. Ask an admin for a role like Project Editor, or create a project outside your organization.
Auth keys, standard keys and restrictions
Every Gemini API key belongs to a Google Cloud project, and its type decides whether it still works.
| Key type | What it is | Works with the Gemini API |
|---|---|---|
| Auth key | Bound to a service account; requests run as that account. Every new AI Studio key since May 28, 2026 is one | Yes, restricted to the Gemini API by default |
| Standard key with restrictions | Ties requests to a project for billing and quota, without identifying a caller | Yes |
| Standard key without restrictions | The same, with no API restriction. Keys made through the REST API start out this way | No, the Gemini API rejects it |
If an old key shows the Unrestricted label in AI Studio, hover over the label, click Add restrictions, pick Restrict to Gemini API only and confirm with Restrict key. That takes the apikeys.keys.update permission. Unrestricted keys that sat unused for a long time get a Blocked tag instead; replace those with a new key.
On the Credentials page of the Cloud console you can also limit a key to your servers' IP addresses, the only application restriction auth keys support.
Rate limits apply per project, not per key, so a second key in the same project adds no quota.
Where your key lives
Keys are listed on the API Keys page in AI Studio. It only shows keys that are unrestricted or restricted to the Gemini API, and at most 100 keys and 50 projects. Everything else is on the Credentials page in the Google Cloud console.
Missing a project? Import it from Dashboard, Projects. Requests AI Studio can't match to a named key show up on the Usage page under (unknown keys).
Deleted a key by mistake? You can restore it in the Cloud console within 30 days.
Free tier and billing
New accounts start on the Free tier: certain models, up to their free tier rate limits, at no charge. On the Free tier your content is used to improve Google's products. On paid tiers it isn't.
To go paid, click Set up billing next to the project in AI Studio, link a Cloud Billing account and prepay at least $5 in credits. API costs then come off the prepaid balance in near real time. Unused credits expire after 12 months and aren't refundable.
When the prepaid balance hits $0, every API key in every project on that billing account stops at once, and requests fail with HTTP 402 until you add credits. Billing runs about 10 minutes behind, so spend can overshoot the balance.
Opened your Google Cloud account after March 2, 2026? Then the $300 welcome credit can't pay for Gemini usage. Model prices are in Gemini API pricing.
Cap what the key can spend
Gemini spend caps sit on the billing account and on each project. Each paid tier has a monthly cap on the billing account: $250 on Tier 1, $2,000 on Tier 2 and $20,000 to $100,000 on Tier 3. When the total across all linked projects reaches it, service pauses for every project until the 1st of the next month.
To cap one app, give it its own project and key, then set a project spend cap: in AI Studio, open the Spend page and choose Monthly spend cap, Edit spend cap. It takes the project editor, owner or admin role. The feature is experimental, and spend can run past it for around 10 minutes while billing data catches up.
Depending on billing history, Tier 1 accounts also get a spend-based rate limit of $10 per rolling 10 minutes (a 429 RESOURCE_EXHAUSTED error). How to set a Gemini API spending limit covers both caps and Google Cloud budgets.
Keep the key out of code, git and browsers
- Treat it like a password: a leaked key can use your quota, run up charges and reach private resources.
- Never check it into Git.
- Don't put it in web or mobile apps, where it can be extracted. Call Gemini from a backend instead.
- Use environment variables, and a secret store such as Google Cloud Secret Manager in production.
- Don't share a Gemini key with other Google APIs.
If a key leaks, create a new key, deploy it, and disable the old one in the Cloud console once the new one works. Then check billing and API usage for activity you don't recognize. Google also blocks keys it knows are leaked; those fail with 403 PERMISSION_DENIED and "Your API key was reported as leaked". What to do next is in Gemini says my API key was reported as leaked.
Watch what the key spends
Costbrake doesn't use your Gemini API key. It reads your Cloud Billing export in BigQuery with a reader service account, plus optional live estimates for the Gemini API from Cloud Monitoring, about 5 minutes behind. It alerts on a spike: an hour that costs more than 3x your usual hour and at least $5 more.
It can also list the API keys in projects with the Gemini API on, never their values, and warn about keys without API or application restrictions. With live estimates on, Pro and Team check every 5 minutes, and every 2 minutes during a spike. Without them, and on Free, Google Cloud is checked hourly.
Pro and Team can add a brake that sets a zero Google spend cap on one service, such as the Gemini API, in one project. Google pauses new usage once its cost estimate passes the cap; that isn't instant, and usage until then is still billed. The brake uses a second service account that can only set spend caps, and it never fires on its own: an admin clicks it and confirms. Setup is on the Google Cloud integration page, plans are on the pricing page, and new workspaces get a 14-day Pro trial with no card.
Questions and answers
Is a Gemini API key free?
Yes. The key costs nothing, and new accounts start on a Free tier that covers certain models up to their free tier rate limits. On the Free tier your content is used to improve Google's products. Paid use needs a linked Cloud Billing account and a prepay of at least $5.
Where do I find my Gemini API key?
On the API Keys page in Google AI Studio; import the key's project first if it is missing. AI Studio only lists keys that are unrestricted or restricted to the Gemini API. Other keys are on the Credentials page in the Google Cloud console.
Why is my Gemini API key not working?
The Gemini API rejects unrestricted standard keys, so restrict the key to the Gemini API in AI Studio or create a new one. A 403 PERMISSION_DENIED saying the key was reported as leaked means Google blocked it for good, so create a new key. A 402 means the prepaid balance is empty.
How do I limit what a Gemini API key can spend?
Gemini caps spend per project and per billing account, so give the key its own project and set a monthly project spend cap on the Spend page in Google AI Studio. The project cap is experimental, and spend can run past it for around 10 minutes.
What should I do if my Gemini API key leaks?
Create a new key, deploy it, then disable the leaked key in the Cloud console once the new one works. Check billing and API usage for activity you don't recognize, and keep a project spend cap in place.
Sources
Updated