In short
- You create and view Gemini API keys in Google AI Studio at aistudio.google.com/apikey, and every key belongs to a Google Cloud project, which handles billing and permissions. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- Since May 28, 2026, new keys created in AI Studio are auth keys: bound to a Google Cloud service account and restricted to the Gemini API by default. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- Client libraries read GEMINI_API_KEY or GOOGLE_API_KEY from the environment, and if both are set, GOOGLE_API_KEY takes precedence. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- New accounts begin on the Free Tier; the paid tier takes a Cloud Billing account and a prepayment of at least $5 of credits. Read on Billing (Google AI Studio docs) (opens in a new tab)
- A Gemini key runs the model. PrimaryAPI gives the agents you build on Gemini public data from social platforms, maps and filings through one more key.
How to get a Gemini API key, step by step
These are Google’s own steps, as its AI Studio docs give them in November 2026.
- Open the API Keys page in Google AI Studio at aistudio.google.com/apikey. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- If you are a new user, accept Google’s terms: AI Studio then creates a default Google Cloud project and an API key for you. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- To use a Google Cloud project you already have, open the Dashboard, select Projects, click Import projects, pick the project and click Import. Then create a key in it on the API Keys page. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- Copy the key and set it as GEMINI_API_KEY, for example with an export line in ~/.zshrc or ~/.bashrc, so the client libraries find it. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- On REST requests to generativelanguage.googleapis.com, send the key in the x-goog-api-key header. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
Standard keys and auth keys
A standard key ties requests to a Google Cloud project for billing and quotas but doesn’t identify the caller. An auth key is bound to a service account, restricted to the Gemini API by default, and supports faster enforcement when it leaks. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
Since May 28, 2026, new keys made in AI Studio are auth keys. The Gemini API rejects unrestricted standard keys, while standard keys with explicit restrictions still work. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
Since May 7, 2026, the Gemini API blocks unrestricted keys that have been dormant for an extended period, and AI Studio marks them Blocked. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
If the button to create a key is unavailable, your account lacks the IAM permissions for that project. Google’s docs list the ones you need, or you can use a project that isn’t tied to an organization. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
Restrict your Gemini API key
For a key used only with Gemini, choose Restrict to Gemini API only in AI Studio. A key shared with other Google APIs is restricted to specific APIs in the Google Cloud console instead. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
You can also limit which IP addresses or applications may use a key, on the credentials page of the Google Cloud console. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
AI Studio only shows keys that are unrestricted or restricted to the Gemini API. Other keys in the same project appear in the Google Cloud console. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
The free tier and the paid tier
New accounts begin on the Free Tier, which gives access to certain models in the Gemini API and AI Studio, up to each model’s free rate limits. Read on Billing (Google AI Studio docs) (opens in a new tab)
To move to the paid tier, open the Projects page in AI Studio, click Set up billing in the Billing Tier column, choose or add a Cloud Billing account, and prepay at least $5 of credits. Read on Billing (Google AI Studio docs) (opens in a new tab)
On the paid tier you can make sure your prompts and responses are not used to improve Google products. Read on Billing (Google AI Studio docs) (opens in a new tab)
Imported projects, and projects created outside AI Studio, may need verification before they can use the Free Tier. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
Keep your Gemini API key safe
Anyone with the key can run up your project’s bill, so Google’s docs set out these rules.
- Treat the key like a password and never commit it to a repository. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- Don’t put keys in web pages or mobile apps that run on users’ devices; call Gemini from your own back end. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- Read keys from environment variables, keep production keys in Google Cloud Secret Manager, and set billing alerts. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
- If a key leaks, create a replacement, deploy it, disable the leaked key once the new one works, then check billing and usage for activity you don’t recognise. Read on Gemini API keys (Google AI Studio docs) (opens in a new tab)
Give your Gemini agent data with one more key
A Gemini API key runs the model. When your agent also needs facts from outside it, such as YouTube videos, Reddit threads, Instagram profiles or Google Maps places, PrimaryAPI returns them as JSON with one key and one balance of credits.
Agents that support MCP connect to PrimaryAPI’s server and find, price and run APIs on their own; any other code calls the REST API with the same key. You only pay when data comes back.
Try it with PrimaryAPI
One key for every API below, for your code and your AI agents. You only pay when data comes back.
- YouTube SearchKeyword search over YouTube videos with relevance or popularity sorting, upload-date filters and cursor pagination2 credits / call
- YouTube TranscriptExisting captions of a YouTube video or Short as plain text plus timed segments, by URL or ID2 credits / call
- Reddit Subreddit PostsPosts of one subreddit listing, cursor paged2 credits / call
- Instagram ProfilePublic profile of one Instagram account by handle1 credit / call
- Google Maps SearchSearch Google Maps for places matching a query in a free-text location and get up to 20 normalised places with rating, address, phone, website and coordinates2 credits / call