// Models · API key guide
Gemini API keys: generate one in Google AI Studio
Keys are created in Google AI Studio and belong to a Google Cloud project. New accounts start on the Free Tier – no billing account needed.
4 stepsofficial docs onlychecked 2026-10-26
01How to get a Google Gemini API key
- Sign in to Google AI Studio with a Google account and accept the terms – new users get a default Google Cloud project and API key automatically.
- Existing Google Cloud users: Dashboard → Projects → “Import projects”, then create a key in that project.
- Open the API keys page (aistudio.google.com/apikey) → “Create API key”. Since 2026-05-28 new keys are authorization keys bound to a service account.
- Save it as GEMINI_API_KEY and send it in the x-goog-api-key header.
Official key page: https://aistudio.google.com/apikey – console labels may change; follow what the official page shows.
02Real-name, phone and credit card requirements
| Real-name / ID verification | No ID verification for the Free Tier – a Google account is enough. |
|---|---|
| Phone number | Only whatever your Google account requires. |
| Credit card / payment | Free Tier: no. Paid Tier: link a billing account and prepay at least $5 (or equivalent). |
03Base URL and a minimal call
https://generativelanguage.googleapis.com/v1betahttps://generativelanguage.googleapis.com/v1beta/openai/GEMINI_API_KEY · Example model:gemini-3.8-flashcurl
curl -X POST "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": "Explain how AI works in a few words"
}' Python
# pip install openai
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["GEMINI_API_KEY"], base_url="https://generativelanguage.googleapis.com/v1beta/openai/")
resp = client.chat.completions.create(
model="gemini-3.8-flash",
messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content) 04Free quota
All free AI APIs →New accounts begin on the Free Tier, with access to certain models up to their free-tier rate limits; exact limits are shown per project in AI Studio. Availability depends on your region.
05Google Gemini API prices
All model prices →| Model | Input / 1M tokens | Output / 1M tokens | Source |
|---|---|---|---|
Gemini 2.5 Flash-Litegemini-2.5-flash-lite | $0.1 | $0.4 | official · 2026-10-10 |
Gemini 3.1 Flash-Litegemini-3.1-flash-lite | $0.25 | $1.5 | official · 2026-10-10 |
Gemini 3.5 Flash-Litegemini-3.5-flash-lite | $0.3 | $2.5 | official · 2026-10-10 |
Gemini 2.5 Flashgemini-2.5-flash | $0.3 | $2.5 | official · 2026-11-21 |
Gemini 3 Flash Previewgemini-3-flash-preview | $0.5 | $3 | official · 2026-10-10 |
Gemini 3.8 Flashgemini-3.8-flash | $0.75 | $3.75 | official · 2026-10-10 |
Gemini 3.6 Flashgemini-3.6-flash | $0.75 | $3.75 | official · 2026-10-10 |
Gemini Robotics-ER 2gemini-robotics-er-2 | $1 | $5 | official · 2026-11-21 |
Standard (non-batch) list prices from our price database; cheapest first, max 8 rows. Prices change – the official page wins.
06Keep your API key safe
- Unrestricted standard keys are rejected by the Gemini API – use auth keys (default for new keys) or add restrictions to old standard keys.
- Google says: never check keys into source control and never expose keys client-side in production.
- Keep the key in an environment variable or a secrets manager – never hard-code it, never commit it to Git, never paste it into a screenshot, chat or issue.
- Never put a long-lived key in front-end, mobile or desktop client code – anyone can extract it. Call the API from your own server.
- One key per project or environment, so a leak can be revoked without breaking everything else.
- If a key leaks, delete it in the console immediately and create a new one, then check usage and billing.
- Do not buy keys from resellers or “API relays” and do not paste your key into websites you do not trust.
07FAQ
FAQ
How do I generate a Gemini API key?
Google AI Studio → API keys (aistudio.google.com/apikey) → Create API key. New users already get one in a default project.
Are Gemini API keys free?
Creating keys is free and new accounts are on the Free Tier for certain models with rate limits. Higher limits need the Paid Tier (billing account + $5 prepay).
Can I have multiple Gemini API keys?
Yes – keys live in Google Cloud projects; create separate keys or projects per app so you can revoke one without affecting others.
08Official sources
- Gemini API · Using API keys ai.google.dev
- Gemini API · Quickstart ai.google.dev
- Gemini API · Billing ai.google.dev
- Gemini API · OpenAI compatibility ai.google.dev
All facts checked against these pages on 2026-10-26. If anything differs, the official page wins.