How to Get a Gemini API Key in Google AI Studio (Free Tier, Billing, Key Types)
TL;DR: Get a Gemini API key from Google AI Studio — new users get a default project and key automatically; check the 2026 key-type changes and free-tier conditions before you build.
Gemini API keys come from Google AI Studio. New users get a default project and key automatically; existing Google Cloud users import a project first. Google changed the key type in 2026, and the free tier has conditions worth knowing before you build on it.
Count Gemini tokens and cost →All guides
Before you start: region and age
The Gemini API’s available-regions list does not include mainland China, Hong Kong or Macau. You must be 18 or older and have completed Google account age verification. In Colab, availability is decided by the region of the runtime instance (Available regions).
Create the key
- Open Google AI Studio at
https://aistudio.google.com/apikey. - New users: accept the terms of service; AI Studio automatically creates a default Cloud project and an API key.
- Existing Google Cloud users: Dashboard → Projects → Import projects, choose the project and click Import. Then on the API Keys page click Create API key (Using Gemini API keys).
Key types changed in 2026: since 28 May 2026 new keys are auth keys bound to a service account by default, and unrestricted standard keys are rejected. Since 7 May 2026, unrestricted keys that sit unused for a long time are blocked. If an old key suddenly stops working, check its type and restrictions first.
Free tier and billing
- New accounts start on the Free Tier: some models are available at free-tier rate limits. Google notes that free-tier data may be used to improve its products, while paid-tier data is not.
- To pay, click Set up billing on the AI Studio project, link a Cloud Billing account and prepay at least $5 (maximum $5,000). When the balance reaches $0, every key returns HTTP 402.
- Prepaid credits expire after 12 months and are non-refundable.
- The $300 Google Cloud welcome credit cannot be used for the Gemini API (for accounts opened after 2 March 2026) (Billing).
| Tier | Qualification | Monthly cap |
|---|---|---|
| Free | Default for new accounts | — |
| Tier 1 | Billing linked | $250 |
| Tier 2 | $100 paid and 3 days since first payment | $2,000 |
| Tier 3 | $1,000 paid and 30 days | $20,000–$100,000+ |
Before you top up, paste a typical prompt into the token counter and estimate a month of traffic with the LLM cost calculator.
Endpoint and authentication
- REST endpoint shown on the API key page:
https://generativelanguage.googleapis.com/v1beta/interactions - Header:
x-goog-api-key: $GEMINI_API_KEY - Environment variable:
GEMINI_API_KEYorGOOGLE_API_KEY; if both are set,GOOGLE_API_KEYwins. - Google also documents an OpenAI-compatibility layer; we did not verify its base URL for this guide, so take it from Google’s own page if you need it.
Hello world
export GEMINI_API_KEY="paste-your-key-here" # never commit this
curl https://generativelanguage.googleapis.com/v1beta/interactions \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.8-flash",
"input": "Say hello in one sentence."
}'
# If both GEMINI_API_KEY and GOOGLE_API_KEY are set, the SDKs use GOOGLE_API_KEY.
If the request body format has changed, copy the current sample from the API key page — the endpoint, header and model above are the ones it lists.
Common gotchas
- HTTP 402 on every key — the prepaid balance is $0. Top up the billing account.
- Key rejected — unrestricted standard keys are no longer accepted; create an auth key or restrict the key.
- Expecting the $300 Cloud credit to cover Gemini — it does not for accounts opened after 2 March 2026.
- Safety: Google advises restricting the key to the Gemini API, never committing it to Git or putting it in client-side code, and — if it leaks — creating a new key first, then disabling the old one. Put the key in an environment variable, keep it out of Git and out of any code that runs in a browser or mobile app, and replace it if it is ever exposed. The API keys overview has the full checklist.
FAQ
Is the Gemini API free?
New accounts get a Free Tier with some models at free-tier limits. Paid use requires linking billing and prepaying at least $5.
Can I use it from mainland China?
Mainland China, Hong Kong and Macau are not on the Gemini API’s available-regions list.
Which environment variable should I use?
Either GEMINI_API_KEY or GOOGLE_API_KEY. Set only one to avoid surprises — if both exist, GOOGLE_API_KEY takes precedence.
Sources
Vendor features and prices were checked against these official pages on 2026-10-20. Products change; if something here no longer matches, the official page is right.
- Google AI for Developers — Using Gemini API keys (updated 2026-10-06)
https://ai.google.dev/gemini-api/docs/api-key - Google AI for Developers — Available regions (updated 2026-04-28)
https://ai.google.dev/gemini-api/docs/available-regions - Google AI for Developers — Billing (updated 2026-09-28)
https://ai.google.dev/gemini-api/docs/billing